-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·113 lines (96 loc) · 3.22 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
#!/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
# find the latest semantic version from the git tags
version=$(git tag | head -1)
while read tagVersion
do
if [ $(./scripts/semver.sh $tagVersion $version) == '1' ]
then
version=$tagVersion
fi
done <<< "$(git tag)"
echo "Analytics-Swift Appcues 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 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)
# write changelog to temp file.
echo "$changelog" >> $tempFile
cat $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