forked from wix-incubator/DetoxInstruments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseVersion.sh
executable file
·243 lines (191 loc) · 9.46 KB
/
releaseVersion.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash -e
# This script is responsible for creating a release and getting all the gears in motion
# so that cask, appcast and GitHub releases are all updated with the new release.
# Prerequisites:
# $GITHUB_RELEASES_TOKEN should be valid and include a GitHub OAuth 2 token with at least repo permission.
# See https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ and https://github.com/settings/tokens
# jq for json parsing and querying.
# brew install jq
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ ! "$BRANCH" = "master" ]; then
printf >&2 "\033[1;31mNot on master branch, performing a dry run\033[0m\n"
DRY_RUN="1"
else
if [ "$1" = "--dry" ]; then
DRY_RUN=$1
fi
fi
if [ -z "$DRY_RUN" ]; then
XCODEVERSION=$(xcodebuild -version | grep -oEi "([0-9]*(\.[0-9]*)+)")
XCODENEWESTSUPPORTED="12.4"
if [ ${XCODEVERSION} != ${XCODENEWESTSUPPORTED} ] && [ "${XCODEVERSION}" = "`echo -e "${XCODEVERSION}\n${XCODENEWESTSUPPORTED}" | sort --version-sort -r | head -n1`" ]; then
printf >&2 "\033[1;31mUnsupported Xcode, aborting\033[0m\n"
exit 1;
fi
fi
NO_DOCS="1"
if [ "$1" = "docs" ]; then
NO_DOCS="0"
fi
if [ ! -z "$DRY_RUN" ]; then
printf >&2 "\033[1;31mPerforming a dry run\033[0m\n"
fi
if [ -z "$DRY_RUN" ]; then
if [[ -n $(git status --porcelain) ]]; then
printf >&2 "\033[1;31mCannot release version because there are unstaged changes, aborting.\nChanges:\033[0m\n"
git status --short
exit -1
fi
fi
if [[ -n $(git log --branches --not --remotes) ]]; then
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mPushing pending commits to git\033[0m"
git push
fi
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mCreating release notes\033[0m"
RELEASE_NOTES_FILE=Distribution/_tmp_release_notes.md
# rm -f "${RELEASE_NOTES_FILE}"
touch "${RELEASE_NOTES_FILE}"
open -Wn "${RELEASE_NOTES_FILE}"
if ! [ -s "${RELEASE_NOTES_FILE}" ]; then
echo -e >&2 "\033[1;31mNo release notes provided, aborting\033[0m"
rm -f "${RELEASE_NOTES_FILE}"
exit -1
fi
fi
Scripts/updateCopyright.sh
Scripts/updateContributors.sh
if [ "$NO_DOCS" == "0" ]; then
echo -e "\033[1;34mUpdating acknowledgements and Apple Help\033[0m"
Scripts/updateAcknowledgements.sh
Scripts/updateHelp.sh || :
fi
echo -e "\033[1;34mBuilding archive and exporting\033[0m"
ARCHIVE=Distribution/Archive.xcarchive
EXPORT_DIR=Distribution/Export
rm -fr Distribution/*.zip
rm -fr "${ARCHIVE}"
rm -fr "${EXPORT_DIR}"
export CODE_SIGNING_REQUIRED=NO && xcodebuild -project DetoxInstruments/DetoxInstruments.xcodeproj -scheme "Detox Instruments" -configuration release clean archive -archivePath "${ARCHIVE}" DTXBundleName="Detox Instruments" ASSETCATALOG_COMPILER_APPICON_NAME="AppIcon"
xcodebuild -project DetoxInstruments/DetoxInstruments.xcodeproj -exportArchive -archivePath "${ARCHIVE}" -exportOptionsPlist Distribution/exportOptions.plist -exportPath "${EXPORT_DIR}"
SHORT_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${EXPORT_DIR}"/*.app/Contents/Info.plist)
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${EXPORT_DIR}"/*.app/Contents/Info.plist)
VERSION="${SHORT_VERSION}"."${BUILD_NUMBER}"
ZIP_FILE=Distribution/DetoxInstruments-v"${SHORT_VERSION}".b"${BUILD_NUMBER}".zip
echo -e "\033[1;34mVersion is: $VERSION\033[0m"
echo -e "\033[1;34mCreating ZIP file\033[0m"
ditto -c -k --sequesterRsrc --keepParent "${EXPORT_DIR}"/*.app "${ZIP_FILE}" &> /dev/null
# https://developer.apple.com/documentation/security/notarizing_your_app_before_distribution/customizing_the_notarization_workflow
echo -e "\033[1;34mSubmitting to notarization service\033[0m"
NOTARIZATION_UUID=$(xcrun altool --notarize-app --primary-bundle-id "com.wix.DetoxInstruments" --username "[email protected]" --password "@keychain:notary_password" --file "$ZIP_FILE" 2>&1 | grep RequestUUID | awk '{print $3}')
echo -e "\033[1;34mAwaiting notarization success for ${NOTARIZATION_UUID}\033[0m"
NOTARIZATION_SUCCESS=0
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
PROGRESS=$(xcrun altool --notarization-info "${NOTARIZATION_UUID}" --username "[email protected]" --password "@keychain:notary_password" 2>&1 )
Echo "${PROGRESS}"
if [ $? -ne 0 ] || [[ "${PROGRESS}" =~ "Invalid" ]] ; then
echo -e >&2 "\033[1;31mNotarization failed\033[0m"
exit -1
break
fi
if [[ "${PROGRESS}" =~ "success" ]]; then
NOTARIZATION_SUCCESS=1
break
fi
sleep 30
done
if [ $NOTARIZATION_SUCCESS -ne 1 ] ; then
echo -e >&2 "\033[1;31mNotarization timed out\033[0m"
exit -1
fi
echo -e "\033[1;34mStapling notarization ticket\033[0m"
xcrun stapler staple "${EXPORT_DIR}/Detox Instruments.app"
echo -e "\033[1;34mCreating stapled ZIP file\033[0m"
rm "${ZIP_FILE}"
ditto -c -k --sequesterRsrc --keepParent "${EXPORT_DIR}"/*.app "${ZIP_FILE}" &> /dev/null
echo -e "\033[1;34mUpdating archive with submission\033[0m"
SUBMISSION_IN_ARCHIVE="${ARCHIVE}/Submissions/${NOTARIZATION_UUID}"
mkdir -p "${SUBMISSION_IN_ARCHIVE}"
cp -r "${EXPORT_DIR}/Detox Instruments.app" "${SUBMISSION_IN_ARCHIVE}/"
LOG_URL=$(xcrun altool --notarization-info "${NOTARIZATION_UUID}" --username "[email protected]" --password "@keychain:notary_password" 2>&1 | grep LogFileURL | awk '{print $2}')
curl -o "${SUBMISSION_IN_ARCHIVE}/audit.log" "${LOG_URL}" &> /dev/null
/usr/libexec/PlistBuddy -c "Add Distributions array" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0 dict" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:destination string upload" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:identifier string ${NOTARIZATION_UUID}" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:task string distribute" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:teamID string S3GLW74Y8N" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:uploadDestination string 'Developer ID'" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:uploadEvent:shortTitle string Uploaded" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:uploadEvent:state string success" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:uploadEvent:title string 'Uploaded to Apple'" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:uploadEvent:date date $(date)" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:preparationEvent:shortTitle string Prepared" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:preparationEvent:state string success" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:preparationEvent:title string 'Prepared archive for uploading'" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:preparationEvent:date date $(date)" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:processingCompletedEvent:shortTitle string 'Ready to distribute'" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:processingCompletedEvent:state string success" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:processingCompletedEvent:title string 'Ready to distribute'" ${ARCHIVE}/Info.plist
/usr/libexec/PlistBuddy -c "Add Distributions:0:processingCompletedEvent:date date $(date)" ${ARCHIVE}/Info.plist
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mUpdating cask with latest release\033[0m"
pushd . &> /dev/null
cd Distribution/homebrew-brew/Casks/
git checkout master
git fetch
git pull --rebase
sed -i '' -e 's/url .*/url '"'https:\/\/github.com\/wix\/DetoxInstruments\/releases\/download\/${VERSION}\/$(basename ${ZIP_FILE})'"'/g' detox-instruments.rb
git add -A
git commit -m "Detox Instruments ${VERSION}" &> /dev/null
git push
popd &> /dev/null
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mPushing updated versions\033[0m"
git add -A &> /dev/null
git commit -m "${VERSION}" &> /dev/null
git push
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mCreating a GitHub release\033[0m"
gh release create --repo wix/DetoxInstruments "$VERSION" --title "$VERSION" --notes-file "${RELEASE_NOTES_FILE}"
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mUploading ZIP attachment to release\033[0m"
gh release upload --repo wix/DetoxInstruments "$VERSION" "${ZIP_FILE}"
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mTriggering gh-pages rebuild\033[0m"
curl -H "Authorization: token ${GITHUB_RELEASES_TOKEN}" -H "Content-Type: application/json; charset=UTF-8" -X PUT -d '{"message": "Rebuild GH Pages", "committer": { "name": "PublishScript", "email": "[email protected]" }, "content": "LnB1Ymxpc2gK", "sha": "3f949857e8ed4cb106f9744e40b638a7aabf647f", "branch": "gh-pages"}' https://api.github.com/repos/wix/DetoxInstruments/contents/.publish | jq "."
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mCreating an NPM release\033[0m"
pushd . &> /dev/null
cd Distribution
mv package package.json
NPM_VERSION="${SHORT_VERSION}"
if [[ $(echo ${NPM_VERSION} | grep -o "\." | grep -c "\.") == 1 ]]; then
NPM_VERSION="${NPM_VERSION}."
fi
NPM_VERSION="${NPM_VERSION}${BUILD_NUMBER}"
npm version "${NPM_VERSION}" --allow-same-version &> /dev/null
npm publish
mv package.json package
git checkout package
popd &> /dev/null
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mOpening archive in Xcode\033[0m"
open "${ARCHIVE}"
sleep 8
fi
if [ -z "$DRY_RUN" ]; then
echo -e "\033[1;34mCleaning up\033[0m"
rm -f "${RELEASE_NOTES_FILE}"
rm -f "${ZIP_FILE}"
rm -fr "${ARCHIVE}"
rm -fr "${EXPORT_DIR}"
fi