-
Notifications
You must be signed in to change notification settings - Fork 3
/
release
executable file
·44 lines (37 loc) · 1.78 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
44
#!/bin/bash
DIR="$(dirname "$0")"
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
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
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"/package.json | grep '"version":' | cut -d'"' -f4)"
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" \
&& ./integration-test/run-in-docker-compose \
&& sed -i -e "s/\"version\": \".*\"/\"version\": \"$PATCH_VERSION\"/" package.json \
&& git add package.json \
&& git commit -m "v$PATCH_VERSION" \
&& git push \
&& git tag "v$PATCH_VERSION" \
&& git push origin "v$PATCH_VERSION"
)