forked from segmentio/analytics-swift
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·154 lines (132 loc) · 3.62 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
148
149
150
151
152
153
154
#!/bin/bash
PROJECT_NAME="Analytics-Swift"
PRODUCT_NAME="Segment"
LOWER_PRODUCT_NAME="$(echo ${PRODUCT_NAME} | tr '[:upper:]' '[:lower:]')"
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
# 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 `swift-create-xcframework` tool is installed.
# command will return non-zero if not.
if ! command -v swift-create-xcframework &> /dev/null
then
echo "Swift's create-xcframework tool is required, but could not be found."
echo "Install it via:"
echo " $ brew install mint"
echo " $ mint install unsignedapps/swift-create-xcframework"
echo ""
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' ]
then
echo "The 'main' must be the current branch to make a release."
echo "You are currently on: $branch"
exit 1
fi
versionFile="./sources/${PRODUCT_NAME}/Version.swift"
# get last line in version.swift
versionLine=$(tail -n 1 $versionFile)
# split at the =
version=$(cut -d "=" -f2- <<< "$versionLine")
# remove quotes and spaces
version=$(sed "s/[' \"]//g" <<< "$version")
echo "${PROJECT_NAME} 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%.*}.$((${1##*.}))"
echo "Preparing to release $newVersion..."
vercomp $newVersion $version
case $? in
0) op='=';;
1) op='>';;
2) op='<';;
esac
if [ $op != '>' ]
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...
# note: we do this here so the "Version x.x.x" commit doesn't show up in logs.
changelog=$(git log --pretty=format:"- (%an) %s" $(git describe --tags --abbrev=0 @^)..@)
tempFile=$(mktemp)
#write changelog to temp file.
echo -e "$changelog" >> $tempFile
# update sources/Segment/Version.swift
# - remove last line...
sed -i '' -e '$ d' $versionFile
# - add new line w/ new version
echo "internal let __${LOWER_PRODUCT_NAME}_version = \"$newVersion\"" >> $versionFile
# commit the version change.
git commit -am "Version $newVersion" && git push
# gh release will make both the tag and the release itself.
gh release create $newVersion -F $tempFile -t "Version $newVersion"
# remove the tempfile.
rm $tempFile
# build up the xcframework to upload to github
./build.sh
# upload the release
gh release upload $newVersion ${PRODUCT_NAME}.zip
gh release upload $newVersion ${PRODUCT_NAME}.sha256
# SPECIAL CASE: We need to upload Sovran and JSONSafeEncoding to save them time.
gh release upload $newVersion Sovran.zip
gh release upload $newVersion Sovran.sha256
gh release upload $newVersion JSONSafeEncoding.zip
gh release upload $newVersion JSONSafeEncoding.sha256