-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
Β·145 lines (123 loc) Β· 4.91 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
#!/bin/sh
# MIT License
#
# Copyright (c) 2021 Segment
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Original source: https://github.com/segmentio/analytics-swift/blob/main/release.sh
# check if `gh` tool is installed.
if ! command -v gh &> /dev/null
then
echo "Github CLI tool is required, but could not be found."
echo "Install it via: $ brew install gh"
exit 1
fi
# check if `gh` tool has auth access.
# command will return non-zero if not auth'd.
authd=$(gh auth status -t)
if [[ $? != 0 ]]
then
echo "ex: $ gh auth login"
exit 1
fi
# check that we're on the `main` branch
branch=$(git rev-parse --abbrev-ref HEAD)
if [ $branch != 'main' ] && [[ $branch != release/* ]]
then
echo "The 'main' must be the current branch to make a release."
echo "You are currently on: $branch"
exit 1
fi
if [ -n "$(git status --porcelain)" ]
then
echo "There are uncommited changes. Please commit and create a pull request or stash them.";
exit 1
fi
# check that the required maven central signing and auth vars are set
if [ -z ${GPG_SIGNING_KEY+x} ]; then echo "GPG_SIGNING_KEY must be set for Maven Central publishing"; exit 1; fi
if [ -z ${GPG_SIGNING_KEY_PWD+x} ]; then echo "GPG_SIGNING_KEY_PWD must be set for Maven Central publishing"; exit 1; fi
if [ -z ${OSSRH_USERNAME+x} ]; then echo "OSSRH_USERNAME must be set for Maven Central publishing"; exit 1; fi
if [ -z ${OSSRH_PASSWORD+x} ]; then echo "OSSRH_PASSWORD must be set for Maven Central publishing"; exit 1; fi
# read the properties file
while IFS= read -r line; do
key="${line%% =*}"
value="${line#*= }"
eval "$key"="'$value'"
done < ./segment-appcues/segment-appcues.properties
versionMajor=$VERSION_MAJOR
versionMinor=$VERSION_MINOR
versionPatch=$VERSION_PATCH
versionClassifier=$VERSION_CLASSIFIER
# construct the version string
version="$versionMajor.$versionMinor.$versionPatch"
if [ ! -z "$versionClassifier" ]
then
version="$version-$versionClassifier"
fi
echo "Segment-Appcues plugin current version: $version"
# no args, so give usage.
if [ $# -eq 0 ]
then
echo "Release automation script"
echo ""
echo "Usage: $ ./release.sh <version>"
echo " ex: $ ./release.sh \"1.0.2\""
exit 0
fi
newVersion="${1}"
echo "Preparing to release $newVersion..."
versionComparison=$(./scripts/semver.sh $newVersion $version)
if [ $versionComparison != '1' ]
then
echo "New version must be greater than previous version ($version)."
exit 1
fi
read -r -p "Are you sure you want to release $newVersion? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
;;
*)
exit 1
;;
esac
# get the components of the version string for the properties file update
newMajorVersion=$(echo $newVersion | cut -sd. -f1)
newMinorVersion=$(echo $newVersion | cut -sd. -f2)
newPatchVersion=$(echo $newVersion | cut -sd. -f3 | cut -d- -f1)
newVersionClassifier=$(echo $newVersion | cut -sd- -f2)
# update segment-appcues/segment-appcues.properties
sed -i '' "/^VERSION_MAJOR /s/=.*$/= $newMajorVersion/" ./segment-appcues/segment-appcues.properties
sed -i '' "/^VERSION_MINOR /s/=.*$/= $newMinorVersion/" ./segment-appcues/segment-appcues.properties
sed -i '' "/^VERSION_PATCH /s/=.*$/= $newPatchVersion/" ./segment-appcues/segment-appcues.properties
sed -i '' "/^VERSION_CLASSIFIER /s/=.*$/= $newVersionClassifier/" ./segment-appcues/segment-appcues.properties
# commit the version change.
git commit -am "π Update version to $newVersion"
git push
# get the commits since the last release, filtering ones that aren't relevant.
changelog=$(git log --pretty=format:"- [%as] %s (%h)" $(git describe --tags --abbrev=0 @^)..@ --abbrev=7 | sed '/[π§π¬πΈβ
π‘π]/d')
tempFile=$(mktemp)
echo $changelog
# write changelog to temp file.
echo "$changelog" >> $tempFile
# gh release will make both the tag and the release itself.
gh release create $newVersion -F $tempFile -t $newVersion
# remove the tempfile.
rm $tempFile
# publish to Maven Central
gradle segment-appcues:publishReleasePublicationToOSSRHRepository