-
Notifications
You must be signed in to change notification settings - Fork 9
/
release.sh
executable file
·89 lines (73 loc) · 2.45 KB
/
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<HELP_USAGE
Usage:
$0 NEW_VERSION
Tags the master branch with given NEW_VERSION and pushes to upstream.
Ensures the current HEAD is master and has no untracked changes.
HELP_USAGE
exit 1
}
NEW_VERSION=${1:-""}
if [[ -z "$NEW_VERSION" ]]; then
echo "Error: First argument NEW_VERSION must be non-empty"
usage
fi
ERROR_OCCURRED=""
if [[ "$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" != "master" ]]; then
echo "Error: The current branch is not master"
ERROR_OCCURRED="1"
fi
if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: There are untracked changes. Please commit or stash them before releasing."
ERROR_OCCURRED="1"
fi
TAG_NAME="version-$NEW_VERSION"
if [[ "$(git tag -l "$TAG_NAME")" == "$TAG_NAME" ]]; then
echo "Error: Tag $TAG_NAME already exists locally"
ERROR_OCCURRED="1"
fi
echo "Running mvn verify...(be patient)"
if ! mvn -q verify >/dev/null; then
echo "Error: mvn verify has failed"
ERROR_OCCURRED="1"
fi
REMOTE_TRACKING_REF=$(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)" | tr -d "$IFS")
if [[ -z "${REMOTE_TRACKING_REF/[ ]*\n/}" ]]; then
echo "Error: No remote tracking ref found"
ERROR_OCCURRED="1"
fi
REMOTE_NAME=${REMOTE_TRACKING_REF%/*}
git fetch -q "$REMOTE_NAME" master
if [[ "$(git rev-list -1 FETCH_HEAD)" != "$(git rev-list -1 master)" ]]; then
echo "Error: Upstream is not in sync with local master. Please pull and/or push before releasing."
ERROR_OCCURRED="1"
fi
if git fetch -q "$REMOTE_NAME" $TAG_NAME 2>/dev/null; then
echo "Error: Tag $TAG_NAME already exists remotely"
ERROR_OCCURRED="1"
fi
if [[ -n "$ERROR_OCCURRED" ]]; then
exit 1
fi
echo "Releasing version $NEW_VERSION..."
mvn -q versions:set -DgenerateBackupPoms=false "-DnewVersion=$NEW_VERSION"
git commit -am "Release version $NEW_VERSION"
git tag "$TAG_NAME"
git push "$REMOTE_NAME" "refs/heads/master" "refs/tags/$TAG_NAME"
echo "Updating versions in README..."
sed -z -i -f - \
README.md \
<<SED_SCRIPT
s~\(\
[ ]*<dependency>\n\
[ ]*<groupId>de.qaware.tools.collection-cacheable-for-spring</groupId>\n\
[ ]*<artifactId>collection-cacheable-for-spring-starter</artifactId>\n\
[ ]*<version>\).*\(</version>\)\
~\1$NEW_VERSION\2~
SED_SCRIPT
git commit -am "Use released version in README"
mvn -q versions:set -DgenerateBackupPoms=false -DnextSnapshot=true >/dev/null
git commit -am "Start development on next version"
git push "$REMOTE_NAME" "refs/heads/master"