This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
494 lines (408 loc) · 16.3 KB
/
build-and-release.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
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
name: Build and Release
on:
push:
paths:
- "**.c"
- "**.h"
- "**.feature"
- "Kconfig"
- ".github/workflows/build-and-release.yaml"
- "west.yml"
- "*.conf"
repository_dispatch:
types:
- source-update
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
STACK_NAME: ${{ secrets.STACK_NAME }}
CI: 1
FORCE_COLOR: 3
jobs:
# This generates a unique build id (which is also different for re-runs) to
# be used in the artifact names to be able to distinguish them when
# downloading the artifact files.
build-id:
name: Generate build ID
runs-on: ubuntu-latest
outputs:
id: ${{ steps.id.outputs.id }}
steps:
- name: Generate build ID
id: id
run: |
ID=`uuidgen`
echo "::set-output name=id::${ID}"
broker:
name: Determine broker hostname
runs-on: ubuntu-latest
steps:
- name: Determine the AWS IoT broker hostname
id: broker-hostname
run: |
BROKER_HOSTNAME=`AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION=${{ env.AWS_REGION }} aws iot describe-endpoint --endpoint-type iot:Data-ATS | jq '.endpointAddress' -r | tr -d '\n'`
echo ${BROKER_HOSTNAME}
if [ -z "$BROKER_HOSTNAME" ]; then echo "Failed to discover broker hostname."; exit 1; fi
echo ${BROKER_HOSTNAME} > broker.conf
- uses: actions/upload-artifact@v3
with:
name: broker
path: broker.conf
release-version:
name: Determine next release version
runs-on: ubuntu-latest
outputs:
nextRelease: ${{ steps.version.outputs.nextRelease }}
steps:
- uses: actions/checkout@v3
- name: Determine next release version
uses: nordicsemiconductor/cloud-get-next-version-action@saga
id: version
with:
branch: saga
defaultVersion: "0.0.0-development"
- run: echo ${{ steps.version.outputs.nextRelease }}
build:
runs-on: ubuntu-latest
needs: [broker, release-version]
strategy:
matrix:
board: [thingy91_nrf9160_ns, nrf9160dk_nrf9160_ns]
loglevel: [debug, nodebug]
steps:
- uses: actions/checkout@v3
with:
path: firmware
- name: Configure Version
run: |
APP_VERSION=${{ needs.release-version.outputs.nextRelease }}-${{ matrix.board }}-${{ matrix.loglevel }}
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${APP_VERSION}\"" >> firmware/firmware.conf
- uses: actions/download-artifact@v3
with:
name: broker
- name: Configure the AWS IoT broker hostname
run: |
BROKER_HOSTNAME=`cat broker.conf`
echo "CONFIG_AWS_IOT_BROKER_HOST_NAME=\"${BROKER_HOSTNAME}\"" >> firmware/firmware.conf
- run: cat firmware/firmware.conf
- name: Pull Docker image
run: docker pull nrfassettracker/nrfconnect-sdk:main
- name: Build with debug enabled
if: matrix.loglevel == 'debug'
run: |
docker run --rm -v ${PWD}:/workdir/project nrfassettracker/nrfconnect-sdk:main /bin/bash -c 'cd firmware && west init -l && west update --narrow -o=--depth=1 && west build -p always -b ${{ matrix.board }} -- -DOVERLAY_CONFIG="overlay-aws.conf;overlay-pgps.conf;overlay-debug.conf;asset-tracker-cloud-firmware-aws.conf;firmware.conf" -DEXTRA_CFLAGS="-Werror=format-truncation"'
- name: Build with debug disabled
if: matrix.loglevel != 'debug'
run: |
docker run --rm -v ${PWD}:/workdir/project nrfassettracker/nrfconnect-sdk:main /bin/bash -c 'cd firmware && west init -l && west update --narrow -o=--depth=1 && west build -p always -b ${{ matrix.board }} -- -DOVERLAY_CONFIG="overlay-aws.conf;overlay-pgps.conf;asset-tracker-cloud-firmware-aws.conf;firmware.conf" -DEXTRA_CFLAGS="-Werror=format-truncation"'
- name: Copy firmware
run: |
cp firmware/build/zephyr/merged.hex ./
cp firmware/build/zephyr/app_signed.hex ./
cp firmware/build/zephyr/app_update.bin ./
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.board }}-${{ matrix.loglevel }}-${{ github.sha }}
path: |
merged.hex
app_signed.hex
app_update.bin
firmware.conf
e2e-credentials:
name: Create device credentials for end-to-end test
runs-on: ubuntu-latest
needs: [build-id]
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- name: Generate device ID
run: |
DEVICE_ID=`uuidgen`
echo "DEVICE_ID=${DEVICE_ID}" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: "16.x"
- uses: actions/checkout@v3
- name: Clone nRF Asset Tracker for AWS
run: |
git clone `cat package.json | jq -r '.cloud.repository'` cloud
- name: Install dependencies
run: |
cd cloud
npm ci
- name: Compile TypeScript
run: |
cd cloud
npx tsc
- name: Keep CA certificates around
uses: actions/cache@v3
with:
path: cloud/certificates
key: certificates-2020-01-20
- name: Check if CA certificate exists
run: |
ls ./cloud/certificates/*/rootCA.pem 1> /dev/null 2>&1
echo "SKIP_CERT_GENERATION=1" >> $GITHUB_ENV
continue-on-error: true
- name: Create CA certificate
if: env.SKIP_CERT_GENERATION != '1'
run: |
cd cloud
node cli create-ca
- name: Create device credentials
run: |
cd cloud
node cli create-simulator-cert -d ${{ env.DEVICE_ID }}
- name: Copy credentials
run: |
mkdir e2e-credentials
cp cloud/certificates/*/device-${{ env.DEVICE_ID }}* e2e-credentials
- uses: actions/upload-artifact@v3
with:
name:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path: |
e2e-credentials/*
- name: Remove device certificates
run: rm -vf ./cloud/certificates/*/device*
e2e-firmware:
name: Build firmware for end-to-end test
runs-on: ubuntu-latest
needs: [e2e-credentials, broker, build-id]
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- uses: actions/checkout@v3
with:
path: firmware
- uses: actions/download-artifact@v3
with:
name:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
- name: Set device id
run: |
echo "DEVICE_ID=`find e2e-credentials-${{ matrix.board }}-${{
needs.build-id.outputs.id }} -name \*.json | head -n 1 | xargs cat | jq -r '.clientId'`" >> $GITHUB_ENV
- name: Configure Version
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
run: |
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${{ env.APP_VERSION }}-original\"" >> firmware/firmware.conf
- name: Disable GPS
run: echo "CONFIG_GNSS_MODULE=n" >> firmware/firmware.conf
- name: Disable nRF Cloud Assisted GPS
run: |
echo "CONFIG_AGPS=n" >> firmware/firmware.conf
echo "CONFIG_AGPS_SRC_NRF_CLOUD=n" >> firmware/firmware.conf
- uses: actions/download-artifact@v3
with:
name: broker
- name: Configure the AWS IoT broker hostname
run: |
BROKER_HOSTNAME=`cat broker.conf`
echo "CONFIG_AWS_IOT_BROKER_HOST_NAME=\"${BROKER_HOSTNAME}\"" >> firmware/firmware.conf
- name: Set MQTT client ID to test device
run: |
echo "CONFIG_CLOUD_CLIENT_ID_USE_CUSTOM=y" >> firmware/firmware.conf
echo "CONFIG_AWS_IOT_CLIENT_ID_MAX_LEN=40" >> firmware/firmware.conf
echo "CONFIG_CLOUD_CLIENT_ID=\"${{ env.DEVICE_ID }}\"" >> firmware/firmware.conf
- run: cat firmware/firmware.conf
- name: Pull Docker image
run: docker pull nrfassettracker/nrfconnect-sdk:main
- name: Build
run: |
docker run --rm -v ${PWD}:/workdir/project nrfassettracker/nrfconnect-sdk:main /bin/bash -c 'cd firmware && west init -l && west update --narrow -o=--depth=1 && west build -p always -b ${{ matrix.board }} -- -DOVERLAY_CONFIG="overlay-aws.conf;overlay-debug.conf;asset-tracker-cloud-firmware-aws.conf;firmware.conf" -DEXTRA_CFLAGS="-Werror=format-truncation"'
cp firmware/build/zephyr/merged.hex firmware.hex
cp firmware/build/zephyr/app_update.bin firmware.bin
cp firmware/firmware.conf firmware.conf
- name: Build with changed version for FOTA test
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
run: |
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${{ env.APP_VERSION }}-upgraded\"" >> firmware/firmware.conf
docker run --rm -v ${PWD}:/workdir/project nrfassettracker/nrfconnect-sdk:main /bin/bash -c 'cd firmware && west build -p always -b ${{ matrix.board }} -- -DOVERLAY_CONFIG="overlay-aws.conf;overlay-debug.conf;asset-tracker-cloud-firmware-aws.conf;firmware.conf" -DEXTRA_CFLAGS="-Werror=format-truncation"'
cp firmware/build/zephyr/app_update.bin fota-upgrade.bin
cp firmware/firmware.conf fota-upgrade.conf
- uses: actions/upload-artifact@v3
with:
name:
e2e-firmware-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path: |
firmware.hex
firmware.bin
firmware.conf
fota-upgrade.hex
fota-upgrade.bin
fota-upgrade.conf
e2e-device:
name: Run the firmware for the end-to-end tests on a real device
runs-on: [self-hosted, firmware-ci]
env:
# Disables TLS certificate verification on Node.js which might be not
# possible if behind a (corporate) firewall
NODE_TLS_REJECT_UNAUTHORIZED: 0
outputs:
connected: ${{ steps.device.outputs.connected }}
needs:
- e2e-firmware
- e2e-credentials
- broker
- build-id
# While not needed, don't run expensive e2e tests if "build" steps fails
- build
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- uses: actions/download-artifact@v3
with:
name:
e2e-firmware-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
- uses: actions/download-artifact@v3
with:
name:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
- name: Set device id
run: |
echo "DEVICE_ID=`find e2e-credentials-${{ matrix.board }}-${{
needs.build-id.outputs.id }} -name \*.json | head -n 1 | xargs cat | jq -r '.clientId'`" >> $GITHUB_ENV
- uses: actions/download-artifact@v3
with:
name: broker
- name: Configure the AWS IoT broker hostname
run: |
BROKER_HOSTNAME=`cat broker.conf`
echo "BROKER_HOSTNAME=${BROKER_HOSTNAME}" >> $GITHUB_ENV
- name: Run firmware on real device
uses: NordicSemiconductor/cloud-aws-firmware-ci-device-action@saga
id: device
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
with:
device id: ${{ env.DEVICE_ID }}
app version: ${{ env.APP_VERSION }}
aws access key id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws secret access key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws region: ${{ secrets.AWS_REGION }}
broker hostname: ${{ env.BROKER_HOSTNAME }}
stack name: ${{ secrets.STACK_NAME }}
hex file: firmware.hex
fota file: fota-upgrade.bin
abort on: |
aws_fota: Error (-7) when trying to start firmware download
aws_iot_integration: aws_iot_hub_init, error
end on: |
aws_iot_integration: cloud_wrap_init: Version: ${{ env.APP_VERSION }}-upgraded
"appV"
"${{ env.APP_VERSION }}-upgraded"
event_manager: CLOUD_EVT_DATA_ACK
timeout in minutes: 20
sec tag: 42
certificate location:
./e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id
}}
target: ${{ matrix.board }}
- uses: actions/upload-artifact@v3
with:
name: e2e-run-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path: |
device.log
flash.log
job.json
e2e-credentials-${{ matrix.board }}-${{
needs.build-id.outputs.id }}
firmware.hex
fota-upgrade.bin
e2e-tests:
name: Run the end-to-end test
runs-on: ubuntu-latest
needs:
- e2e-firmware
- e2e-device
- broker
- build-id
# Wait for build step here, otherwise entire workflow will not pass, so running the expensive e2e test is pointless
- build
if: needs.e2e-device.outputs.connected == 'true'
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
- uses: actions/download-artifact@v3
with:
name: e2e-run-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path: e2e-run-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
- name: Set device id
run: |
echo "DEVICE_ID=`find e2e-credentials-${{ matrix.board }}-${{
needs.build-id.outputs.id }} -name \*.json | head -n 1 | xargs cat | jq -r '.clientId'`" >> $GITHUB_ENV
- uses: actions/download-artifact@v3
with:
name: broker
- name: Configure the AWS IoT broker hostname
run: |
BROKER_HOSTNAME=`cat broker.conf`
echo "BROKER_HOSTNAME=${BROKER_HOSTNAME}" >> $GITHUB_ENV
- name: Run feature tests
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
uses: NordicSemiconductor/cloud-aws-firmware-ci-feature-runner-action@saga
with:
device id: ${{ env.DEVICE_ID }}
app version: ${{ env.APP_VERSION }}
aws access key id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws secret access key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws region: ${{ secrets.AWS_REGION }}
broker hostname: ${{ env.BROKER_HOSTNAME }}
stack name: ${{ secrets.STACK_NAME }}
feature dir: features
log dir: e2e-run-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
target: ${{ matrix.board }}
- name: Remove test device
if:
${{ !contains(toJSON(github.event.commits.*.message),
'[skip-cleanup]') }}
run: |
CERT_ARN=`aws iot list-thing-principals --thing-name ${{ env.DEVICE_ID }} | jq -r '.principals[0]'`
CERT_ID=`echo $CERT_ARN | cut -d'/' -f2`
aws iot detach-thing-principal --thing-name ${{ env.DEVICE_ID }} --principal $CERT_ARN
aws iot update-certificate --certificate-id $CERT_ID --new-status INACTIVE
aws iot delete-certificate --certificate-id $CERT_ID
aws iot delete-thing --thing-name ${{ env.DEVICE_ID }}
release:
name: Release
runs-on: ubuntu-latest
if:
github.ref == 'refs/heads/saga' && (github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' || github.event_name ==
'repository_dispatch')
needs: [build, e2e-tests]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- run: npx semantic-release