-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrelease.sh
More file actions
147 lines (114 loc) · 4.07 KB
/
release.sh
File metadata and controls
147 lines (114 loc) · 4.07 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
# fail if any commands fails
set -e
assert_false() {
local expression=$1
local message=$2
if [[ $(eval "$expression") ]]; then
echo "Assertion failed: (>$expression) - $message"
exit 1
fi
}
assert_eq() {
if [[ "$1" != "$2" ]]; then
echo "$3"
exit 1
fi
}
assert_not_empty() {
# check if the first argument is empty after trimming
if [[ -z "${1//[[:space:]]/}" ]]; then
echo "$2"
exit 1
fi
}
get_current_branch() { git rev-parse --abbrev-ref HEAD; }
assert_on_branch() {
local branch=$1
local current_branch
current_branch=$(get_current_branch)
if [[ "$current_branch" != "$branch" ]]; then
echo "Not on branch $branch, aborting."
exit 1
fi
}
confirm() {
local message=$1
local response
read -p "$message [n]: " response
response=${response:-n}
if [[ "$response" != "y" ]]; then
echo "Aborting."
exit 1
fi
}
assert_clean_branch() { assert_false "git status --porcelain" "There are uncommitted changes, aborting."; }
increment_version() { echo "$1" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g'; }
assert_tag_not_exists() { assert_false "git tag -l $1" "Tag $1 already exists, aborting."; }
assert_branch_not_exist() { assert_false "git branch -l $1" "Branch $1 already exists, aborting."; }
get_current_project_version() {
# shellcheck disable=SC2155
local OUTPUT=$(./gradlew -q printVersion)
# shellcheck disable=SC2155
local VERSION=$(echo "$OUTPUT" | tr '\n' ' ' | awk '{print $NF}')
echo "$VERSION"
}
prompt_for_version() {
local default_version=$1
read -p "Enter the version [$default_version]: " actual_default_version
actual_default_version=${actual_default_version:-$default_version}
echo "$actual_default_version"
}
assert_branch_is_up_to_date() {
git fetch
HEAD=$(git rev-parse HEAD)
UPSTREAM=$(git rev-parse '@{u}')
assert_eq "$HEAD" "$UPSTREAM" "Local branch is not up-to-date, aborting."
}
update_version_in_properties_and_readme() {
echo "Updating README.md and gradle.properties to [$1]"
sed -i -e "s/implementation 'io\.github\.kayr:fuzzy-csv:.*-groovy3'/implementation 'io.github.kayr:fuzzy-csv:$1-groovy3'/g" README.md
sed -i -e "s/implementation 'io\.github\.kayr:fuzzy-csv:.*-groovy4'/implementation 'io.github.kayr:fuzzy-csv:$1-groovy4'/g" README.md
sed -i -e "s/VERSION_NAME=.*/VERSION_NAME=$1/g" gradle.properties
}
MAIN_BRANCH="master"
CURRENT_BRANCH=$(get_current_branch)
RELEASE_VERSION=$(get_current_project_version)
RELEASE_VERSION_INCREMENTED=$(increment_version "$RELEASE_VERSION")
echo "check the current branch is clean"
assert_clean_branch
echo "check the current branch is up-to-date"
assert_branch_is_up_to_date
echo "check the current branch is $MAIN_BRANCH"
assert_eq "$CURRENT_BRANCH" "$MAIN_BRANCH" "Not on branch $MAIN_BRANCH, aborting."
NEW_VERSION=$(prompt_for_version "$RELEASE_VERSION_INCREMENTED")
assert_not_empty "$NEW_VERSION" "Version cannot be empty"
echo "check tag [$NEW_VERSION] and branch [release/$NEW_VERSION] does not exist"
assert_tag_not_exists "$NEW_VERSION"
assert_branch_not_exist "release/$NEW_VERSION"
echo " -> Creating branch release/$NEW_VERSION"
git checkout -b "release/$NEW_VERSION"
echo " -> Updating README.md and gradle.properties to [$NEW_VERSION]"
update_version_in_properties_and_readme "$NEW_VERSION"
echo " -> Committing changes"
git commit -am "Release $NEW_VERSION"
echo " -> Pushing branch release/$NEW_VERSION"
git push --set-upstream origin "release/$NEW_VERSION"
echo " -> Run Tests"
make test
echo " -> Publish groovy 3"
make publish-groovy3
echo " ####### Successfully published groovy 3 artifacts #########"
echo " -> Publish groovy 4"
make publish-groovy4
echo " ####### Successfully published groovy 4 artifacts #########"
echo " -> Creating tag $NEW_VERSION"
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION"
echo " -> Pushing tag $NEW_VERSION"
git push origin "$NEW_VERSION"
echo " -> Switching to branch $MAIN_BRANCH"
git checkout "$MAIN_BRANCH"
echo " -> Merging branch release/$NEW_VERSION into $MAIN_BRANCH"
git merge "release/$NEW_VERSION"
echo " -> Pushing branch $MAIN_BRANCH"
git push