Skip to content

Github Actions: build and release workflow #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
name: Build
name: Build native Zephyr samples

on: [push, pull_request]

jobs:
build:
name: Build native Zephyr samples
runs-on: ubuntu-latest
container: zephyrprojectrtos/ci:latest
env:
CMAKE_PREFIX_PATH: /opt/toolchains
PR_NUMBER: ${{ github.event.number }}
CCACHE_IGNOREOPTIONS: -specs=*
REPOSITORY: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}
steps:
- name: Initialize
run: |
mkdir build && cd build
west init -m https://github.com/${{ github.repository }}
cd modules/lib/ArduinoCore-zephyr/
git fetch origin ${{ github.ref }}
git checkout FETCH_HEAD
cd -
west update
west init -m https://github.com/${{ env.REPOSITORY }} --mr ${{ env.BRANCH }}
west update -o=--filter=tree:0

- name: ccache
uses: hendrikmuhs/[email protected]
with:
verbose: 1

- name: Build fade
working-directory: build
@@ -33,4 +37,4 @@ jobs:
- name: Build adc
working-directory: build
run: |
west build -p -b arduino_nano_33_ble/nrf52840/sense modules/lib/ArduinoCore-zephyr/samples/analog_input
west build -p -b arduino_nano_33_ble/nrf52840/sense modules/lib/ArduinoCore-zephyr/samples/analog_input
176 changes: 155 additions & 21 deletions .github/workflows/package_core.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,187 @@
name: Package core
name: Package, test and upload core

on: [push, pull_request]
on:
push:
branches:
- arduino
pull_request:

jobs:
build:

package-core:
name: Build and package core
runs-on: ubuntu-latest
env:
ZEPHYR_SDK_INSTALL_DIR: /opt/zephyr-sdk-0.16.8
CCACHE_IGNOREOPTIONS: -specs=*
outputs:
CORE_TAG: ${{ env.CORE_TAG }}
CORE_ARTIFACT: ${{ env.CORE_ARTIFACT }}
BOARD_NAMES: ${{ env.BOARD_NAMES }}
steps:
- name: Install toolchain
working-directory: /opt
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git cmake wget python3-pip ninja-build
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.8/zephyr-sdk-0.16.8_linux-x86_64_minimal.tar.xz
sudo apt-get install -y --no-install-recommends git cmake wget python3-pip ninja-build ccache
wget -nv https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.8/zephyr-sdk-0.16.8_linux-x86_64_minimal.tar.xz
tar xf zephyr-sdk-0.16.8_linux-x86_64_minimal.tar.xz && cd zephyr-sdk-0.16.8 && ./setup.sh -t arm-zephyr-eabi -c

- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Initialize
run: |
./extra/bootstrap.sh
./extra/build_all.sh
./extra/package.sh `git describe --always`
mv ../arduino-core-zephyr-llext* .
./extra/bootstrap.sh -o=--filter=tree:0
echo "CORE_TAG=$(git describe --always)" >> "$GITHUB_ENV"
echo "CORE_ARTIFACT=ArduinoCore-zephyr-$(git describe --always)" >> "$GITHUB_ENV"
echo "BOARD_NAMES=[ $(cat boards.txt | grep '^[^#]*\.build\.variant' | cut -d '.' -f 1 | xargs printf '"%s",' | sed -e 's/,$//') ]" >> "$GITHUB_ENV"

- name: ccache
uses: hendrikmuhs/[email protected]
with:
verbose: 1

- name: Build variants
run: |
./extra/build_all.sh -f

- name: Package
run: |
./extra/package.sh ${{ env.CORE_TAG }}
mv ../${{ env.CORE_ARTIFACT }}.tar.bz2 .

- name: Archive core
uses: actions/upload-artifact@v4
with:
name: Core
path: arduino-core-zephyr-llext*
name: ${{ env.CORE_ARTIFACT }}
path: ${{ env.CORE_ARTIFACT }}.tar.bz2

test-core:
name: Test arduino:zephyr:${{ matrix.board }}
runs-on: ubuntu-latest
needs: package-core
strategy:
matrix:
board: ${{ fromJSON( needs.package-core.outputs.BOARD_NAMES ) }}
fail-fast: false
env:
FQBN: arduino:zephyr:${{ matrix.board }}
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ needs.package-core.outputs.CORE_ARTIFACT }}

- name: Set up core
run: |
tar xf ${{ needs.package-core.outputs.CORE_ARTIFACT }}.tar.bz2

