-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelease.sh
executable file
·147 lines (120 loc) · 3.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
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
#!/bin/bash -e
# Constants & Variables
VERSION_FILE=build.gradle.kts
# Functions
function isVersionValid {
local VERSION_PARAM=$1
if [[ -n "$VERSION_PARAM" ]] && [[ ! "$VERSION_PARAM" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version '$VERSION_PARAM' does not match pattern major.minor.fixes"
exit 1
fi
}
function readVersion {
local CURRENT_VERSION=$(grep "val appVersionName = " ${VERSION_FILE} | xargs echo | cut -d ' ' -f 4)
echo "${CURRENT_VERSION}"
}
function setVersion {
local VERSION="$1"
sed -i '' -E "s/(val appVersionName = )\".+\"/\1\"$VERSION\"/" ${VERSION_FILE}
}
function getNextSnapshotVersion {
local VERSION="$1"
local MAJOR=${VERSION%%.*}
local MINOR=${VERSION%.*}
local MINOR=${MINOR##*.}
local FIXES=${VERSION##*.}
local NEW_FIXES=$((FIXES+1))
echo "$MAJOR.$MINOR.$NEW_FIXES-SNAPSHOT"
}
# Checks
## Check that a version parameter was provided and that it's the correct format
VERSION_PARAM=$1
if ! isVersionValid "${VERSION_PARAM}"; then
exit 1
fi
## Check that the current git branch is develop
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" != "develop" ]]; then
echo "Current branch is '$CURRENT_BRANCH', should be 'develop'"
exit 1
fi
## Check that gitflow has been configured
if ! grep -q gitflow .git/config; then
echo "It looks like gitflow is not configured"
exit 1
fi
## Get and check current version
CURRENT_VERSION=$(readVersion)
if [[ "$CURRENT_VERSION" != *"-SNAPSHOT" ]]; then
echo "The current version ($CURRENT_VERSION) doesn't end with -SNAPSHOT"
exit 1
fi
# Release process
## Prepare parameters
CURRENT_VERSION=$(readVersion)
VERSION_RELEASE=$(test -z "${VERSION_PARAM}" && echo "${CURRENT_VERSION%-*}" || echo "${VERSION_PARAM}")
VERSION_SNAPSHOT=$(getNextSnapshotVersion "${VERSION_RELEASE}")
## Explain what will happen
echo
echo "Current version: $CURRENT_VERSION"
echo "Release version: $VERSION_RELEASE"
echo "Working version: $VERSION_SNAPSHOT"
echo
echo -ne "\rHit Ctrl-C if something's wrong, release in 3"
sleep 1
echo -ne "\rHit Ctrl-C if something's wrong, release in 2"
sleep 1
echo -ne "\rHit Ctrl-C if something's wrong, release in 1"
sleep 1
echo -ne "\rHit Ctrl-C if something's wrong, release in 0"
sleep 1
echo
echo
## Execute release
echo "Pulling main"
git checkout main
git pull
echo
echo "Pulling develop"
git checkout develop
git pull
echo
echo "Starting Git Flow Release $VERSION_RELEASE"
git flow release start "${VERSION_RELEASE}"
echo
echo "Setting version in $VERSION_FILE to $VERSION_RELEASE"
setVersion "${VERSION_RELEASE}"
echo
echo "Syncing XCode app version"
./gradlew setXcodeVersion
echo
echo "Committing changes to $VERSION_FILE"
git add ${VERSION_FILE} xcode
git commit -m "Set version to $VERSION_RELEASE for release"
echo
echo "Finishing Git Flow Release $VERSION_RELEASE"
export GIT_MERGE_AUTOEDIT=no
git flow release finish -m "Tagging version $VERSION_RELEASE"
unset GIT_MERGE_AUTOEDIT
echo
echo "Setting version in $VERSION_FILE to $VERSION_SNAPSHOT"
setVersion "${VERSION_SNAPSHOT}"
echo
echo "Syncing XCode app version"
./gradlew setXcodeVersion
echo
echo "Committing changes to $VERSION_FILE"
git add ${VERSION_FILE} xcode
git commit -m "Set version to $VERSION_SNAPSHOT for development"
echo
echo "Pushing main"
git checkout main
git push -u origin main
echo
echo "Pushing develop"
git checkout develop
git push -u origin develop
echo
echo "Pushing tags"
git push origin --tags
echo