-
Notifications
You must be signed in to change notification settings - Fork 3
/
perform_release.sh
executable file
·75 lines (62 loc) · 1.69 KB
/
perform_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
#!/bin/bash
set -euo pipefail
RED='\033[0;31m' # Red Color
GREEN='\033[0;32m' # Green Color
NC='\033[0m' # No Color
print_message() {
echo -e "${GREEN}${1}${NC}"
}
remove_snapshot() {
print_message "Removing snapshot from pom"
mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
mvn clean deploy -Ppublish -Prelease
}
git_push() {
for remote in `git remote`; do
if [ "upstream" = ${remote} ]; then
print_message "push to ${remote} ${1}"
git push ${remote} ${1}
fi
done
}
git_commit() {
print_message "Commit: $1"
git add .
git commit -sm "build(release): $1"
git_push main
}
git_tag() {
version=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`
print_message "Creating tag v${version}"
git tag -s v${version} -m "v${version}"
git_push v${version}
}
next_version() {
version=${1:-}
if [[ ! -z $version ]]; then
echo "Using custom version ${version}"
mvn -B release:update-versions -DnewVersion=${version}
else
echo "Using default version"
mvn -B release:update-versions
fi
}
perform_release() {
remove_snapshot
git_commit "removed snapshot from version"
git_tag
next_version ${1:-}
mvn -B clean package -Ppublish
git_commit "updated next development version"
}
branch=`git branch --no-color --show-current`
if [ "main" != $branch ]; then
echo -e "${RED}Error: The release must be performed in the main branch. Current: ${branch}"
exit 1
fi
if [ ! -z "$(git status --porcelain)" ]; then
echo -e "${RED}Error: Make sure all changes are committed"
exit 1
fi
print_message "Performing release"
perform_release ${1:-''}