diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 43cd1f15..ba541799 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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/ccache-action@v1.2 + 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 \ No newline at end of file + west build -p -b arduino_nano_33_ble/nrf52840/sense modules/lib/ArduinoCore-zephyr/samples/analog_input diff --git a/.github/workflows/package_core.yml b/.github/workflows/package_core.yml index ea7bd7ee..a2f6511d 100644 --- a/.github/workflows/package_core.yml +++ b/.github/workflows/package_core.yml @@ -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/ccache-action@v1.2 + 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 "
:warning: $BOARD - $WARNINGS Warnings:" >> "$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 "
" >> "$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 }} diff --git a/extra/bootstrap.sh b/extra/bootstrap.sh index f8a1e01d..f175a201 100755 --- a/extra/bootstrap.sh +++ b/extra/bootstrap.sh @@ -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 diff --git a/extra/build.sh b/extra/build.sh index 379fe34a..d7bff7d5 100755 --- a/extra/build.sh +++ b/extra/build.sh @@ -13,10 +13,11 @@ 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 @@ -24,20 +25,13 @@ 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} diff --git a/extra/build_all.sh b/extra/build_all.sh index 5d7c7b8f..e66542e4 100755 --- a/extra/build_all.sh +++ b/extra/build_all.sh @@ -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 arduino_portenta_h7@1.0.0//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 diff --git a/extra/gen_package_index_json.sh b/extra/gen_package_index_json.sh new file mode 100755 index 00000000..bcaee2cb --- /dev/null +++ b/extra/gen_package_index_json.sh @@ -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 diff --git a/extra/get_variant_name.sh b/extra/get_variant_name.sh new file mode 100755 index 00000000..a1eaba45 --- /dev/null +++ b/extra/get_variant_name.sh @@ -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 diff --git a/extra/package.sh b/extra/package.sh index b6459f3f..5e88ce3c 100755 --- a/extra/package.sh +++ b/extra/package.sh @@ -10,4 +10,4 @@ FOLDER=`basename $PWD` VERSION=$1 cd .. -tar --exclude=extras/** --exclude=.git* --exclude=build --exclude=venv --exclude=samples -cjhf arduino-core-zephyr-llext-${VERSION}.tar.bz2 $FOLDER \ No newline at end of file +tar --exclude=extras/** --exclude=.git* --exclude=build --exclude=venv --exclude=samples -cjhf ArduinoCore-zephyr-${VERSION}.tar.bz2 $FOLDER diff --git a/extra/targets.json b/extra/targets.json new file mode 100755 index 00000000..156aa6e9 --- /dev/null +++ b/extra/targets.json @@ -0,0 +1,10 @@ +[ + { "board": "arduino_giga_r1//m7", "args": "--shield giga_display_shield" }, + { "board": "arduino_nano_33_ble//sense" }, + { "board": "arduino_nicla_sense_me" }, + { "board": "arduino_portenta_c33" }, + { "board": "arduino_portenta_h7@1.0.0//m7" }, + { "board": "ek_ra8d1" }, + { "board": "frdm_mcxn947/mcxn947/cpu0" }, + { "board": "frdm_rw612" } +] diff --git a/extra/zephyr-core-template.json b/extra/zephyr-core-template.json new file mode 100644 index 00000000..7f4f72d1 --- /dev/null +++ b/extra/zephyr-core-template.json @@ -0,0 +1,66 @@ +{ + "packages": [ + { + "platforms": [ + { + "name": "Arduino Zephyr Boards", + "architecture": "zephyr", + "version": "$CORE_TAG", + "category": "Arduino", + "url": "https://downloads.arduino.cc/cores/zephyr/${CORE_ARTIFACT}.tar.bz2", + "archiveFileName": "${CORE_ARTIFACT}.tar.bz2", + "checksum": "SHA-256:${ARTIFACT_HASH}", + "size": "${ARTIFACT_SIZE}", + "help": { + "online": "https://www.arduino.cc/en/Reference/HomePage" + }, + "boards": [ + { + "name": "Arduino Giga" + }, + { + "name": "Arduino Nano 33 BLE" + }, + { + "name": "Arduino Portenta H7" + }, + { + "name": "Arduino Portenta C33" + }, + { + "name": "Renesas EK_RA8D1" + }, + { + "name": "NXP FRDM MCXN947" + }, + { + "name": "NXP FRDM RW612" + } + ], + "toolsDependencies": [ + { + "packager": "zephyr", + "name": "arm-zephyr-eabi", + "version": "0.16.8" + }, + { + "packager": "arduino", + "name": "dfu-util", + "version": "0.11.0-arduino5" + }, + { + "packager": "arduino", + "name": "bossac", + "version": "1.9.1-arduino2" + }, + { + "packager": "arduino", + "name": "zephyr-post-build-tool", + "version": "0.1.0" + } + ] + } + ] + } + ] +}