-
Notifications
You must be signed in to change notification settings - Fork 10
/
versionbump
executable file
·102 lines (91 loc) · 3.54 KB
/
versionbump
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
#!/bin/bash
# Bumps up the version of source files
# Usage:
# versionbump # Show current version
# versionbump xxxx.xx.x.x # Set version number
bumpedversion=$1
config=.versionrc
format=$(sed -r -n "s/^format: *(.+)\$/\1/ p" $config)
formathuman=$(sed -r -n 's/^formathuman: (.*)$/\1/ p' $config)
currentversion=$(sed -r -n "s/^version: *($format)\$/\1/ p" $config)
files=$(sed -r -n 's/^files: *(([-_./a-zA-Z0-9]+ *)+)/\1/ p' $config)
changes=$(sed -r -n 's/^changesfile: *(([-_./a-zA-Z0-9]+ *)+)/\1/ p' $config)
tagprefix=$(sed -r -n 's/^tagprefix: *(([-_./a-zA-Z0-9]+ *)+)/\1/ p' $config)
changestemplate="/tmp/XXXX-suse-xsl-version"
changes_header="-------------------------------------------------------------------"
changes_user="[email protected]"
if [[ $1 == '' ]]; then
currentversion=$(sed -r -n 's/^version: *(.+)$/\1/ p' $config)
echo "Current version number is $currentversion"
echo "Format: $formathuman"
echo -n "Format policy: "
sed -r -n 's/^formatpolicy: (.*)$/\1/ p' $config | sed -r 's/(^|; *)/\n * /g'
exit
fi
if [[ $currentversion == '' ]]; then
echo -n "(aem) Old version number does not adhere to format: $format. Continue anyway? y/[n] "
read DECISION
if [[ ! $DECISION == 'y' ]] && [[ ! $DECISION == 'yes' ]]; then
echo "(meh) Not setting new version number."
exit
else
currentversion=$(sed -r -n 's/^version: *(.+)$/\1/ p' $config)
fi
fi
if [[ "$1" == '--finalize' ]]; then
if [[ $(git tag | grep -o "$tagprefix$bumpedversion") ]]; then
echo "(meh) The tag $tagprefix$bumpedversion already exists. I am confused."
exit 1
else
bumpedversion="$currentversion"
fi
else
if [[ ! $(echo $bumpedversion | grep -P "^$format\$") ]]; then
echo "(meh) New version does not adhere to format: $formathuman"
echo "Format as regular expression: $format"
exit
fi
echo "Current version number is $currentversion"
echo -n "Really set new version number $bumpedversion? y/[n] "
read DECISION
if [[ ! $DECISION == 'y' ]] && [[ ! $DECISION == 'yes' ]]; then
echo "(meh) Not setting new version number."
exit 1
fi
for versionfile in $config $files; do
sed -i -r "s/$currentversion/$bumpedversion/" $versionfile
done
echo "Set version number: $currentversion => $bumpedversion"
fi
if [[ $(grep -o "$bumpedversion" $changes) ]]; then
echo "(yay) Changes file appears to mention version $bumpedversion already."
else
echo "(aem) Changes file does not appear to mention $bumpedversion yet."
fi
echo -n "Open changes file for editing? [y]/n "
read DECISION
if [[ ! $DECISION == 'n' ]] && [[ ! $DECISION == 'no' ]]; then
TMPFILE=$(mktemp $changestemplate)
TMPFILE2=$(mktemp $changestemplate)
echo -e $changes_header > $TMPFILE
DATE=$(LANG=C TZ=UTC date '+%A %b %d %T %Z %Y' | awk '{$1=substr($1,1,3); print $0}')
echo -e "$DATE - $changes_user\n\n" >> $TMPFILE
${EDITOR:-vi} $TMPFILE
cat $TMPFILE $changes > $TMPFILE2 && mv $TMPFILE2 $changes
else
echo "(kay) Using changes as-is."
fi
echo -n "Commit and tag version $bumpedversion? y/[n] "
read DECISION
if [[ ! $DECISION == 'y' ]] && [[ ! $DECISION == 'yes' ]]; then
echo "(meh) Not creating commit and tag."
echo "Rerun this script with --finalize to finish."
exit
else
COMMITMESSAGE="Set version to $bumpedversion"
sed -i '1d' $TMPFILE
git commit -m "$COMMITMESSAGE" $files $changes $config
git tag -a "$tagprefix$bumpedversion" -m "$COMMITMESSAGE"
echo -e "(hey) Do not forget:\n git push && git push $(git remote | head -1) $tagprefix$bumpedversion"
rm $TMPFILE 2>/dev/null || true
fi