-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgbump
executable file
·49 lines (38 loc) · 1.15 KB
/
pkgbump
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
#!/bin/bash
# Checks if the patch version number commited to package.json on the current
# branch is less than the one commmitted to master and if so bumps the package
# version by one patch number and commits it
set -o nounset
set -o errexit
print_patch() {
awk -F '.' '/"version":/{print $3+0}'
}
# The file that contains the version number
FILE=${1:-}
ROOT="$(git rev-parse --show-toplevel)"
# If file is not passed in, try to find it
if [[ -z "$FILE" ]]; then
for file in "package.json" "server/package.json"; do
if [[ -f "$ROOT/$file" ]]; then
FILE="$file"
break
fi
done
fi
FPATH="$ROOT/$FILE"
if [[ ! -f "$FPATH" ]]; then
if [[ -z "$FILE" ]]; then
echo "ERROR: could not find package.json file, pass file as first argument"
else
echo "ERROR: $FPATH is not a file"
fi
exit 1
fi
git fetch origin master
MASTER="$(git show origin/master:$FILE | print_patch)"
CURRENT="$(cat "$FPATH" | print_patch)"
if [[ $MASTER -ge $CURRENT ]]; then
perl -i -pe 's/(version": "(\d+\.)*)(\d+)(.*)/$1.($3+1).$4/e' "$FPATH"
git commit "$FPATH" --no-verify -m "bump version" > /dev/null
echo "bumped and commited patch version"
fi