-
Notifications
You must be signed in to change notification settings - Fork 4
/
versionbump
executable file
·79 lines (71 loc) · 2.59 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
#!/bin/bash
# Bumps up the version of doc-kit source files
# Usage:
# versionbump # Show current version
# versionbump 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)
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 "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 [[ ! $(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 -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
fi
for versionfile in $files; do
line=$(grep -inP '^(/+|/\*|#+|<!--)?[ \t]*project version number[ \t]*(/+|/\*|#+|-->)?' $versionfile | cut -f1 -d ':')
if [[ $line != '0' ]]; then
line=$(($line + 1))
sed -i -r "$line s/$currentversion/$bumpedversion/" $versionfile
fi
done
sed -i -r "s/$currentversion/$bumpedversion/" $config
echo "Set version number: $currentversion => $bumpedversion"
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
$EDITOR $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."
exit
else
git commit -m "Set version to $bumpedversion" $files $changes $config
git tag "$bumpedversion"
fi