-
Notifications
You must be signed in to change notification settings - Fork 0
/
release
executable file
·43 lines (36 loc) · 1.67 KB
/
release
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
#!/bin/bash
DIR="$(dirname "$0")"
if [ -n "$(echo "v$1" | sed -e 's/v[0-9]\+\.[0-9]\+\.[0-9]\+//')" ]; then
echo "Usage: $0 VERSION, where VERSION is like '1.0.0'" >&2
exit 1
fi
if (cd "$DIR" && git status --short | grep -E '.'); then
echo "You have unsaved changes. Please git commit or reset them and run this again." >&2
exit 1
fi
PATCH_VERSION="$1"
MINOR_VERSION="${PATCH_VERSION%.*}"
MAJOR_VERSION="${MINOR_VERSION%.*}"
version_too_small() {
echo "Cannot release v${PATCH_VERSION} because the latest release on this branch is already ${OLD_PATCH_VERSION}." >&2
exit 1
}
OLD_PATCH_VERSION=$(cat "$DIR"/VERSION)
MAJOR_VERSION_INT=$(echo $PATCH_VERSION | cut -d. -f1)
MINOR_VERSION_INT=$(echo $PATCH_VERSION | cut -d. -f2)
PATCH_VERSION_INT=$(echo $PATCH_VERSION | cut -d. -f3)
OLD_MAJOR_VERSION_INT=$(echo $OLD_PATCH_VERSION | cut -d. -f1)
OLD_MINOR_VERSION_INT=$(echo $OLD_PATCH_VERSION | cut -d. -f2)
OLD_PATCH_VERSION_INT=$(echo $OLD_PATCH_VERSION | cut -d. -f3)
if [ $MAJOR_VERSION_INT -lt $OLD_MAJOR_VERSION_INT ]; then version_too_small; fi
if [ $MAJOR_VERSION_INT -eq $OLD_MAJOR_VERSION_INT ] && [ $MINOR_VERSION_INT -lt $OLD_MINOR_VERSION_INT ]; then version_too_small; fi
# Let user re-release the current version, in case something went wrong last release
if [ $MAJOR_VERSION_INT -eq $OLD_MAJOR_VERSION_INT ] && [ $MINOR_VERSION_INT -eq $OLD_MINOR_VERSION_INT ] && [ $PATCH_VERSION_INT -lt $OLD_PATCH_VERSION_INT ]; then version_too_small; fi
(cd "$DIR" \
&& docker build . \
&& echo "$PATCH_VERSION" > VERSION \
&& (git diff --quiet || git commit -m "v$PATCH_VERSION" VERSION) \
&& git push \
&& git tag "v$PATCH_VERSION" \
&& git push origin "v$PATCH_VERSION"
)