-
Notifications
You must be signed in to change notification settings - Fork 64
/
bump-version.sh
executable file
·78 lines (63 loc) · 1.65 KB
/
bump-version.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
#!/usr/bin/env bash
#
# Copyright (C) 2014-2020, Markus Hubig <[email protected]>
#
set -e
BRANCH_NAME="$(git symbolic-ref HEAD 2>/dev/null)"
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
README_FILE="README.md"
README_TEMP=".README.md.new"
DOCKER_FILE="Dockerfile"
DOCKER_TEMP=".Dockerfile.new"
function push_hint () {
MSG1="Now please push the changes and the new tag like this:"
MSG2="git push && git push --tags"
echo "$MSG1 $MSG2"
}
function update_readme () {
sed -e "s/> The most resent version is: .*$/> The most resent version is: $1/g" \
-e "s/bump-version\.sh .*/bump-version\.sh $1/g" \
-e "s/(e.g. \`.*\`)/(e.g. \`$1\`)/g" \
$README_FILE > $README_TEMP
}
function update_docker () {
sed -e "s/^LABEL version=\".*\"$/LABEL version=\"$1\"/g" \
$DOCKER_FILE > $DOCKER_TEMP
}
function commit_version () {
git commit -m "Bumped version number to $1."
}
function tag_version () {
git tag "$1"
}
if [ $# -ne 1 ]; then
echo "usage: bump-version <version-id>"
exit 1
fi
if [[ ! $BRANCH_NAME = master ]]; then
echo "You need to be on master to use this script!"
exit 1
fi
if ! update_readme "$1"; then
echo "Could not bump version inside $README_FILE!" >&2
exit 2
else
mv $README_TEMP $README_FILE
git add $README_FILE
fi
if ! update_docker "$1"; then
echo "Could not bump version inside $DOCKER_FILE!" >&2
exit 2
else
mv $DOCKER_TEMP $DOCKER_FILE
git add $DOCKER_FILE
fi
if ! commit_version "$1"; then
echo "Could not commit the new version!" >&2
exit 2
fi
if ! tag_version "$1"; then
echo "Could not tag the new version!" >&2
exit 2
fi
push_hint "$1"