- name: Create Blink sketch
run: |
mkdir extra/Blink/
wget https://raw.githubusercontent.com/arduino/arduino-examples/refs/heads/main/examples/01.Basics/Blink/Blink.ino
mv Blink.ino extra/Blink/
mkdir Blink/
wget -nv https://raw.githubusercontent.com/arduino/arduino-examples/refs/heads/main/examples/01.Basics/Blink/Blink.ino -P Blink/

- name: Compile Blink
uses: arduino/compile-sketches@main
- name: Compile Blink for ${{ env.FQBN }}
uses: pillo79/compile-sketches@main
with:
fqbn: arduino:zephyr:giga
fqbn: ${{ env.FQBN }}
platforms: |
# Use Board Manager to install the latest release of Arduino Zephyr Boards to get the toolchain
- name: "arduino:zephyr"
source-url: "https://downloads.arduino.cc/packages/package_zephyr_index.json"
- source-path: "./"
name: "arduino:zephyr"
sketch-paths: |
extra/Blink
- name: "arduino:zephyr"
source-path: "ArduinoCore-zephyr"
sketch-paths: Blink
verbose: 'false'
enable-deltas-report: 'false'
enable-warnings-report: 'true'
enable-warnings-log: 'true'

- name: Clean up log
run: |
sed -i -e 's!/home/runner/.arduino15/packages/arduino/hardware/zephyr/[^/]*/!!g' sketches-reports/*

- uses: actions/upload-artifact@v4
with:
name: test-report-${{ needs.package-core.outputs.CORE_TAG }}-${{ matrix.board }}
path: sketches-reports/*

collect-logs:
name: Test summary
runs-on: ubuntu-latest
needs:
- package-core
- test-core
if: ${{ !cancelled() && needs.package-core.result == 'success' }}
env:
BOARD_NAMES: ${{ needs.package-core.outputs.BOARD_NAMES }}
steps:
- uses: actions/download-artifact@v4
with:
path: .
pattern: test-report-*
merge-multiple: true

- run: |
echo "### Core test results" >> "$GITHUB_STEP_SUMMARY"
for BOARD in $(echo $BOARD_NAMES | jq -cr '.[]'); do
FQBN="arduino:zephyr:$BOARD"
REPORT_FILE="arduino-zephyr-$BOARD.json"
if [ ! -f $REPORT_FILE ]; then
echo ":x: $BOARD - No report found?" >> "$GITHUB_STEP_SUMMARY"
else
REPORT=$(jq -cr '.boards[0].sketches[0]' $REPORT_FILE)
if ! $(echo $REPORT | jq -cr '.compilation_success') ; then
echo ":x: $BOARD - **Build failed**" >> "$GITHUB_STEP_SUMMARY"
else
WARNINGS=$(echo $REPORT | jq -cr '.warnings.current.absolute // 0')
if [ $WARNINGS -eq 0 ]; then
echo ":white_check_mark: $BOARD - Build successful" >> "$GITHUB_STEP_SUMMARY"
else
echo "<details><summary>:warning: $BOARD - $WARNINGS Warnings:</summary>" >> "$GITHUB_STEP_SUMMARY"
echo >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
echo $REPORT | jq -cr '.warnings_log[]' >> "$GITHUB_STEP_SUMMARY"
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
echo >> "$GITHUB_STEP_SUMMARY"
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
fi
fi
fi
done

publish-artifacts:
name: Publish artifacts
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && github.repository == 'arduino/ArduinoCore-zephyr' }}
needs:
- package-core
- test-core
env:
CORE_ARTIFACT: ${{ needs.package-core.outputs.CORE_ARTIFACT }}
CORE_TAG: ${{ needs.package-core.outputs.CORE_TAG }}
PACKAGE_INDEX_JSON: zephyr-core-${{ needs.package-core.outputs.CORE_TAG }}.json
steps:
- uses: actions/download-artifact@v4
with:
name: ${{ env.CORE_ARTIFACT }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Upload artifact
run: aws s3 sync ${{ env.CORE_ARTIFACT }}.tar.bz2 s3://${{ secrets.S3_BUCKET }}

- name: Prepare package index snippet
run: ./extra/gen_package_index_json.sh

- name: Archive package index snippet
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_INDEX_JSON }}
path: ${{ env.PACKAGE_INDEX_JSON }}
2 changes: 1 addition & 1 deletion extra/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ python3 -m venv venv
source venv/bin/activate
pip install west
west init -l .
west update
west update "$@"
west zephyr-export
pip install -r ../zephyr/scripts/requirements-base.txt
# download slim toolchain from https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8
16 changes: 5 additions & 11 deletions extra/build.sh
Original file line number Diff line number Diff line change
@@ -13,31 +13,25 @@ if [ x$ZEPHYR_SDK_INSTALL_DIR == x"" ]; then
fi

if [[ $# -eq 0 ]]; then
board=arduino_giga_r1//m7
board=$(jq -cr '.[0].board' < ./extra/targets.json)
args=$(jq -cr '.[0].args' < ./extra/targets.json)
else
board=$1
shift
board=$1
shift
fi

source venv/bin/activate

ZEPHYR_BASE=$(west topdir)/zephyr

# Get the variant name (NORMALIZED_BOARD_TARGET in Zephyr)
tmpdir=$(mktemp -d)
variant=$(cmake -DBOARD=$board -P extra/get_variant_name.cmake | grep 'VARIANT=' | cut -d '=' -f 2)
rm -rf ${tmpdir}
variant=$(extra/get_variant_name.sh $board)

if [ -z "${variant}" ] ; then
echo "Failed to get variant name from '$board'"
exit 1
fi

echo && echo && echo
echo ${variant}
echo ${variant} | sed -e 's/./=/g'
echo

# Build the loader
BUILD_DIR=build/${variant}
VARIANT_DIR=variants/${variant}
70 changes: 58 additions & 12 deletions extra/build_all.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
# Update this file if a new board gets supported

set -e

./extra/build.sh arduino_giga_r1//m7 --shield giga_display_shield
./extra/build.sh arduino_nano_33_ble//sense
./extra/build.sh arduino_nicla_sense_me
./extra/build.sh arduino_portenta_c33
./extra/build.sh [email protected]//m7
./extra/build.sh ek_ra8d1
./extra/build.sh frdm_mcxn947/mcxn947/cpu0
./extra/build.sh frdm_rw612
#!/bin/bash

FORCE=false

while getopts "hfl" opt; do
case $opt in
h)
echo "Usage: $0 [-hfl]"
echo " -h Show this help message"
echo " -f Force build all targets"
exit 0
;;
f)
FORCE=true
;;
*)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done

if [ ! -z "$GITHUB_STEP_SUMMARY" ] ; then
echo "### Variant build results:" >> "$GITHUB_STEP_SUMMARY"
fi

jq -cr '.[]' < ./extra/targets.json | while read -r item; do
board=$(jq -cr '.board // ""' <<< "$item")
args=$(jq -cr '.args // ""' <<< "$item")

variant=$(extra/get_variant_name.sh "$board" || echo "$board")
if [ -z "$GITHUB_STEP_SUMMARY" ] ; then
echo && echo
echo ${variant}
echo ${variant} | sed -e 's/./=/g'
else
echo "::group::=== ${variant} ==="
fi

./extra/build.sh "$board" $args
result=$?

if [ -z "$GITHUB_STEP_SUMMARY" ] ; then
echo
echo "${variant} result: $result"
else
echo "::endgroup::"
if [ $result -eq 0 ] ; then
echo "- :white_check_mark: \`${variant}\`" >> "$GITHUB_STEP_SUMMARY"
else
echo "^^^$(echo ${variant} | sed -e 's/./^/g')^^ FAILED with $result!"
echo "- :x: \`${variant}\`" >> "$GITHUB_STEP_SUMMARY"
fi
fi
[ $result -ne 0 ] && ! $FORCE && exit $result
done

exit 0
11 changes: 11 additions & 0 deletions extra/gen_package_index_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ -z "$CORE_TAG" ]; then
echo "This script can be used in Github CI only."
exit 1
fi

export ARTIFACT_HASH=$(sha256sum $CORE_ARTIFACT)
export ARTIFACT_SIZE=$(stat -c %s $CORE_ARTIFACT)

envsubst < extra/zephyr-core-template.json > $PACKAGE_INDEX_JSON
11 changes: 11 additions & 0 deletions extra/get_variant_name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

source venv/bin/activate

# Get the variant name (NORMALIZED_BOARD_TARGET in Zephyr)
tmpdir=$(mktemp -d)
variant=$(cmake "-DBOARD=$1" -P extra/get_variant_name.cmake 2>/dev/null | grep 'VARIANT=' | cut -d '=' -f 2)
rm -rf ${tmpdir}

echo $variant
Loading