-
Notifications
You must be signed in to change notification settings - Fork 6
/
new-release.sh
executable file
·68 lines (52 loc) · 1.92 KB
/
new-release.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
#!/usr/bin/env bash
set -eo pipefail
#
## Given version (and optional variant), this script creates & pushes a relevant git-tag.
#
# Required version
VERSION="$1"
# Optional variant
VARIANT="$2"
# Verify version to-be-released is provided
if [[ -z "$VERSION" ]]; then
>&2 printf "\nERR: version missing: version needs to be passed as the first argument. Try:\n"
>&2 printf "\t./%s %s\n\n" "$(basename "$0")" "v0.9.1"
exit 1
fi
# Get directory
DIR="$(echo "${VERSION#v}" | cut -d. -f-2)"
# If variant is provided, verify it exists
if [[ -n "$VARIANT" ]]; then
if [[ ! -f "$DIR/variant-$VARIANT.patch" ]]; then
>&2 printf "\nERR: variant missing: variant passed as the 2nd argument, but corresponding patch file is not present.\n"
>&2 printf "\tMake sure that './%s/variant-%s.patch' file exists.\n\n" "$DIR" "$VARIANT"
exit 1
fi
if ! patch --dry-run --quiet -d "$DIR" < "$DIR/variant-$VARIANT.patch"; then
>&2 printf "\nERR: variant broken: specified variant: '%s' does not apply cleanly\n" "$VARIANT"
>&2 printf "\tFix the errors, and run this command again.\n\n"
exit 1
fi
fi
# Verify there's no uncommitted changes in the working dir
if [[ -n "$(git status --untracked-files=no --porcelain)" ]]; then
>&2 printf "\nERR: working directory not clean. Commit, or stash changes to continue.\n\n"
exit 1
fi
if ! grep -q "$VERSION" "$DIR/Dockerfile" ; then
>&2 printf "\nERR: Requested version not present in Dockerfile. Make sure that's what you want to do.\n\n"
exit 1
fi
git fetch --tags
# Get last build number used for $VERSION
LAST=$(git tag | sed -n "s|^$VERSION.*+build||p" | sort -rn | head -n 1)
# Increment it
LAST=$((LAST+1))
# Construct the full $TAG, ex: `v0.10.1-variant+build666`
TAG="$VERSION${VARIANT:+-$VARIANT}+build$LAST"
printf "Creating tag: %s, " "$TAG"
git tag -sa "$TAG" -m "$TAG"
echo "done."
printf "Pushing tag: %s…\n" "$TAG"
git push origin "$TAG"
echo "All done."