-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbamboobuild.sh
executable file
·203 lines (157 loc) · 5.16 KB
/
bamboobuild.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
#!/usr/bin/env bash
#---------------------------
# For iOS, this build script assumes that your iOS project
# has a target build scheme that is shared and
# that in your Build Settings, "Code Signing Resource Rules Path"
# is set to $(SDKROOT)/ResourceRules.plist
#---------------------------
EXPECTED_ARGS=2
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: ./bamboobuild.sh [platform (optional)] [environment (optional)]"
echo "ex: ./bamboobuild.sh ios production"
exit 1
fi
set -x
set -e
#---------------------------
#***************************
# App Specific Configuration
#***************************
#---------------------------
grunt shell:setShellVariables
if [ -e ".build-config" ]
then
source ".build-config"
else
echo "variable retrieval failed"
exit 1
fi
shouldUpload=false
shouldGenerateIcons=false
#---------------------------
#***************************
# End App Specific Configuration
#***************************
#---------------------------
#---------------------------
# Get Arguments
#---------------------------
platform="web"
env="production"
if [ "$1" ]
then
platform=$1
fi
if [ "$2" ]
then
env=$2
fi
#---------------------------
# Set PATH
#---------------------------
node_mods=$(pwd)/node_modules
export ANDROID_HOME=/usr/local/android
export PATH=/usr/local/bin/:$node_mods/grunt-cli/bin:$node_mods/bower/bin:$node_mods/cordova/bin:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
#---------------------------
# Set Variables
#---------------------------
#General
branchName="${bamboo_planRepository_branchName}"
semVerBranchName="${branchName//[^0-9a-zA-Z-]/-}"
shortHash="$(git rev-parse --short HEAD)"
buildPlanName="${bamboo_buildPlanName}"
buildNumber="${bamboo_buildNumber}"
revisionNumber="${bamboo_planRepository_revision}"
slug="${appName}-${platform}"
buildTimeStamp="${bamboo_buildTimeStamp}"
hockeyMessage="${slug}.${branchName}.${buildNumber}"
workingDirectory="${bamboo_build_working_directory}"
buildString="${branchName}-${buildNumber}"
#iOS
buildScheme="${appName}"
archiveFile="${appName}.xcarchive"
appFile="${appName}.app"
ipaFile="${appName}.ipa"
binaryFileName="${ipaFile}"
codesignIdentity="${bamboo_codesignIdentity}"
appleProvisionId="${bamboo_APPLE_PROVISION_ID}"
#Android
apkFile="${appName}.apk"
#web
buildFolder="${appName}-${buildNumber}-${revisionNumber}-${buildTimeStamp}"
#---------------------------
# generate icons
#---------------------------
if [ $shouldGenerateIcons == true ]
then
./icongen.sh ${appName} ${platform} ${env} ${buildString}
else
echo "Bypassing Icon Gen"
fi
#---------------------------
# Install dependencies
#---------------------------
npm install
#---------------------------
# Inject build info into project
#---------------------------
echo "{\"name\":\"$buildPlanName\",\"number\":\"$buildNumber\",\"revision\":\"$revisionNumber\",\"slug\":\"$slug\",\"branchname\":\"$branchName\",\"shorthash\":\"$shortHash\",\"timestamp\":\"$buildTimeStamp\"}" > version.json
cat version.json
cp version.json src/www/assets/version.json
#---------------------------
# Do iOS specific things
#---------------------------
if [ "$platform" == "ios" ]
then
binaryFileName="${ipaFile}"
hockeyAppId="${hockeyAppIdiOS}"
cordova --version
grunt build:$env:ios
(cd cordova/platforms/ios/ && xcodebuild -scheme "$buildScheme" -sdk iphoneos archive -archivePath "$archiveFile" CODE_SIGN_IDENTITY="$codesignIdentity" PROVISIONING_PROFILE=$appleProvisionId)
(cd cordova/platforms/ios/ && xcrun -sdk iphoneos PackageApplication -v "${archiveFile}/Products/Applications/${appFile}" -o "${workingDirectory}/${ipaFile}" --sign "$codesignIdentity")
fi
#---------------------------
# Do Android specific things
#---------------------------
if [ "$platform" == "android" ]
then
binaryFileName="${apkFile}"
hockeyAppId="${hockeyAppIdAndroid}"
(cd cordova/platforms/android/ && android update project -p ./ -t "android-21" -s)
(cd cordova/platforms/android/CordovaLib/ && android update project -p ./ -t "android-21" -s)
#(cd cordova/platforms/android/com.urbanairship.phonegap.PushNotification/SleepIQ-google-play-services/ && android update project -p ./ -t "android-21" -s)
#(cd cordova/platforms/android/com.urbanairship.phonegap.PushNotification/SleepIQ-urbanairship-lib/ && android update project -p ./ -t "android-21" -s)
cordova --version
mkdir -p cordova/platforms/android/assets
grunt build:$env:android
(cd cordova && cordova build android --release)
fi
if [ $shouldUpload == false ]
then
echo "Bypassing Upload"
exit
fi
#---------------------------
# Upload to Hockey App
#---------------------------
if [ "$platform" == "ios" -o "$platform" == "android" ]
then
curl -X POST https://rink.hockeyapp.net/api/2/apps/$hockeyAppId/app_versions \
-H "X-HockeyAppToken: $hockeyApiToken" \
-F status=2 \
-F "notes=$hockeyMessage" \
-F notes_type=1 \
-F "ipa=@$binaryFileName" \
-F commit_sha=$revisionNumber \
-F "teams=$hockeyAppTeams"
fi
#---------------------------
# Upload to Web Server
#---------------------------
if [ "$platform" == "web" ]
then
scp -r ./build/www ${serverUserName}@${serverAddress}:${serverRemoteFolder}/${buildFolder}
fi