forked from solana-foundation/anchor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbump-version.sh
More file actions
executable file
·113 lines (93 loc) · 3.17 KB
/
bump-version.sh
File metadata and controls
executable file
·113 lines (93 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
set -ex
if [ $# -eq 0 ]; then
echo "Usage $0 VERSION"
exit 1
fi
old_version=$(cat VERSION)
version=$1
if [[ "$version" == v* ]]; then
echo "The version number must not contain the v[...] prefix"
exit 1
fi
is_prerelease=0
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-.+ ]]; then
is_prerelease=1
fi
echo "Bumping versions to $version (is_prerelease=$is_prerelease)"
# GNU/BSD compat
sedi=(-i)
case "$(uname)" in
# For macOS, use two parameters
Darwin*) sedi=(-i "")
esac
# Bump all rust crates that have `publish` enabled
cargo release version $version \
--workspace \
$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.publish == []) | "--exclude " + .name') \
--no-confirm \
--execute
# Only replace version with the following globs
allow_globs="**/Makefile client/src/lib.rs lang/attribute/program/src/lib.rs"
git grep -l $old_version -- $allow_globs |
xargs sed "${sedi[@]}" \
-e "s/$old_version/$version/g"
# Avoid updating the docs for pre-release builds
if [[ "$is_prerelease" -eq 0 ]]; then
latest_stable_version=$(
git tag --sort=-version:refname | \
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | \
head -n1 | \
sed 's/^v//'
)
echo "Latest stable version for documentation was $latest_stable_version..."
# Separately handle docs because blindly replacing the old version with the new
# might break certain examples/links
pushd docs/content/docs
git grep -l $latest_stable_version -- "./*.md*" | \
xargs sed "${sedi[@]}" \
-e "s/\"$latest_stable_version\"/\"$version\"/g"
allow_globs="installation.mdx quickstart/local.mdx references/verifiable-builds.mdx"
git grep -l $latest_stable_version -- $allow_globs |
xargs sed "${sedi[@]}" \
-e "s/$latest_stable_version/$version/g"
# Replace `solana_version` with the current version
solana_version=$(solana --version | awk '{print $2;}')
sed $sedi "s/solana_version.*\"/solana_version = \"$solana_version\"/g" references/anchor-toml.mdx
# Keep release notes and changelog the same
git restore updates
popd
fi
# Potential for collisions in `package.json` files, handle those separately
# Replace only matching "version": "x.xx.x" and "@anchor-lang/core": "x.xx.x"
git grep -l $old_version -- "**/package.json" | \
xargs sed -E "${sedi[@]}" \
-e "s/\"version\": \"$old_version\"/\"version\": \"$version\"/g" \
-e "s/@anchor-lang\/(.*)\": \"(.*)$old_version\"/@anchor-lang\/\1\": \"\2$version\"/g"
# Insert version number into CHANGELOG
sed "${sedi[@]}" -e \
"s/## \[Unreleased\]/## [Unreleased]\n\n### Features\n\n### Fixes\n\n### Breaking\n\n## [$version] - $(date '+%Y-%m-%d')/g" \
CHANGELOG.md
# Update lock files
pushd ts
yarn
popd
pushd tests
yarn
popd
pushd examples
yarn
pushd tutorial
yarn
popd
popd
# Avoid updating the benchmarks for pre-release builds
if [[ "$is_prerelease" -eq 0 ]]; then
# Bump benchmark files
pushd tests/bench
anchor run bump-version -- --anchor-version $version
popd
fi
echo $version > VERSION
echo "$(git diff --stat | tail -n1) files modified"
echo "$version changeset generated, commit and tag"