forked from rundeck/rundeck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
161 lines (136 loc) · 4.34 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#/ Update version to release version, create a release tag and, then update to new snapshot version.
#/ usage: [--dryrun|--commit]
#/ --dryrun: don't commit changes
#/ --commit: commit changes
set -euo pipefail
IFS=$'\n\t'
readonly ARGS=("$@")
DRYRUN=1
SIGN=0
. rd_versions.sh
die(){
echo >&2 "$@" ; exit 2
}
usage() {
grep '^#/' <"$0" | cut -c4- # prints the #/ lines above as usage info
}
do_dryrun(){
local FARGS=("$@")
if [ $DRYRUN -eq 0 ]; then
"${FARGS[@]}"
else
echo "DRYRUN: " "${FARGS[@]}"
fi
}
rd_check_current_version_is_not_GA(){
local VERS=("$@")
echo "Current version: ${VERS[0]}-${VERS[1]}-${VERS[2]}"
if [ "${VERS[2]}" == "GA" ] ; then
echo "GA Release already, done."
exit 0
fi
}
commit_changes(){
local MESSAGE=$1
echo "Commit changes.."
do_dryrun git add -u .
do_dryrun git commit -m "$MESSAGE"
}
commit_tag(){
local FARGS=("$@")
local MESSAGE=${FARGS[1]}
local TAG=${FARGS[0]}
echo "Create tag $TAG.."
if [ "$SIGN" == "1" ] ; then
do_dryrun git tag -s $TAG -m "$MESSAGE"
else
do_dryrun git tag -a $TAG -m "$MESSAGE"
fi
}
check_args(){
if [ ${#ARGS[@]} -lt 1 ] ; then
usage
exit 2
fi
if [ ${#ARGS[@]} -gt 0 ] && [ "${ARGS[0]}" == "--help" -o "${ARGS[0]}" == "-h" -o "${ARGS[0]}" == "-?" ] ; then
usage
exit 2
fi
if [ ${#ARGS[@]} -gt 0 ] && [ "${ARGS[0]}" == "--commit" ] ; then
DRYRUN=0
elif [ ${#ARGS[@]} -gt 0 ] && [ "${ARGS[0]}" == "--dryrun" ] ; then
DRYRUN=1
else
usage
exit 2
fi
if [ ${#ARGS[@]} -gt 1 ] && [ "${ARGS[1]}" == "--sign" ] ; then
SIGN=1
fi
}
check_release_notes(){
local PATTERN=$1
set +e
local result=$( head -n 1 < RELEASE.md | grep -c "$PATTERN" )
set -e
if [ $result != "1" ] ; then
die "ERROR: RELEASE.md has not been updated, please add release notes."
fi
}
check_git_is_clean(){
set +e
# find any git file with status other than ?? (untracked)
git status --porcelain | grep '^[^?][^?]'
local status=$?
set -e
if [ $status -eq 0 ] ; then
die "ERROR: Git has modified files, please stash/commit any changes before updating version."
fi
}
generate_release_name(){
local vers=$1
local osascript=$(which osascript)
local TEMPL='<span style="color: $REL_COLOR"><span class="glyphicon glyphicon-$REL_ICON"></span> "$REL_TEXT"</span>'
if [ -n "$osascript" ] ; then
# run javascript file with osascript (mac)
local vars=$(cat rundeckapp/grails-app/assets/javascripts/version.js releaseversion.js | osascript -l JavaScript - $vers )
eval $vars
echo $TEMPL | sed "s#\$REL_COLOR#$REL_COLOR#" \
| sed "s#\$REL_ICON#$REL_ICON#" \
| sed "s#\$REL_TEXT#$REL_TEXT#"
fi
}
#/ Update date/name for release notes in RELEASE.md and git add the changes.
generate_release_notes_documentation(){
local NEW_VERS=$1
local DDATE=$(date "+%Y-%m-%d")
sed "s#Date: ....-..-..#Date: $DDATE#" < RELEASE.md > RELEASE.md.new
mv RELEASE.md.new RELEASE.md
local RELNAME=$(generate_release_name $NEW_VERS)
if [ -z "$RELNAME" ] ; then
die "Failed to generate release name"
fi
sed "s#Name: <span.*/span>#Name: $RELNAME#" < RELEASE.md > RELEASE.md.new
mv RELEASE.md.new RELEASE.md
git add RELEASE.md
git add CHANGELOG.md
out=$( git status --porcelain | grep "^M CHANGELOG.md") || die "CHANGELOG.md was not modified"
}
main() {
check_args
local -a VERS=( $( rd_get_version ) )
rd_check_current_version_is_not_GA "${VERS[@]}"
check_git_is_clean
local -a NEW_VERS=( $( rd_make_release_version "${VERS[@]}" ) )
check_release_notes "Release ${NEW_VERS[0]}"
rd_set_version "${NEW_VERS[@]}"
commit_changes "Update version to ${NEW_VERS[0]}-${NEW_VERS[1]}-${NEW_VERS[2]}"
generate_release_notes_documentation "${NEW_VERS[@]}"
commit_changes "Update release documentation for ${NEW_VERS[0]}-${NEW_VERS[1]}-${NEW_VERS[2]}"
commit_tag "v${NEW_VERS[0]}" "Release version ${NEW_VERS[0]}-${NEW_VERS[1]}-${NEW_VERS[2]}"
local -a NEXT_VERS=( $( rd_make_next_snapshot "${VERS[@]}" ) )
rd_set_version "${NEXT_VERS[@]}"
commit_changes "Update version to ${NEXT_VERS[0]}-${NEXT_VERS[1]}-${NEXT_VERS[2]}"
}
main