-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrelease.sh
executable file
·97 lines (69 loc) · 2.3 KB
/
release.sh
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
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set -e
MAIN_BRANCH=main
cd $(dirname "$0")
cd "$(git rev-parse --show-toplevel)"
source "tools/utils.sh"
function set_version {
local version=$1
sed -i "0,/version = .*$/s//version = \"$version\"/" Cargo.toml
# Update version in `Cargo.lock`.
cargo update -w --offline
}
if [ $(git symbolic-ref --short HEAD) != $MAIN_BRANCH ]; then
echo "Not in $MAIN_BRANCH branch." >&2
exit 1
fi
if [ $(git status --porcelain --untracked-files=no | wc -l) -ne 0 ]; then
echo "Working directory is not clean." >&2
exit 1
fi
echo 'Checking if local branch is up to date...'
git remote update origin > /dev/null 2> /dev/null
if git status -uno | grep --silent "behind"; then
echo "Local branch is not up to date." >&2
exit 1
fi
echo "Current version is $(project_version)."
echo -n "Which version do you want to release? "
read release_version
echo -n "Which will be the next version? "
read next_version
if ! echo "$next_version" | grep --silent -- "-pre$"; then
echo 'Next version must end in `-pre`.' >&2
fi
echo
echo "Current version: $(project_version)"
echo "Release version: $release_version"
echo "Next version: $next_version"
echo
echo -n 'Does this look right [yes/no]? '
read answer
if [ "$answer" != "yes" ]; then
exit 0
fi
echo -n "Running tests... "
if ! ./tools/check.sh 2>/dev/null > /dev/null; then
echo "It failed :(" >&2
exit 0
fi
echo "done."
while ! grep "^## " release-notes.md | head -1 | grep --silent "^## $release_version$"; do
echo
echo "There's no entry for this version in the release notes."
echo -n "Go ahead and add them and press enter when you're done... "
read
done
set_version "$release_version"
git commit -am "Release v${release_version}."
git tag --sign -a "v${release_version}" -m "$(project_name) version ${release_version}."
set_version "$next_version"
git commit -am "Bump to version $next_version."
echo "Check if everything is alright. If so do:"
echo
echo " git push --atomic origin $MAIN_BRANCH v${release_version} && git checkout v${release_version} && cargo publish && git checkout $MAIN_BRANCH"
echo