forked from git-up/GitUp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
continuous-build.sh
executable file
·85 lines (61 loc) · 3.19 KB
/
continuous-build.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
#!/bin/sh -ex
EMAIL="$1"
ASC_PROVIDER="$2"
if [[ "$EMAIL" == "" || "$ASC_PROVIDER" == "" ]]; then
echo "Usage ./continuous-build.sh \"email\" \"asc_provider\". Run \`xcrun altool --list-providers -u email -p password\` to get potential asc_provider."
exit 1
fi
CHANNEL="continuous"
PRODUCT_NAME="GitUp"
APPCAST_NAME="appcast.xml"
MAX_VERSION=`git tag -l "b*" | sed 's/b//g' | sort -nr | head -n 1`
VERSION=$((MAX_VERSION + 1))
##### Archive and export app
rm -rf "build"
pushd "GitUp"
xcodebuild archive -scheme "Application" -archivePath "../build/$PRODUCT_NAME.xcarchive" "BUNDLE_VERSION=$VERSION"
xcodebuild -exportArchive -exportOptionsPlist "Export-Options.plist" -archivePath "../build/$PRODUCT_NAME.xcarchive" -exportPath "../build/$PRODUCT_NAME"
popd
FULL_PRODUCT_NAME="$PRODUCT_NAME.app"
PRODUCT_PATH="`pwd`/build/$PRODUCT_NAME/$FULL_PRODUCT_NAME" # Must be absolute path
ARCHIVE_NAME="$PRODUCT_NAME.zip"
ARCHIVE_PATH="build/$ARCHIVE_NAME"
##### Notarize zip file
ditto -c -k --keepParent "$PRODUCT_PATH" "$ARCHIVE_PATH"
UUID=`xcrun altool --notarize-app --primary-bundle-id "co.gitup.mac.zip" -u $EMAIL -p "@keychain:password" --asc-provider $ASC_PROVIDER --file $ARCHIVE_PATH | grep "RequestUUID = " | sed 's/^.*= //'`
if [ "$UUID" == "" ]; then
echo "No request UUID found"
exit 1
fi
while true; do
sleep 60
STATUS_CODE=`xcrun altool --notarization-info $UUID -u "$EMAIL" -p "@keychain:password" | grep "Status Code" | sed 's/^.*: //' | xargs`
if [ "$STATUS_CODE" == "0" ]; then
echo "Notarization Success! - $STATUS_CODE"
break
fi
echo "Not notarized yet - $STATUS_CODE"
done
##### Staple app and regenerate zip
xcrun stapler staple "$PRODUCT_PATH"
ditto -c -k --keepParent "$PRODUCT_PATH" "$ARCHIVE_PATH"
##### Tag build
git tag -f "b$VERSION"
git push -f origin "b$VERSION"
##### Upload to S3 and update Appcast
INFO_PLIST_PATH="$PRODUCT_PATH/Contents/Info.plist"
VERSION_ID=`defaults read "$INFO_PLIST_PATH" "CFBundleVersion"`
VERSION_STRING=`defaults read "$INFO_PLIST_PATH" "CFBundleShortVersionString"`
MIN_OS=`defaults read "$INFO_PLIST_PATH" "LSMinimumSystemVersion"`
BACKUP_ARCHIVE_NAME="$PRODUCT_NAME-$VERSION_ID.zip"
APPCAST_URL="https://s3-us-west-2.amazonaws.com/gitup-builds/$CHANNEL/$APPCAST_NAME"
ARCHIVE_URL="https://s3-us-west-2.amazonaws.com/gitup-builds/$CHANNEL/$ARCHIVE_NAME"
BACKUP_ARCHIVE_URL="https://s3-us-west-2.amazonaws.com/gitup-builds/$CHANNEL/$BACKUP_ARCHIVE_NAME"
APPCAST_PATH="GitUp/SparkleAppcast.xml"
ARCHIVE_SIZE=`stat -f "%z" "$ARCHIVE_PATH"`
EDITED_APPCAST_PATH="build/appcast.xml"
perl -p -e "s|__APPCAST_TITLE__|$PRODUCT_NAME|g;s|__APPCAST_URL__|$APPCAST_URL|g;s|__VERSION_ID__|$VERSION_ID|g;s|__VERSION_STRING__|$VERSION_STRING|g;s|__ARCHIVE_URL__|$ARCHIVE_URL|g;s|__ARCHIVE_SIZE__|$ARCHIVE_SIZE|g;s|__MIN_OS__|$MIN_OS|g" "$APPCAST_PATH" > "$EDITED_APPCAST_PATH"
aws s3 cp "$ARCHIVE_PATH" "s3://gitup-builds/$CHANNEL/$BACKUP_ARCHIVE_NAME"
aws s3 cp "s3://gitup-builds/$CHANNEL/$BACKUP_ARCHIVE_NAME" "s3://gitup-builds/$CHANNEL/$ARCHIVE_NAME"
aws s3 cp "$EDITED_APPCAST_PATH" "s3://gitup-builds/$CHANNEL/$APPCAST_NAME"
osascript -e 'display notification "Successfully completed continuous build" with title "GitUp Script" sound name "Hero"'