-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·96 lines (76 loc) · 1.83 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
#!/bin/bash
set -eo pipefail
shopt -s extglob
version=$1
awk-in-place () {
local tmpfile=$(mktemp)
local original="$1"
shift
cp "$original" "$tmpfile"
awk "$@" <"$tmpfile" >"$original"
rm "$tmpfile"
}
confirm () {
local prompt="$1"
local answer
read -n 1 -p "${prompt} [yN] " answer
case $answer in
[yY]*) echo ;; # Continue
*) echo ; echo Canceling. >&2 ; exit 1 ;;
esac
}
case $version in
+([0-9]).+([0-9]).+([0-9])) ;; # Good
*) echo "Usage $0 VERSION" >&2 ; exit 1 ;;
esac
echo 'Making sure version is correct.'
awk-in-place Cargo.toml '
/^version *=/ && !done {
sub(/"[0-9.]+"/, "\"'$version'\"")
done=1
}
{ print }'
cargo check --quiet
cargo semver-checks check-release
awk-in-place CHANGELOG.md '
/^## / && !done {
$0 = "## Release '$version' ('$(date +%Y-%m-%d)')"
done=1
}
{ print }'
# Check for changes
if git ls-files --exclude-standard --other | grep . >/dev/null ; then
echo 'Found untracked files:' >&2
git ls-files --exclude-standard --other | sed -e 's/^/ /' >&2
echo >&2
echo 'Please commit changes before proceeding.' >&2
exit 1
fi
git diff --color --exit-code HEAD || {
echo >&2
echo 'Please commit changes before proceeding.' >&2
exit 1
}
# Confirm changelog
changelog=$(mktemp)
{
echo "## Release ${version}"
echo
parse-changelog CHANGELOG.md "$version"
} >"$changelog"
cat "$changelog"
echo
confirm 'Release notes displayed above. Continue?'
cargo publish -p matchgen
git tag --sign --file "$changelog" --cleanup=verbatim "v${version}"
git push --tags origin main
awk-in-place CHANGELOG.md '
/^## Release/ && !done {
print "## main branch\n"
done=1
}
{ print }'
git add CHANGELOG.md
git diff --staged
confirm 'Commit with message "Prepping CHANGELOG.md for development."?'
git commit -m 'Prepping CHANGELOG.md for development.'