forked from immuni-app/immuni-app-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.yml
470 lines (423 loc) · 16.7 KB
/
config.yml
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# Immuni CircleCI configuration.
# Copyright (C) 2020 Presidenza del Consiglio dei Ministri.
# Please refer to the AUTHORS file for more information.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
version: 2.1
# Shared settings
settings:
xcode: &xcode_version
xcode: "11.7.0"
# Custom commands
commands:
build:
description: Perform a build of the Immuni iOS application.
steps:
- run:
name: "[build] Compile and archive"
command: |
fastlane ios build \
configuration:$BUILD_CONFIGURATION \
distribution_method:$DISTRIBUTION_METHOD \
signing:$SIGNING_PROFILE
- run:
name: "[build] Archive build products"
working_directory: Products
command: |
zip -r Immuni-${BUILD_CONFIGURATION}.zip Immuni.xcarchive
# Remove xcarchive to avoid storing it as a plain directory among the build artifacts
rm -rf Immuni.xcarchive
- run:
name: "[build] Create GitHub release"
command: |
RELEASE_NAME="Immuni-${APP_VERSION}build${BUILD_NUMBER}"
# Use -soft to prevent release from being re-created if it already exists
# This takes care of concurrency issues (the build would fail)
ghr \
-t $RELEASE_GITHUB_TOKEN \
-u $CIRCLE_PROJECT_USERNAME \
-r $CIRCLE_PROJECT_REPONAME \
-c $CIRCLE_SHA1 \
-n $RELEASE_NAME \
-soft \
$RELEASE_NAME Products | tee release_result
if grep -q aborted release_result; then
echo "A release with version $APP_VERSION and build number $BUILD_NUMBER already exists. Aborting."
exit 1
fi
- store_artifacts:
path: Products
- run:
name: "[build] Upload to App Store Connect"
no_output_timeout: 30m
command: |
if [[ "${BUILD_KIND}" == "release" ]]; then
fastlane ios upload_appstore
else
echo "This is not a production build, skipping the App Store Connect upload phase."
fi
check_build_kind:
description: Check whether the commit should trigger a build or not.
steps:
- run:
name: "[check] Identify build kind"
command: |
# Verify if it's a build commit
GIT_MESSAGE=$(git log --pretty=%s | head -1 || true)
if [[ ! $GIT_MESSAGE == *"#build"* ]]; then
echo "Not a build commit. Stopping the execution of the build job."
circleci-agent step halt
fi
# Check the build kind from the git message. The git message must contain either:
# "#build-release" or "#build-dev", depending on the kind of build.
BUILD_KIND="$(echo $GIT_MESSAGE | sed -n -E 's/^.*#build-(release|dev).*$/\1/p')"
if [[ -z "${BUILD_KIND}" ]]; then
echo "Unrecognized build kind; valid types are: dev, release."
circleci-agent step halt
fi
# Make it available for the rest of the pipeline
echo "export BUILD_KIND=$BUILD_KIND" >> $BASH_ENV
check_release_branch:
description: Verify if the commit of the build being released is on master.
steps:
- run:
name: "[release] Stop if not executed on master"
command: |
# Verify if the commit belongs to master
ON_MASTER=$(git branch --contains tags/$CIRCLE_TAG | grep '^. master$' || true)
if [[ -z "${ON_MASTER}" ]]; then
echo "Releases can only be tagged on master. Stopping the execution of the job."
exit 1
fi
compute_release_changelog:
description: Compute the release changelog based on conventional commits.
steps:
- run:
name: "[release] Compute changelog"
command: |
# Uses conventional-changelog-cli to compute a semantic changelog
# Configuration
CHANGELOG_HEADER_LINES=8
VERSION_REGEX='^v\([0-9]\+\.\?\)\+$'
# Retrieve the tags associated with the previous release and the newly tagged release
CURRENT_RELEASE_TAG=$CIRCLE_TAG
PREVIOUS_RELEASE_TAG=$(git tag -l | grep $VERSION_REGEX | sort -nr | head -2 | tail -1)
if [[ "${CURRENT_RELEASE_TAG}" == "${PREVIOUS_RELEASE_TAG}" ]]; then
echo "This is the first release of the project; its changelog must be set manually."
exit 1
fi
# Configure conventional-changelog
sed "s/PREVIOUS_RELEASE_TAG/$PREVIOUS_RELEASE_TAG/g" CI/changelog_config.tpl > CI/changelog_config.js
# Compute the changelog
conventional-changelog -p angular -n CI/changelog_config.js > FULL_CHANGELOG.md
# Skip the changelog header
awk 'NF {p=1} p' \<<< "$(< FULL_CHANGELOG.md)" | tail -n +$CHANGELOG_HEADER_LINES > CHANGELOG.md
install_ios_dependencies:
description: Install CocoaPods iOS dependencies.
steps:
- run:
name: "[cocoapods] Retrieve the Podfile.lock checksum"
command: sed -n '/PODFILE CHECKSUM:/p' Podfile.lock > podfile_checksum
- restore_cache:
name: "[cocoapods] Restore the cache"
keys:
- 1-pods-{{ checksum "podfile_checksum" }}
- 1-pods-
- run:
name: "[cocoapods] Install pods"
command: pod install
- save_cache:
name: "[cocoapods] Save the cache"
key: 1-pods-{{ checksum "podfile_checksum" }}
paths:
- ./Pods
post_release_changelog:
description: Update the changelog of the GitHub released that has been published on the store.
steps:
- run:
name: "[release] Post changelog"
command: |
# Configuration
FULL_REPO_NAME="$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
RELEASE_API="https://api.github.com/repos/$FULL_REPO_NAME/releases"
RELEASE_REGEX='^Immuni-\([0-9]\+\.\?\)\+build[0-9]\+$'
# Retrieve the existing release. Note: if multiple exist for the same commit,
# we take the latest.
MATCHING_TAG=$(git tag --points-at tags/$CIRCLE_TAG | grep $RELEASE_REGEX | sort -nr | head -1 || true)
if [[ -z "${MATCHING_TAG}" ]]; then
echo "No GitHub release associated with this version, halting."
exit 1
fi
RELEASE_ID=$(curl -H "Authorization: token $RELEASE_GITHUB_TOKEN" $RELEASE_API/tags/$MATCHING_TAG -s | jq -r '.id')
# Edit changelog
curl \
--request PATCH \
--header "Authorization: token $RELEASE_GITHUB_TOKEN" \
--data "`jq -n --arg msg "$(cat CHANGELOG.md)" '{body: $msg}'`" \
$RELEASE_API/$RELEASE_ID
prepare_xcode_project:
description: Prepare the Xcode project for compilation.
steps:
- run:
name: "[xcode_setup] Configure build kind"
command: |
# Ensure the startup script exists
touch $BASH_ENV
# Configure build kind
if [[ "${BUILD_KIND}" == "dev" ]]; then
export BUILD_CONFIGURATION="Debug"
export DISTRIBUTION_METHOD="development"
export SIGNING_PROFILE="development"
else
echo "export EXCLUDE_DEV_TOOLING='1'" >> $BASH_ENV
export BUILD_CONFIGURATION="Release"
export DISTRIBUTION_METHOD="app-store"
export SIGNING_PROFILE="appstore"
fi
echo "Performing $BUILD_CONFIGURATION build for $DISTRIBUTION_METHOD."
echo "export BUILD_CONFIGURATION=$BUILD_CONFIGURATION" >> $BASH_ENV
echo "export DISTRIBUTION_METHOD=$DISTRIBUTION_METHOD" >> $BASH_ENV
echo "export SIGNING_PROFILE=$SIGNING_PROFILE" >> $BASH_ENV
- run:
name: "[xcode_setup] Retrieve the app version"
command: |
APP_VERSION=$(cat version)
echo "Semantic version for this build is $APP_VERSION"
echo "export APP_VERSION=$APP_VERSION" >> $BASH_ENV
- run:
name: "[xcode_setup] Configure Xcode project"
command: CI_MODE=1 make immuni
- run:
name: "[xcode_setup] Increment the build number"
command: |
# Use the CircleCI workflow number as the build number.
# This guarantees a unique, monotonically increasing build number.s
BUILD_NUMBER=$CIRCLE_BUILD_NUM
fastlane run increment_build_number build_number:$BUILD_NUMBER
echo "export BUILD_NUMBER=$BUILD_NUMBER" >> $BASH_ENV
echo "Build number for this build is $BUILD_NUMBER"
setup_ci:
description: Configure the continuous integration.
steps:
- run:
name: "[ci_setup] Configure Fastlane for CircleCI"
command: |
fastlane run setup_circle_ci
echo "export KEYCHAIN_NAME=fastlane_tmp_keychain" >> $BASH_ENV
- run:
name: "[ci_setup] Install homebrew dependencies"
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install xcodegen swiftgen ghr
setup_code_signing:
description: Install the necessary signing certificates and provisioning profiles.
steps:
- run:
name: "[code_signing] Install signing certificate and provisioning profile"
command: |
if [[ "${SIGNING_PROFILE}" == "appstore" ]]; then
echo $APPSTORE_PROVISIONING_PROFILE | base64 --decode > profile.mobileprovision
echo $APPSTORE_SIGNING_CERTIFICATE | base64 --decode > signing_certificate.p12
export SIGNING_CERTIFICATE_PASSWORD=$APPSTORE_SIGNING_CERTIFICATE_PASSWORD
else
echo $DEVELOPMENT_PROVISIONING_PROFILE | base64 --decode > profile.mobileprovision
echo $DEVELOPMENT_SIGNING_CERTIFICATE | base64 --decode > signing_certificate.p12
export SIGNING_CERTIFICATE_PASSWORD=$DEVELOPMENT_SIGNING_CERTIFICATE_PASSWORD
fi
# Install signing certificate
fastlane run import_certificate \
certificate_path:signing_certificate.p12 \
certificate_password:$SIGNING_CERTIFICATE_PASSWORD \
keychain_name:$KEYCHAIN_NAME
# Install provisioning profile
fastlane run install_provisioning_profile path:profile.mobileprovision
setup_pr_tools:
description: Configure the pull requests environment.
steps:
- restore_cache:
name: "[pr_setup] Restore Linux binaries dependency cache"
keys:
- 1-linux-bin-pr-tools
- run:
name: "[pr_setup] Install swiftformat"
command: |
if [ ! -f $HOME/bin/swiftformat ]; then
# Setup Mint package manager for Swift
git clone https://github.com/yonaskolb/Mint.git
cd Mint
make
# Install swiftformat
mint install nicklockwood/SwiftFormat
mkdir $HOME/bin
cp /usr/local/bin/swiftformat $HOME/bin
fi
- save_cache:
name: "[pr_setup] Save Linux binaries dependency cache"
key: 1-linux-bin-pr-tools
paths:
- /root/bin
- run:
name: "[pr_setup] Move swiftformat binary"
command: cp $HOME/bin/swiftformat /usr/local/bin/swiftformat
- run:
name: "[pr_setup] Install danger"
command: |
# Install Node.js 12.x and npm
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
## Install the Yarn package manager
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install yarn
# Install Danger
yarn install --dev
setup_release_tools:
description: Configure the release environment.
steps:
- run:
name: "[release_setup] Install dependencies"
command: sudo npm install -g conventional-changelog-cli
jobs:
build:
macos:
<<: *xcode_version
resource_class: medium
steps:
- checkout:
name: "[build] Checkout the code"
- check_build_kind
- setup_ci
- prepare_xcode_project
- setup_code_signing
- install_ios_dependencies
- build
pr_check:
docker:
- image: norionomura/swiftlint:0.39.2_swift-5.1
resource_class: small
steps:
- run:
name: "[pr_check] Stop job if DANGER_GITHUB_API_TOKEN is missing"
command: |
if [[ -z "${DANGER_GITHUB_API_TOKEN}" ]]; then
circleci-agent step halt
fi
- run:
name: "[pr_check] Stop job if not running in PR"
command: |
if [[ -z "${CIRCLE_PULL_REQUEST}" ]]; then
circleci-agent step halt
fi
- checkout:
name: "[pr_check] Checkout the code"
- setup_pr_tools
- run:
name: "[pr_check] Run danger"
command: yarn danger ci
release:
docker:
- image: cimg/node:12.16
resource_class: small
steps:
- checkout:
name: "[release] Checkout the code"
- check_release_branch
- setup_release_tools
- compute_release_changelog
- post_release_changelog
scheduler:
docker:
- image: norionomura/swiftlint:0.39.2_swift-5.1
resource_class: small
steps:
- checkout
- run:
name: "[scheduler] Initialize scheduler submodule"
command: git submodule update --init
- run:
name: "[scheduler] Initialize Python runtime"
command: |
gpg --keyserver keyserver.ubuntu.com --recv 6A755776
gpg --export --armor 6A755776 | apt-key add -
cat \<<EOF > /etc/apt/sources.list.d/deadsnakes.list
deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial main
EOF
apt-get update
apt-get install -y python3.7-minimal
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.7 get-pip.py
- run:
name: "[scheduler] Setup project path"
command: echo "export PROJECT_PATH=$(pwd)" >> $BASH_ENV
- setup_pr_tools
- restore_cache:
name: "[scheduler] Restore Python Cache"
keys:
- pip-packages-v2-{{ .Branch }}-{{ checksum "scheduler/Pipfile.lock" }}
- pip-packages-v2-{{ .Branch }}-
- pip-packages-v2-
- run:
name: "[scheduler] Install dependencies"
working_directory: scheduler
environment:
PIPENV_NOSPIN: 1
PIPENV_VENV_IN_PROJECT: 1
command: |
pip install pipenv
pipenv install
- save_cache:
name: "[scheduler] Save Python Cache"
paths:
- ~/.cache/pip
- scheduler/.venv
key: pip-packages-v2-{{ .Branch }}-{{ checksum "scheduler/Pipfile.lock" }}
- run:
name: "[scheduler] Configure scheduler"
command: |
mv scheduler_config.json scheduler/config.json
- run:
name: "[scheduler] Run scheduler"
working_directory: scheduler
command: |
export REPOSITORY="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"
pipenv run python scheduler.py
workflows:
version: 2
build:
jobs:
- build:
context: ios
filters:
branches:
ignore:
- /pull\/.+/
pr_check:
jobs:
- pr_check:
context: danger
release:
jobs:
- release:
context: ios
filters:
branches:
ignore: /.*/
tags:
only: /^v(?:[0-9]+\.?)+$/
scheduler:
triggers:
- schedule:
cron: "0,15,30,45 * * * *"
filters:
branches:
only:
- development
jobs:
- scheduler:
context: scheduler