-
Notifications
You must be signed in to change notification settings - Fork 8
352 lines (296 loc) · 11.8 KB
/
build.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
name: Build, Test, Release
on:
push:
paths-ignore:
- "**.js"
- "**.json"
- .github/workflows/publish-firmware-bundles.yml
workflow_dispatch:
permissions:
contents: write
issues: write
actions: write
packages: write
env:
BUILD_IMAGE_NAME: hello-nrfcloud-firmware
TWISTER_IMAGE_NAME: hello-nrfcloud-firmware-twister
jobs:
# generate date string to be embedded in builds
date-string:
name: Generate date string
runs-on: ubuntu-22.04
outputs:
dateAsString: ${{ steps.dateAsString.outputs.dateAsString }}
steps:
- run: echo "$(date +'%Y%m%d%H%M%S')"
- name: Generate date string
id: dateAsString
run: echo "dateAsString=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
# generate version string to be embedded in builds
release-version:
name: Determine next release version
runs-on: ubuntu-22.04
outputs:
nextRelease: ${{ steps.version.outputs.nextRelease }}
steps:
- uses: actions/checkout@v4
- name: Determine next release version
uses: nordicsemiconductor/cloud-get-next-version-action@saga
id: version
with:
branch: saga
defaultVersion: "0.0.0-development-${{ github.sha }}"
- run: echo ${{ steps.version.outputs.nextRelease }}
docker:
name: Prepare docker image
runs-on: ubuntu-22.04
outputs:
docker_image: ${{ steps.docker-image-tag.outputs.docker_image }}
steps:
- name: Authenticate against Container Registry
run:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $
--password-stdin
- name: Checkout
uses: actions/checkout@v4
# Only rebuild the docker image of the contents of the files change that
# determine what goes into the Docker image
- name: Determine Docker image name and tag
id: docker-image-tag
run: |
IMAGE_VERSION=`cat Dockerfile west.yml | sha256sum | awk '{ print $1 }' | tr -d '\n'`
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$BUILD_IMAGE_NAME
echo "docker_image=${IMAGE_ID}:${IMAGE_VERSION}" >> $GITHUB_OUTPUT
echo "IMAGE_ID=${IMAGE_ID}" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION}" >> $GITHUB_ENV
- name: Check if Docker image exists
id: check-docker-image
continue-on-error: true
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: docker manifest inspect $IMAGE_ID:$IMAGE_VERSION
- name: Build Docker
if: steps.check-docker-image.outcome == 'failure'
run: docker buildx build -t $BUILD_IMAGE_NAME .
- name: Publish Docker image
if: steps.check-docker-image.outcome == 'failure'
run: |
docker tag $BUILD_IMAGE_NAME $IMAGE_ID:$IMAGE_VERSION
docker push $IMAGE_ID:$IMAGE_VERSION
docker-twister:
name: Prepare docker image for Twister
runs-on: ubuntu-22.04
outputs:
docker_image: ${{ steps.docker-image-tag.outputs.docker_image }}
steps:
- name: Authenticate against Container Registry
run:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $
--password-stdin
- name: Checkout
uses: actions/checkout@v4
# Only rebuild the docker image of the contents of the files change that
# determine what goes into the Docker image
- name: Determine Docker image name and tag
id: docker-image-tag
run: |
TWISTER_IMAGE_VERSION=`cat Dockerfile.twister | sha256sum | awk '{ print $1 }' | tr -d '\n'`
TWISTER_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$TWISTER_IMAGE_NAME
echo "docker_image=${TWISTER_IMAGE_ID}:${TWISTER_IMAGE_VERSION}" >> $GITHUB_OUTPUT
echo "TWISTER_IMAGE_ID=${TWISTER_IMAGE_ID}" >> $GITHUB_ENV
echo "TWISTER_IMAGE_VERSION=${TWISTER_IMAGE_VERSION}" >> $GITHUB_ENV
- name: Check if Docker image exists
id: check-docker-image
continue-on-error: true
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: docker manifest inspect $TWISTER_IMAGE_ID:$TWISTER_IMAGE_VERSION
- name: Build Docker
if: steps.check-docker-image.outcome == 'failure'
run: docker buildx build -t $TWISTER_IMAGE_NAME -f Dockerfile.twister .
- name: Publish Docker image
if: steps.check-docker-image.outcome == 'failure'
run: |
docker tag $TWISTER_IMAGE_NAME $TWISTER_IMAGE_ID:$TWISTER_IMAGE_VERSION
docker push $TWISTER_IMAGE_ID:$TWISTER_IMAGE_VERSION
test:
name: Run Twister tests
runs-on: ubuntu-22.04
needs: [docker-twister]
container:
image: ${{ needs.docker-twister.outputs.docker_image }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
CMAKE_PREFIX_PATH: /opt/toolchains
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: project
- name: Twister Tests
working-directory: project/asset_tracker_v2
run: |
/zephyr/scripts/twister -G --testsuite-root ./tests/
- name: Archive test result
if: failure()
uses: actions/upload-artifact@v3
with:
name: twister
path: project/asset_tracker_v2/twister-out
build:
name: Build
runs-on: ubuntu-22.04
container:
image: ${{ needs.docker.outputs.docker_image }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
needs: [release-version, date-string, docker]
env:
AWS_BROKER_HOSTNAME: iot.thingy.rocks
environment: production
# list variants to build
strategy:
matrix:
configuration:
- thingy91
- thingy91.dbg
- thingy91.lp.mmflt
- thingy91.sol
- thingy91.sol.dbg
- thingy91.sol.lp.mmflt
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: project
- name: Show nrfutil details
run: |
nrfutil --version
nrfutil list
nrfutil toolchain-manager list
# configure build {
- name: Build for Thingy:91
if: contains(matrix.configuration, 'thingy91')
run: echo 'BOARD=thingy91_nrf9160_ns' >> $GITHUB_ENV
- name: Build for nRF9160-DK
if: contains(matrix.configuration, 'nrf9160dk')
run: echo 'BOARD=nrf9160dk_nrf9160_ns' >> $GITHUB_ENV
- name: Add KConfig options unconditionally
working-directory: project/asset_tracker_v2
run: |
APP_VERSION=${{ needs.release-version.outputs.nextRelease }}+${{ matrix.configuration }}
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${APP_VERSION}\"" >> firmware.conf
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
echo "CONFIG_DATA_DEVICE_MODE_ACTIVE=y" >> firmware.conf
echo "CONFIG_LTE_PSM_REQ_RAT=\"00000000\"" >> firmware.conf
echo "CONFIG_CLOUD_CLIENT_ID_IMEI_PREFIX=\"oob-\"" >> firmware.conf
echo "CONFIG_NRF_CLOUD_SEC_TAG=42" >> firmware.conf
echo "CONFIG_DATA_DEVICE_MODE_ACTIVE=y" >> firmware.conf
echo "CONFIG_DATA_ACTIVE_TIMEOUT_SECONDS=60" >> firmware.conf
- name: Configure Memfault
if: contains(matrix.configuration, 'mmflt')
working-directory: project/asset_tracker_v2
run: |
echo "CONFIG_DEBUG_MODULE_MEMFAULT_USE_EXTERNAL_TRANSPORT=y" >> overlay-memfault.conf
echo "CONFIG_DEBUG_MODULE_MEMFAULT_HEARTBEAT_INTERVAL_SEC=3600" >> overlay-memfault.conf
echo "CONFIG_MEMFAULT_NCS_FW_VERSION_STATIC=y" >> overlay-memfault.conf
echo "CONFIG_MEMFAULT_NCS_FW_VERSION=\"${{ env.APP_VERSION }}\"" >> overlay-memfault.conf
echo "CONFIG_MEMFAULT_NCS_FW_TYPE=\"atv2\"" >> overlay-memfault.conf
echo "CONFIG_MEMFAULT_NCS_PROJECT_KEY=\"${{ vars.MEMFAULT_PROJECT_KEY }}\"" >> overlay-memfault.conf
echo MEMFAULT_OVERLAY=overlay-memfault.conf >> $GITHUB_ENV
- name: Configure Low-Power
working-directory: project/asset_tracker_v2
if: contains(matrix.configuration, 'lp')
run: echo CONFIG_OVERLAY=overlay-low-power.conf >> $GITHUB_ENV
- name: Configure Debug
working-directory: project/asset_tracker_v2
if: contains(matrix.configuration, 'dbg')
run: |
echo CONFIG_OVERLAY=overlay-debug.conf >> $GITHUB_ENV
echo "CONFIG_NRF_MODEM_LIB_TRACE=y" >> firmware.conf
- name: Configure Solar Shield
working-directory: project/asset_tracker_v2
if: contains(matrix.configuration, 'sol')
run: |
echo EXTRA_ARGS="-DSHIELD=powerfoyle" >> $GITHUB_ENV
- name: enable BSEC library to support Bosch BME680 Environmental sensor
if: contains(matrix.configuration, 'thingy91')
working-directory: /nrf/ext
run: |
wget -q ${{ secrets.BSEC_ARCHIVE_URL }} -O bsec.zip
unzip -q bsec.zip
ls BSEC_1.4.8.0_Generic_Release_updated_v3
echo BSEC_OVERLAY=overlay-bsec.conf >> $GITHUB_ENV
# }
- run: |
pwd
ls -la
printenv
- name: Build firmware
working-directory: project/asset_tracker_v2
run: |
nrfutil toolchain-manager launch /bin/bash -- -c '\
west build -b ${{ env.BOARD }} \
-p always -- \
${{ env.EXTRA_ARGS }} \
-DOVERLAY_CONFIG="${{ env.CONFIG_OVERLAY }};${{ env.MEMFAULT_OVERLAY }};${{ env.BSEC_OVERLAY }};firmware.conf" \
'
- name: Upload symbols file to Memfault
continue-on-error: true
if:
contains(matrix.configuration, 'mmflt') && github.ref ==
'refs/heads/saga' && (github.event_name == 'push' || github.event_name
== 'workflow_dispatch' || github.event_name == 'repository_dispatch')
working-directory: project/asset_tracker_v2
run: |
memfault \
--org-token ${{ secrets.MEMFAULT_ORGANIZATION_TOKEN }} \
--org ${{ vars.MEMFAULT_ORGANIZATION_SLUG }} \
--project ${{ vars.MEMFAULT_PROJECT_SLUG }} \
upload-mcu-symbols \
--software-type atv2 \
--software-version ${{ env.APP_VERSION }} \
build/zephyr/zephyr.elf
- name: Archive firmware
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name:
${{ matrix.configuration }}-${{
needs.date-string.outputs.dateAsString }}-${{ github.sha }}
path: |
project/asset_tracker_v2/build/zephyr/zephyr.elf
project/asset_tracker_v2/build/zephyr/merged.hex
project/asset_tracker_v2/build/zephyr/app_update.bin
project/asset_tracker_v2/build/zephyr/app_signed.hex
project/asset_tracker_v2/build/zephyr/zephyr.dts
project/asset_tracker_v2/build/zephyr/.config
release:
name: Release
runs-on: ubuntu-22.04
if:
github.ref == 'refs/heads/saga' && (github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' || github.event_name ==
'repository_dispatch')
needs: [build, test, release-version]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
- uses: cycjimmy/semantic-release-action@v4
id: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Trigger deployment workflow
if: steps.semantic-release.outputs.new_release_published == 'true'
run:
gh workflow run publish-firmware-bundles.yml --raw-field version=v${{
needs.release-version.outputs.nextRelease }}