forked from splinesoft/SSBuild
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSBuild.sh
executable file
·248 lines (195 loc) · 6.77 KB
/
SSBuild.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
244
245
246
247
248
#!/bin/bash
#
# SSBuild - a script to build your iOS app.
# https://github.com/splinesoft/SSBuild
#
# SSBuild performs these steps:
#
# 1. Downloads and installs your distribution provisioning profiles from Apple's Developer Center
# 2. Updates your app's major (marketing) and minor (build) version numbers
# 3. Installs your Cocoapods
# 4. Unlocks the OS X keychain to prepare for code signing
# 5. Builds, codesigns, and archives your app into an IPA
# 6. Zips your app's .dSYM.
# (Optional) Repeats steps 3-6 for an Adhoc (Testflight/Hockeyapp) build
# (Optional) Archives important build artifacts -- your IPA and .dSYM -- and uploads them to Amazon S3
#
# The SSBuild.sh script takes just one argument:
# the path to your MyApp.config file.
# Here's how you might run it:
#
# ./SSBuild.sh "/path/to/MyApp.config"
function failed
{
echo ""
echo "=> $1" 1>&2
echo ""
exit 1
}
function clean
{
[ -n "$OUTPUT" ] || failed "No \$OUTPUT specified!"
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT"
}
function uuid_from_profile
{
echo `grep -aA1 UUID "$1" | grep -o "[-A-Z0-9]\{36\}"`
}
function install_profiles
{
# remove old profiles and download distribution profiles
if [ -n "$PROVISIONING_PROFILES" ] && [ -n "$APPLE_UN" ] && [ -n "$APPLE_PW" ]; then
rm -rf "$PROVISIONING_PROFILES"
mkdir -p "$PROVISIONING_PROFILES"
cd "$PROVISIONING_PROFILES"
/usr/bin/ios profiles:download:all \
--type distribution \
-u "$APPLE_UN" \
-p "$APPLE_PW" \
&> /dev/null || failed "Failed Downloading Profiles"
# copy provisioning profiles to user library
FILES=$PROVISIONING_PROFILES/*.mobileprovision
for file in $FILES
do
PROFILE_UUID=`uuid_from_profile $file`
[ -n "$PROFILE_UUID" ] || failed "No UUID found in $file"
cp "$file" $HOME/Library/MobileDevice/Provisioning\ Profiles/${PROFILE_UUID}.mobileprovision || failed "Failed installing $file"
done
fi
}
##########
# Main build and package function.
# Call with these arguments:
# 1. Path to output directory (for CONFIGURATION_BUILD_DIR)
# 2. Defines (for GCC_PREPROCESSOR_DEFINITIONS)
# 3. Scheme (e.g. 'Release' or 'Adhoc')
# 4. Path to mobile provisioning profile
##########
function xc_package
{
echo "Building scheme \"$3\" => $1"
# cocoapods
echo "Installing Cocoapods..."
(cd $SRCROOT && (pod install --no-color || pod update --no-color)) || failed "Failed running 'pod install'"
# unlock keychain
echo "Unlocking keychain..."
/usr/bin/security list-keychains -s "$BUILD_KEYCHAIN"
/usr/bin/security default-keychain -d user -s "$BUILD_KEYCHAIN"
/usr/bin/security unlock-keychain -p "$BUILD_KEYCHAIN_PW" "$BUILD_KEYCHAIN" &> /dev/null || failed "Failed unlocking keychain"
# Calculated paths
APP_IPA="$1/$APPNAME.ipa"
APP_APP="$1/$APPNAME.app"
APP_DSYM="$1/$APPNAME.app.dSYM"
APP_DSYM_ZIP="$1/$APPNAME.dSYM.zip"
# xcodebuild
UUID=`uuid_from_profile "$4"`
[ -n "$UUID" ] || failed "Failed - missing provisioning profile UUID"
echo "Building!"
cd $BUILDROOT && bundle exec xcodebuild \
-workspace "$APPWORKSPACE" \
-scheme "$3" \
clean build \
CONFIGURATION_BUILD_DIR="$1" \
PROVISIONING_PROFILE="$UUID" \
CODE_SIGN_IDENTITY="$CODESIGN_ID" \
OTHER_CODE_SIGN_FLAGS="--keychain $BUILD_KEYCHAIN" \
GCC_PREPROCESSOR_DEFINITIONS="$2" | xcpretty -s || failed "Failed building"
# IPA
echo "Packaging IPA..."
/usr/bin/xcrun -sdk iphoneos \
PackageApplication $APP_APP \
-o $APP_IPA \
--embed "$4" || failed "Failed packaging"
# ZIP dSYM
echo "Zipping .dSYM..."
/usr/bin/zip -qr "$APP_DSYM_ZIP" "$APP_DSYM"
}
set -e
[ -n "$1" ] || failed "No config file specified!"
[ -e "$1" ] || failed "Config file \"$1\" does not exist or is unreadable."
# Location of this script
export BUILDROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$1" &> /dev/null
[ -n "$BUILDROOT" ] || failed "No \$BUILDROOT specified!"
echo "Building $APPNAME in $SRCROOT."
###########
# BEFORE CI
###########
echo "Installing bundle..."
(cd $BUILDROOT && bundle install &> /dev/null) || failed "Failed installing bundle. Try running 'sudo bundle install'"
# Remove output
echo "Cleaning output..."
clean &> /dev/null || failed "Failed clean"
# install distribution profiles
if [ -n "$PROVISIONING_PROFILES" ] && [ -n "$APPLE_UN" ]; then
echo "Installing distribution provisioning profiles for $APPLE_UN..."
install_profiles || failed "Failed installing profiles"
fi
# set marketing and build version
if [ -n "$MARKETINGVERSION" ]; then
echo "Setting App marketing version $MARKETINGVERSION..."
(cd $SRCROOT && /usr/bin/agvtool new-marketing-version $MARKETINGVERSION &> /dev/null) || failed "Failed setting marketing version"
else
echo "Skipping setting marketing version. Specify \$MARKETINGVERSION in your App.config."
fi
if [ -n "$BUILD_NUMBER" ]; then
echo "Setting build number $BUILD_NUMBER..."
(cd $SRCROOT && /usr/bin/agvtool new-version -all $BUILD_NUMBER &> /dev/null) || failed "Failed setting build number"
else
echo "Skipping setting build number. Specify \$BUILD_NUMBER."
fi
###############
# BUILD RELEASE
###############
if [ -n "$RELEASE_OUTPUT" ]; then
xc_package \
"$RELEASE_OUTPUT" \
"$RELEASE_DEFINES" \
"$RELEASE_SCHEME" \
"$RELEASE_PROFILE"
else
failed "Did you specify a release output location?"
fi
###########################
# BUILD ADHOC // TESTFLIGHT
###########################
if [ -n "$ADHOC_OUTPUT" ]; then
# add testflight sdk to podfile
echo "pod 'ARAnalytics/TestFlight'" >> $SRCROOT/Podfile
xc_package \
"$ADHOC_OUTPUT" \
"$ADHOC_DEFINES" \
"$ADHOC_SCHEME" \
"$ADHOC_PROFILE"
# I prefer to upload builds to Testflight with Jenkins
# because the Jenkins-Testflight plugin can include
# your recent commit history in the build notes.
#
# You could also upload to Testflight with Shenzen:
# https://github.com/nomad/shenzhen
#
#ipa distribute:testflight \
#-f IPA file \
#-d dSYM.zip file \
#-a Your api key \
#-T Your team token \
#-m Build notes
else
echo "Skipping Adhoc build"
fi
##################
# RESTORE KEYCHAIN
##################
/usr/bin/security list-keychains -s ~/Library/Keychains/login.keychain
/usr/bin/security default-keychain -d user -s ~/Library/Keychains/login.keychain
############
# S3 Archive
############
if [ -n "$S3_BUCKET" ]; then
s3cmd sync -rv --no-guess-mime-type \
--exclude '*.*' \
--include '*.ipa' --include '*.dSYM.zip' \
$OUTPUT/* \
s3://$S3_BUCKET/$JOB_NAME/$BUILD_NUMBER/
fi