-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbump-version.sh
executable file
·126 lines (95 loc) · 2.71 KB
/
bump-version.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# Unofficial Bash Strict Mode (http://redsymbol.net/articles/unofficial-bash-strict-mode/)
set -euo pipefail
IFS=$'\n\t'
PROG="$(basename "$0")"
function bail_out()
{
echo "$PROG: error: $@"
exit 1
} >&2
function cancel_by_user()
{
local CLEANUP="${1:-true}"
echo "$PROG: process cancelled by user"
eval "$CLEANUP"
exit 1
} >&2
function get_release_version()
{
VERSION="$(sed -nE '/^##\s/ {s/^##\s+\[([^]]+)\].*/\1/p ; q}' CHANGELOG.md)"
[[ "$VERSION" == "Unreleased" ]] && bail_out "update the Changelog first"
grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta)\.[0-9]+)?$' <<<"$VERSION" || \
bail_out "ill-formatted version not allowed: $VERSION"
}
function get_release_changelog()
{
CHANGELOG="$(sed -nE '
/^##\s/ {
h; # put release title in hold buffer
:collect
n; # move to next line
/^##\s/ { # found next release notes
x; # get current release notes
s/\s+$//; # strip trailing whitespace
p; # print out
q; # stop
}
H; # append line to hold buffer
b collect; # loop
}
' CHANGELOG.md)"
}
function remove_existing_release_tag()
{
if git rev-parse --quiet --verify "$RELEASE_TAG" > /dev/null
then
user_confirm "The release tag ($RELEASE_TAG) already exists. Really delete?"
git tag -d "$RELEASE_TAG"
fi
}
function create_release_tag()
{
git tag "$@" --annotate --cleanup=verbatim "$RELEASE_TAG" --message="$CHANGELOG"
}
function show_release_tag()
{
git show --format=short --no-patch "$RELEASE_TAG"
}
function user_confirm()
{
local CLEANUP="${2:-true}"
local REPLY
read -rp "$1 (y/N) "
[[ "$REPLY" == "y" ]] || cancel_by_user "$CLEANUP"
}
function validate_swinfo()
{
grep -F "enum gitVersion = \"$RELEASE_TAG\";" source/dentist/swinfo.d || \
bail_out "could not find the correct version number in " \
"source/dentist/swinfo.d; is the worktree clean? "\
"(git status should be empty)"
}
function main()
{
get_release_version
RELEASE_TAG="v$VERSION"
get_release_changelog
# create preliminary tag
remove_existing_release_tag
create_release_tag
# validate the version and release notes
show_release_tag
user_confirm "Are the version number and changelog correct?" \
'git tag -d "$RELEASE_TAG"'
# update version info
./update-swinfo.sh
# validate correct version without `+dirty
validate_swinfo
# commit swinfo.d
git commit source/dentist/swinfo.d -m 'Bump version'
# update release tag
create_release_tag -f
show_release_tag
}
main "$@"