Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

source-update

source-update #552

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:
permissions:
id-token: write
contents: write
issues: write
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-22.04
outputs:
id: ${{ steps.id.outputs.id }}
steps:
- name: Generate build ID
id: id
run: |
ID=`uuidgen`
echo "id=${ID}" >> $GITHUB_OUTPUT
# This generates a string containing the current date which is used in
# in artifact names to simpify locating and distinguishing them once they have
# been downloaded
date-string:
name: Generate string containing the current date
runs-on: ubuntu-22.04
outputs:
dateAsString: ${{ steps.dateAsString.outputs.dateAsString }}
steps:
- name: Generate date string
id: dateAsString
run: echo "dateAsString=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
release-version:
name: Determine next release version
runs-on: ubuntu-22.04
outputs:
nextRelease: ${{ steps.version.outputs.nextRelease }}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # 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 }}
build:
runs-on: ubuntu-22.04
environment:
name: production
needs: [release-version, date-string]
strategy:
matrix:
board: [thingy91_nrf9160_ns, nrf9160dk_nrf9160_ns]
loglevel: [debug, nodebug]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
path: firmware
- name: Configure Version
working-directory: firmware
run: |
APP_VERSION=${{ needs.release-version.outputs.nextRelease }}-${{ matrix.board }}-${{ matrix.loglevel }}
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${APP_VERSION}\"" >> firmware.conf
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
- name: Configure the Azure IoT DPS ID scope
working-directory: firmware
run: |
echo "CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE=\"${{ secrets.AZURE_IOT_HUB_DPS_ID_SCOPE }}\"" >> firmware.conf
- run: cat firmware/firmware.conf
- name: Build with debug enabled
working-directory: firmware
if: matrix.loglevel == 'debug'
run: |
docker run --rm -v ${PWD}:/workdir/project nordicplayground/nrfconnect-sdk:main west build -p always -b ${{ matrix.board }} --build-dir /workdir/project/build -- -DOVERLAY_CONFIG="overlay-azure.conf;overlay-pgps.conf;overlay-debug.conf;asset-tracker-cloud-firmware-azure.conf;firmware.conf" -DEXTRA_CFLAGS="-Werror"
- name: Build with debug disabled
working-directory: firmware
if: matrix.loglevel != 'debug'
run: |
docker run --rm -v ${PWD}:/workdir/project nordicplayground/nrfconnect-sdk:main west build -p always -b ${{ matrix.board }} --build-dir /workdir/project/build -- -DOVERLAY_CONFIG="overlay-azure.conf;overlay-pgps.conf;asset-tracker-cloud-firmware-azure.conf;firmware.conf" -DEXTRA_CFLAGS="-Werror"
- name: Copy firmware
working-directory: firmware
run: |
cp build/zephyr/merged.hex ../
cp build/zephyr/app_signed.hex ../
cp build/zephyr/app_update.bin ../
cp firmware.conf ../
- uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name:
${{ matrix.board }}-${{ matrix.loglevel }}-${{
needs.date-string.outputs.dateAsString }}-${{ 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-22.04
environment:
name: production
if: ${{ !contains(toJSON(github.event.commits.*.message), '[skip-e2e]') }}
needs: [build-id]
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
env:
LOCATION: ${{ secrets.LOCATION }}
APP_NAME: ${{ secrets.APP_NAME }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
AZURE_IOT_HUB_DPS_ID_SCOPE: ${{ secrets.AZURE_IOT_HUB_DPS_ID_SCOPE }}
steps:
- name: Generate device ID
run: |
DEVICE_ID=`uuidgen | cut -d- -f1`
echo "DEVICE_ID=${DEVICE_ID}" >> $GITHUB_ENV
- name: Login to Azure
uses: azure/login@v1
id: azure-login
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: List Azure accounts
run: az account list --output table
- uses: actions/setup-node@v3
with:
node-version: "18.x"
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Clone nRF Asset Tracker for Azure
run: git clone `cat package.json | jq -r '.cloud.repository'` cloud
- name: Install dependencies
working-directory: cloud
run: npm ci
- name: Compile TypeScript
working-directory: cloud
run: npx tsc
- name: Keep CA certificates around
uses: actions/cache@v3
id: certificates
with:
path: cloud/certificates
key: certificates
- name: Create Intermediate CA certificate
if: steps.certificates.outputs.cache-hit != 'true'
working-directory: cloud
run: |
./cli.sh create-ca-root
./cli.sh create-ca-intermediate
- name: Create device credentials
working-directory: cloud
run: |
./cli.sh 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:
if-no-files-found: error
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-22.04
environment:
name: production
if: ${{ !contains(toJSON(github.event.commits.*.message), '[skip-e2e]') }}
needs: [e2e-credentials, build-id]
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
path: firmware
- uses: actions/download-artifact@v3
with:
name:
e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
path: e2e-credentials
- name: Set device id
run: |
echo "DEVICE_ID=`find e2e-credentials -name \*.json | head -n 1 | xargs cat | jq -r '.clientId'`" >> $GITHUB_ENV
- name: Configure Version
id: configure-version
working-directory: firmware
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
run: |
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${APP_VERSION}-original\"" >> firmware.conf
- name: Configure the Azure IoT DPS ID scope
working-directory: firmware
run: |
echo "CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE=\"${{ secrets.AZURE_IOT_HUB_DPS_ID_SCOPE }}\"" >> firmware.conf
- name: Set MQTT client ID to test device
working-directory: firmware
run: |
echo "CONFIG_CLOUD_CLIENT_ID_USE_CUSTOM=y" >> firmware.conf
echo "CONFIG_CLOUD_CLIENT_ID=\"${{ env.DEVICE_ID }}\"" >> firmware.conf
- name: Enable immediate logging
working-directory: firmware
run: |
echo "CONFIG_LOG_MODE_IMMEDIATE=y" >> firmware.conf
- run: cat firmware/firmware.conf
- name: Build
working-directory: firmware
run: |
docker run --rm -v ${PWD}:/workdir/project nordicplayground/nrfconnect-sdk:main west build -p always -b ${{ matrix.board }} --build-dir /workdir/project/build -- -DOVERLAY_CONFIG="overlay-azure.conf;overlay-pgps.conf;overlay-debug.conf;asset-tracker-cloud-firmware-azure.conf;firmware.conf;e2e.conf" -DEXTRA_CFLAGS="-Werror"
cp build/zephyr/merged.hex ../firmware.hex
cp build/zephyr/app_update.bin ../firmware.bin
cp firmware.conf ../firmware.conf
- name: Build with changed version for FOTA test
working-directory: firmware
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
run: |
echo "CONFIG_ASSET_TRACKER_V2_APP_VERSION=\"${{ env.APP_VERSION }}-upgraded\"" >> firmware.conf
docker run --rm -v ${PWD}:/workdir/project nordicplayground/nrfconnect-sdk:main west build -p always -b ${{ matrix.board }} --build-dir /workdir/project/build -- -DOVERLAY_CONFIG="overlay-azure.conf;overlay-pgps.conf;overlay-debug.conf;asset-tracker-cloud-firmware-azure.conf;firmware.conf;e2e.conf" -DEXTRA_CFLAGS="-Werror"
cp build/zephyr/app_update.bin ../fota-upgrade.bin
cp build/zephyr/merged.hex ../fota-upgrade.hex
cp firmware.conf ../fota-upgrade.conf
- uses: actions/upload-artifact@v3
with:
if-no-files-found: error
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]
environment:
name: production
env:
LOCATION: ${{ secrets.LOCATION }}
APP_NAME: ${{ secrets.APP_NAME }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
AZURE_IOT_HUB_DPS_ID_SCOPE: ${{ secrets.AZURE_IOT_HUB_DPS_ID_SCOPE }}
if: ${{ !contains(toJSON(github.event.commits.*.message), '[skip-e2e]') }}
needs:
- e2e-firmware
- e2e-credentials
- build-id
# Wait for build step here, otherwise entire workflow will not pass, so running the expensive e2e test is pointless
- build
outputs:
connected: ${{ steps.device.outputs.connected }}
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- 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
- name: Login to Azure
uses: azure/login@v1
id: azure-login
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run firmware on real device
uses: NordicSemiconductor/cloud-azure-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 }}
storage account name: ${{ secrets.STORAGE_ACCOUNT_NAME }}
app name: ${{ secrets.APP_NAME }}
hex file: firmware.hex
fota file: fota-upgrade.bin
abort on: |
azure_fota: Error (-7) when trying to start firmware download
azure_iot_integration: azure_iot_hub_init, error
end on: |
CLOUD_WRAP_EVT_AGPS_DATA_RECEIVED
CLOUD_WRAP_EVT_PGPS_DATA_RECEIVED
azure_iot_hub_integration: cloud_wrap_init: Version: ${{ env.APP_VERSION }}-upgraded
azure_iot_hub_integration: azure_iot_hub_event_handler: AZURE_IOT_HUB_EVT_PUBACK
timeout in minutes: 20
sec tag: 11
certificate location:
./e2e-credentials-${{ matrix.board }}-${{ needs.build-id.outputs.id
}}
target: ${{ matrix.board }}
powerCycle enabled: false
ci runner package: "@nordicsemiconductor/firmware-ci-runner-azure@>=3.1.4"
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
if-no-files-found: error
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-22.04
environment:
name: production
needs: [e2e-credentials, e2e-firmware, e2e-device, build-id]
if:
${{ needs.e2e-device.outputs.connected == 'true' &&
!contains(toJSON(github.event.commits.*.message), '[skip-e2e]') }}
strategy:
matrix:
board: [nrf9160dk_nrf9160_ns]
network: [ltem]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- 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
- name: Login to Azure
uses: azure/login@v1
id: azure-login
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run feature tests
uses: NordicSemiconductor/cloud-azure-firmware-ci-feature-runner-action@saga
env:
APP_VERSION:
${{ github.sha }}-${{ matrix.board }}-${{ env.DEVICE_ID }}
with:
device id: ${{ env.DEVICE_ID }}
app version: ${{ env.APP_VERSION }}
azure iot hub dps id scope: ${{ secrets.AZURE_IOT_HUB_DPS_ID_SCOPE }}
app name: ${{ secrets.APP_NAME }}
feature dir: features
log dir: e2e-run-${{ matrix.board }}-${{ needs.build-id.outputs.id }}
target: ${{ matrix.board }}
- name: Enable Azure auto-install
run: az config set extension.use_dynamic_install=yes_without_prompt
- name: Remove test device
if:
${{ !contains(toJSON(github.event.commits.*.message),
'[skip-cleanup]') }}
continue-on-error: true
run: |
az iot hub device-identity delete --device-id ${{ env.DEVICE_ID }} --hub-name ${{ secrets.RESOURCE_GROUP }}IotHub
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, e2e-tests]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- uses: actions/download-artifact@v3
- uses: actions/setup-node@v3
with:
node-version: "18.x"
- run: npx semantic-release