forked from openSUSE/libzypp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkChangelog
executable file
·255 lines (226 loc) · 5.86 KB
/
mkChangelog
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#! /bin/bash
function Recho() { echo -e "\e[0;31m""$@""\e[0m"; }
function Gecho() { echo -e "\e[0;32m""$@""\e[0m"; }
function Becho() { echo -e "\e[0;34m""$@""\e[0m"; }
function errexit() {
exec >&2
Recho "Error: $@"
exit 1
}
function usage() {
exec >&2
cat <<EOF
Usage:
$(basename $0) [OPTIONS]
Options:
-h,-?,--help This page.
-n Dryrun.
Prepare a new changes file entry preloaded with all commits since the last
changes tag and load it into \$EDITOR (vi). If the version file was changed,
optionally submitt and tag the new changes. Otherwise simply leave the changes
in place.
Don't forgett to push created tags as well: git push --tags
EOF
exit 1
}
DRYRUN=0
case "$1" in
-[n]*)
DRYRUN=1
;;
-[hH?]*)
usage
;;
--help)
usage
;;
esac
export LC_ALL=""
export LANG="en"
function Edit()
{
local FILE="$1"
vi "$FILE"
sed -i 's/ \+$//' "$FILE"
}
EMAIL="$(git config --get user.email)"
CHANGESFILE=$(ls package/*.changes)
test -f "$CHANGESFILE" || errexit "No changes file '$CHANGESFILE'"
VERSIONFILE="VERSION.cmake"
test -f "$VERSIONFILE" || errexit "No version file '$VERSIONFILE'"
function getversion() {
cat "$VERSIONFILE" \
| awk '
function getnum() {
gsub("^[^\"]*\"","")
gsub("\".*$","")
}
/^ *SET *\( *LIBZYPP_MAJOR *"[0-9]+" *\)/ {getnum();major=$0}
/^ *SET *\( *LIBZYPP_MINOR *"[0-9]+" *\)/ {getnum();minor=$0}
/^ *SET *\( *LIBZYPP_PATCH *"[0-9]+" *\)/ {getnum();patch=$0}
/^ *SET *\( *LIBZYPP_COMPATMINOR *"[0-9]+" *\)/ {getnum();compatminor=$0}
/^# LAST RELEASED:/ {
gsub("^.*RELEASED: *","");
gsub(" +$","");
lastcompat=$0
gsub(".*\\(","",lastcompat)
gsub("\\).*","",lastcompat)
gsub(" +\\(.*","");
lastrelease=$0
}
END {
thisrelease = major"."minor"."patch" ("compatminor")"
printf "LAST_RELEASE='%s'\n", lastrelease
printf "LAST_COMPAT='%s'\n", lastcompat
printf "THIS_RELEASE='%s'\n", major"."minor"."patch
printf "THIS_COMPAT='%s'\n", compatminor
printf "THIS_MINOR='%s'\n", minor
printf "THIS_PATCH='%s'\n", patch
}
'
}
function setversion() {
local KEY="$1"
local VAL="$2"
sed -i "s/^ *SET *( *${KEY} .*/SET(${KEY} \"${VAL}\")/" "$VERSIONFILE"
}
function sameVersion() {
test "$LAST_RELEASE" == "$THIS_RELEASE" -a "$LAST_COMPAT" == "$THIS_COMPAT"
}
function getchanges() {
git log --no-merges --pretty=format:'- %s' "$LAST_RELEASE"..HEAD | grep -v 'po.tar.bz2\|Translated using Weblate'
}
function newchangesentry() {
echo "-------------------------------------------------------------------"
echo "$(date) - $EMAIL"
echo ""
echo "$(getchanges)"
sameVersion || {
echo "- version $THIS_RELEASE ($THIS_COMPAT)"
}
echo ""
}
function is_fast_forward() {
git fetch
test "$(git rev-list HEAD..origin/$(git name-rev --name-only HEAD) --count)" == "0"
}
is_fast_forward || {
Recho "!!!"
Recho "!!! Branch is not fast-forward. Pull changes first."
Recho "!!!"
exit 7
}
git status --porcelain | grep '^[^ ?]' | grep -v "$VERSIONFILE\|$CHANGESFILE" && {
Becho "!!! Files other than version and changes are added to the index."
Becho "!!! Doing dryrun..."
DRYRUN=1
}
# A tag for $LAST_RELEASE must exist!
eval $(getversion)
git rev-parse -q --verify "$LAST_RELEASE" >/dev/null || {
Recho "!!!"
Recho "!!! There is no LAST_RELEASE tag '$LAST_RELEASE'. Check manually. "
Recho "!!! (git tag -m 'tagging $LAST_RELEASE' '$LAST_RELEASE' ?commit?)"
Recho "!!!"
exit 8
}
if [ "$DRYRUN" == "1" ]; then
newchangesentry
sameVersion && {
Becho "!!! Version is unchanged at $LAST_RELEASE ($LAST_COMPAT)."
}
exit 0
fi
# check version file
#
while true; do
# $LAST_RELEASE
# $LAST_COMPAT
# $THIS_RELEASE
# $THIS_COMPAT
sameVersion && {
newchangesentry
Becho "!!! Version is unchanged at $LAST_RELEASE ($LAST_COMPAT)."
read -n 1 -p "$(Gecho "(a)bort, (c)ontinue, (P) patch, (M) minor, (I) incompat minor, (e)dit version [e]: ")" RES
echo
case "${RES:-e}" in
[eE]*)
Edit $VERSIONFILE
eval $(getversion)
continue
;;
[cC])
Becho "!!! Leave $VERSIONFILE untouched"
break
;;
[P])
setversion LIBZYPP_PATCH $(($THIS_PATCH + 1))
eval $(getversion)
continue
;;
[M])
setversion LIBZYPP_MINOR $(($THIS_MINOR + 1))
setversion LIBZYPP_PATCH 0
eval $(getversion)
continue
;;
[I])
setversion LIBZYPP_COMPATMINOR $(($THIS_MINOR + 1))
setversion LIBZYPP_MINOR $(($THIS_MINOR + 1))
setversion LIBZYPP_PATCH 0
eval $(getversion)
continue
;;
*)
errexit "aborted"
;;
esac
}
break
done
# prepare changes file
#
TMPFILE=$(mktemp)
trap " [ -f \"$TMPFILE\" ] && /bin/rm -f -- \"$TMPFILE\" " 0 1 2 3 13 15
{ newchangesentry; cat $CHANGESFILE; } >$TMPFILE
RES=e
while [ "$RES" == "e" ]; do
Edit $TMPFILE
echo
awk '{print}/^----------/{n=n+1; if ( n == 2 ) exit 0; }' $TMPFILE
read -n 1 -p "$(Gecho "(a)bort, (c)ontinue, (s)ubmitt, (e)dit [e]: ")" RES
echo
case "${RES:-e}" in
[eE]*)
RES=e
;;
[cCsS])
Becho "!!! Store new $CHANGESFILE"
mv $TMPFILE $CHANGESFILE
chmod 644 $CHANGESFILE
test "$RES" == "s" && {
if [ "$LAST_RELEASE" == "$THIS_RELEASE" ]; then
git add "$CHANGESFILE" && git commit -m "changes"
else
Becho "!!! Remember new version $THIS_RELEASE in $VERSIONFILE"
sed -i "s/^# LAST RELEASED:.*$/# LAST RELEASED: $THIS_RELEASE ($THIS_COMPAT)/" $VERSIONFILE
if git add "$CHANGESFILE" "$VERSIONFILE" \
&& git commit -m "changes $THIS_RELEASE ($THIS_COMPAT)" \
&& git tag -m "tagging $THIS_RELEASE" "$THIS_RELEASE" HEAD; then
Becho "!!!"
Becho "!!! Do not forget to push the commit and the tag: $(Gecho git push --tags origin HEAD)"
Becho "!!!"
else
Recho "!!!"
Recho "!!! Commit failed. Check manually. (git reset HEAD~)"
Recho "!!!"
exit 9
fi
fi
}
;;
*)
Becho "!!! Leave $CHANGESFILE untouched"
;;
esac
done