-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkflow_all.yaml
357 lines (354 loc) · 15.7 KB
/
workflow_all.yaml
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# Current limitations:
# Codemagic doesn't parse xcode test logs to output in a nice format
# Codemagic doesn't parse test logs to output in a nice format
# Codemagic doesn't have scheduled builds
#
# You still have NEVERCODE_BUILD_NUMBER env var used. There are 3 ways to deal with it (let's say your Nevercode build has number 1068, and Codemagic's will be the first one):
# 1) Change it with BUILD_NUMBER (equivalent env var on Codemagic)
# 2) export the env var as `export NEVERCODE_BUILD_NUMBER=$(($BUILD_NUMBER + 1068))` right before your `xcode-project command`
# 3) set the build number with agvtool before the build script `cd Avios && agvtool new-version -all $(($BUILD_NUMBER + 1060))`
# Scripts are executed as separate processes, which means created in one script memory env vars won't be available in the next script
# That's why you need to save exports to a file and the source it in another script which will need those variables
# In the same time everything what you call from inside a script (e.g. nc_postclone.sh) is a subprocess and has access to the env vars available in the script
#
# Pay attention that strings encrypted as env vars can be used right away (e.g. NC_KEY_PASSWORD or GOOGLE_PLAY_CREDENTIALS), while files encrypted as env vars should be base64 decoded first (e.g. CM_CERTIFICATE)
#
# In a long run it would make sense to change the scirpts in the repository to use Codemagic's env vars, not Nevercode ones, and simplify the workflows
#
# For app store connect publishing you need to fill APP_STORE_CONNECT_APP_SPECIFIC_PASSWORD (see https://support.apple.com/en-us/HT204397)
# For slack notifications you need to first connect Slack (see https://docs.codemagic.io/publishing-yaml/distribution/#slack)
#
# Your apple certificates (CM_CERTIFICATE) is exported with empty password. If you change it to a certificate with password, you will need to add an env var CM_CERTIFICATE_PASSWORD
# and include it to the command as `keychain add-certificates --certificate /tmp/certificate.p12 --certificate-password $CM_CERTIFICATE_PASSWORD`
workflows:
test-pr:
name: Test PR
instance_type: mac_pro
max_build_duration: 120
environment:
vars:
FCI_CLONE_DEPTH: 1
# manual ios publishing
CM_CERTIFICATE:
CM_PROVISIONING_PROFILE:
CM_CERTIFICATE_PASSWORD:
# android code signing
CM_KEYSTORE_PATH:
CM_KEYSTORE:
CM_KEYSTORE_PASSWORD:
CM_KEY_ALIAS_PASSWORD:
CM_KEY_ALIAS_USERNAME:
#
SSH_KEY_GITHUB:
FASTLANE_PASSWORD:
MATCH_PASSWORD:
GCLOUD_SERVICE_CREDENTIALS:
GCLOUD_PROJECT: woven-voyage-217607
WEBHOOK_NOTIFICATION_URL:
APP_CENTER_TOKEN:
APP_CENTER_GROUP:
APP_CENTER_APP_ID:
FIREBASE_API_TOKEN: Encrypted()
FIREBASE_APP_ID:
FIREBASE_TESTER_GROUPS:
FIREBASE_TESTER_EMAILS:
xcode: 11.4.1
node: 12.13.1
cache:
cache_paths:
- $HOME/.fastlane
- $HOME/Carthage/Build/iOS/
- $FCI_BUILD_DIR/Carthage/Build/iOS/
triggering:
events:
- push
- pull_request
- tag
branch_patterns:
- pattern: 'test/*'
include: true
source: true
cancel_previous_builds: true
scripts:
- name: Redefine enverinment variables used in scripts after migration from Nevercode
script: |
mkdir $HOME/xunit_results
echo "export NEVERCODE_XUNIT_RESULTS_DIR=$HOME/xunit_results" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE=${CONTINUOUS_INTEGRATION}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_BRANCH=${FCI_BRANCH}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_BUILD_NUMBER=${BUILD_NUMBER}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_BUILD_DIR=${FCI_BUILD_DIR}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_EXPORT_DIR=${FCI_EXPORT_DIR}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_BUILD_OUTPUT_DIR=${FCI_BUILD_OUTPUT_DIR}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_REPO_SLUG=${FCI_REPO_SLUG}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_PULL_REQUEST=${FCI_PULL_REQUEST}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_PULL_REQUEST_NUMBER=${FCI_PULL_REQUEST_NUMBER}" >> ~/NEVERCODE_ENV_VARS.sh
echo "export NEVERCODE_XUNIT_RESULTS_DIR=$HOME/xunit_results" >> ~/NEVERCODE_ENV_VARS.sh
- name: Pre-build script
script: |
export NEVERCODE_BRANCH=$FCI_BRANCH
chmod +x NC_PRE_BUILD_SCRIPT.sh && ./NC_PRE_BUILD_SCRIPT.sh
# prepare repo
- name: Install dependencies
script: |
yarn install --non-interactive
cd ios
gem install bundler
bundle install --path "$HOME/vendor/bundle"
bundle update
bundle exec pod repo update
bundle exec pod install
- name: Ionic
script: |
ionic cordova platform remove android --nosave
ionic cordova platform add android --confirm --no-interactive --noresources
ionic cordova platform remove ios --nosave
ionic cordova platform add ios --confirm --no-interactive --noresources
ionic cordova build android --release --no-interactive --prod --device
############################################# build ios
- name: Set up keychain to be used for codesigning using Codemagic CLI 'keychain' command
script: keychain initialize
- name: Set up Provisioning profiles from environment variables
script: |
PROFILES_HOME="$HOME/Library/MobileDevice/Provisioning Profiles"
mkdir -p "$PROFILES_HOME"
PROFILE_PATH="$(mktemp "$PROFILES_HOME"/$(uuidgen).mobileprovision)"
echo ${CM_PROVISIONING_PROFILE} | base64 --decode > $PROFILE_PATH
echo "Saved provisioning profile $PROFILE_PATH"
- name: Set up signing certificate
script: |
echo $CM_CERTIFICATE | base64 --decode > /tmp/certificate.p12
keychain add-certificates --certificate /tmp/certificate.p12
- name: Set up code signing settings on Xcode project
script: xcode-project use-profiles
- name: Set up iOS codesigning
script: |
set -e
keychain initialize
PROFILES_HOME="$HOME/Library/MobileDevice/Provisioning Profiles"
mkdir -p "$PROFILES_HOME"
PROFILE_PATH="$(mktemp "$PROFILES_HOME"/$(uuidgen).mobileprovision)"
echo ${CM_PROVISIONING_PROFILE} | base64 --decode > $PROFILE_PATH
echo "\nSaved provisioning profile $PROFILE_PATH\n"
echo $CM_CERTIFICATE | base64 --decode > /tmp/certificate.p12
keychain add-certificates --certificate /tmp/certificate.p12
xcode-project use-profiles
- name: Build ipa
script: |
export NEVERCODE_BUILD_NUMBER=$(($BUILD_NUMBER + 1068))
xcode-project build-ipa \
--workspace Avios/BAExec.xcworkspace \
--scheme Test \
--config Test
# test ios
- name: Test
script: |
set -o pipefail
xcodebuild \
-workspace Avios/BAExec.xcworkspace \
-scheme Test \
-config Test \
-sdk iphonesimulator \
-enableCodeCoverage YES \
-destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.4' \
test | xcpretty 2>&1 | tee "/tmp/xcodebuild_logs/xcodetest.log"
############################### build android
- name: Set up local properties
script: echo "sdk.dir=$HOME/programs/android-sdk-macosx" > "$FCI_BUILD_DIR/local.properties"
- name: Install gradle wrapper
script: |
GRADLE=$(find $HOME/programs/gradle-*/bin -name gradle | sort -r | head -1)
GRADLE_URL=$(cat gradle/wrapper/gradle-wrapper.properties | grep -w distributionUrl | cut -d= -f2 | sed 's@\\@@g')
$GRADLE wrapper --gradle-distribution-url $GRADLE_URL
./gradlew --version
- name: Build aab
script: ./gradlew -b app/build.gradle.kts bundleToyotaSwitchableDebug
- name: Sign aab and generate universal APK
script: |
CM_KEYSTORE_PATH='/tmp/keystore.keystore'
echo $CM_KEYSTORE | base64 --decode > $CM_KEYSTORE_PATH
AAB_PATH=$(find app/build/outputs/bundle -name "*.aab" | head -1)
jarsigner \
-sigalg SHA1withRSA \
-digestalg SHA1 \
-keystore $CM_KEYSTORE_PATH \
-storepass $CM_KEYSTORE_PASSWORD \
-keypass $CM_KEY_ALIAS_PASSWORD \
$AAB_PATH $CM_KEY_ALIAS_USERNAME
android-app-bundle build-universal-apk \
--bundle $AAB_PATH \
--ks $CM_KEYSTORE_PATH \
--ks-pass $CM_KEYSTORE_PASSWORD \
--ks-key-alias $CM_KEY_ALIAS_USERNAME \
--key-pass $CM_KEY_ALIAS_PASSWORD
name: Sign APK
- name: Sign apk
script: |
set -e
UNSIGNED_APK_PATH=$(find app/build/outputs -name "*.apk" | head -1)
SIGNED_APK_PATH=$(echo $UNSIGNED_APK_PATH | sed 's/-unsigned//')
apksigner sign \
--ks $KEYSTORE_PATH \
--ks-pass pass:$KEYSTORE_PASSWORD \
--ks-key-alias $KEY_ALIAS \
--key-pass pass:$KEY_PASSWORD \
--in $UNSIGNED_APK_PATH \
--out $SIGNED_APK_PATH
rm $UNSIGNED_APK_PATH
- name: Launch emulator
script: |
cd $ANDROID_HOME/tools
emulator -avd emulator &
adb wait-for-device
- name: Test Android
script: |
set -e
./gradlew connectedAndroidTest
adb logcat -d > emulator.log
# android firebase test lab
- name: Build APK for tests
script: ./gradlew -b app/build.gradle.kts assembleToyotaSwitchableDebugAndroidTest
- name: Authorize gcloud service account
script: |
GCLOUD_SERVICE_CREDENTIALS_PATH=$FCI_BUILD_DIR/google-services-credentials.json
echo $GCLOUD_SERVICE_CREDENTIALS | base64 --decode > $GCLOUD_SERVICE_CREDENTIALS_PATH
gcloud auth activate-service-account --key-file=$GCLOUD_SERVICE_CREDENTIALS_PATH
gcloud config set project ${GCLOUD_PROJECT}
- name: Test
script: |
APP_PATH=$(find app/build/outputs/bundle -name "*.apk" | head -1)
TEST_PATH=$(find app/build/outputs/apk/androidTest -name "*.apk" | head -1)
gcloud firebase test android run \
--app "$APP_PATH" \
--test "$TEST_PATH" \
--device "model=G8142,version=25" \
--timeout "45m" \
--type "instrumentation" \
--use-orchestrator \
--environment-variables "clearPackageData=true,numShards=5,shardIndex=0" \
--quiet
#
- name: Execute lane trigger_simulator_reset
script: |
bundle exec fastlane trigger_simulator_reset
# changelog
- name: Create changelog to publish to slack and email
script: |
if [[ -z ${FCI_PREVIOUS_COMMIT} ]]
then
echo "No finished builds found to generate changelog"
else
echo "$(git-changelog generate --previous-commit $FCI_PREVIOUS_COMMIT)" | tee release_notes.txt
fi
- name: Publish to App Center
script: |
echo 'Installing App Center CLI tools'
npm install -g appcenter-cli
echo "Find build artifacts"
IPA_PATH=$(find build/ios/ipa -name "*.ipa" | head -1)
echo "Found ipa at $IPA_PATH"
if [[ -z $IPA_PATH ]]
then
echo "No ipas were found, skip publishing to App Center"
else
if [[ -z $FCI_PREVIOUS_COMMIT ]]
then
echo "No finished builds found to generate changelog"
export RELEASE_NOTES='App submission via Codemagic'
else
export RELEASE_NOTES=$(git-changelog generate --previous-commit $FCI_PREVIOUS_COMMIT)
echo "Release notes generated"
fi
echo "\n\nPublishing $IPA_PATH to App Center"
# appcenter distribute release \
# --group $APP_CENTER_GROUP \
# --file $IPA_PATH \
# --release-notes "$RELEASE_NOTES" \
# --app $APP_CENTER_APP_ID \
# --token $APP_CENTER_TOKEN \
# --quiet
fi
- name: Firebase App Distribution
script: |
echo "Find build artifacts"
APK_PATH=$(find app/build/outputs -name '*.apk' ! -name '*debug*' | head -1)
echo "Found apk at $APK_PATH"
if [[ -z $APK_PATH ]]
then
echo "No apk found, skip publishing to Firebase App Distribution"
else
if [[ -z $FCI_PREVIOUS_COMMIT ]]
then
echo "No finished builds found to generate changelog"
export RELEASE_NOTES='App submission via Codemagic'
else
export RELEASE_NOTES=$(git-changelog generate --previous-commit $FCI_PREVIOUS_COMMIT)
echo "Release notes generated"
fi
echo "\n\nPublishing $APK_PATH to Firebase App Distribution"
# firebase appdistribution:distribute $APK_PATH \
# --app $FIREBASE_APP_ID \
# --token $FIREBASE_API_TOKEN \
# --release-notes "$RELEASE_NOTES" \
# --testers $FIREBASE_TESTER_EMAILS \
# --groups $FIREBASE_TESTER_GROUPS
fi
publishing:
slack:
channel: '#'
email:
recipients:
google_play:
credentials: Encrypt(...)
track: alpha
app_store_connect:
apple_id: [email protected]
password: # please paste your app store connect app specific password
scripts:
- name: Webhook notification
script: |
export PROJECT_URL=https://codemagic.io/app/${FCI_PROJECT_ID}
export VERSION_CODE=$(grep -o "versionCode\s\+\d\+" app/build.gradle | awk '{ print $2 }')
export VERSION_NAME=$(awk '/versionName ".*"/{print $2}' app/build.gradle | tr -d \''"\')
payload(){
echo '{
"project": {
"name": "Lingvist Android",
"id": "'$FCI_PROJECT_ID'",
"url": "'$PROJECT_URL'"
},
"build": {
"id": "'$FCI_BUILD_ID'",
"branch": "'$FCI_BRANCH'",
"number": "'$BUILD_NUMBER'",
"version_code": "'$VERSION_CODE'",
"version_name": "'$VERSION_NAME'",
"url": "'$PROJECT_URL'/build/'$FCI_BUILD_ID'"
},
"commit": {
"hash": "'$FCI_COMMIT'",
"commit_subject": "'$(git show -s --format=%s)'",
"commit_body": "'$(git show -s --format=%b)'"
},
"artefacts": '$FCI_ARTIFACT_LINKS'
}'
}
curl $WEBHOOK_NOTIFICATION_URL \
--header "Content-Type: application/json" \
--request POST \
--data "$(payload)"
artifacts:
# ios artifacts
- build/ios/ipa/*.ipa
- /tmp/xcodebuild_logs/*.log
- $HOME/Library/Developer/Xcode/DerivedData/**/Build/**/*.dSYM
- $HOME/Library/Developer/Xcode/DerivedData/**/*.embeddedframework
# android artifacts
- app/build/reports
- app/build/test-results
- app/build/outputs/logs
- app/build/outputs/**/*.apk
- app/build/outputs/**/*.aab
- app/build/outputs/**/mapping.txt
- platforms/android/build/outputs/**/*.apk