Skip to content

Commit 4402664

Browse files
authored
Merge pull request #98 from pillo79/gh-ci
Github Actions: build and release workflow
2 parents 4887276 + 516bef9 commit 4402664

10 files changed

+331
-55
lines changed

Diff for: .github/workflows/build.yml

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
name: Build
1+
name: Build native Zephyr samples
22

33
on: [push, pull_request]
44

55
jobs:
66
build:
7+
name: Build native Zephyr samples
78
runs-on: ubuntu-latest
89
container: zephyrprojectrtos/ci:latest
910
env:
1011
CMAKE_PREFIX_PATH: /opt/toolchains
11-
PR_NUMBER: ${{ github.event.number }}
12+
CCACHE_IGNOREOPTIONS: -specs=*
13+
REPOSITORY: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
14+
BRANCH: ${{ github.event.pull_request.head.ref || github.ref_name }}
1215
steps:
1316
- name: Initialize
1417
run: |
1518
mkdir build && cd build
16-
west init -m https://github.com/${{ github.repository }}
17-
cd modules/lib/ArduinoCore-zephyr/
18-
git fetch origin ${{ github.ref }}
19-
git checkout FETCH_HEAD
20-
cd -
21-
west update
19+
west init -m https://github.com/${{ env.REPOSITORY }} --mr ${{ env.BRANCH }}
20+
west update -o=--filter=tree:0
21+
22+
- name: ccache
23+
uses: hendrikmuhs/[email protected]
24+
with:
25+
verbose: 1
2226

2327
- name: Build fade
2428
working-directory: build
@@ -33,4 +37,4 @@ jobs:
3337
- name: Build adc
3438
working-directory: build
3539
run: |
36-
west build -p -b arduino_nano_33_ble/nrf52840/sense modules/lib/ArduinoCore-zephyr/samples/analog_input
40+
west build -p -b arduino_nano_33_ble/nrf52840/sense modules/lib/ArduinoCore-zephyr/samples/analog_input

Diff for: .github/workflows/package_core.yml

+155-21
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,187 @@
1-
name: Package core
1+
name: Package, test and upload core
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- arduino
7+
pull_request:
48

59
jobs:
6-
build:
10+
11+
package-core:
12+
name: Build and package core
713
runs-on: ubuntu-latest
814
env:
915
ZEPHYR_SDK_INSTALL_DIR: /opt/zephyr-sdk-0.16.8
16+
CCACHE_IGNOREOPTIONS: -specs=*
17+
outputs:
18+
CORE_TAG: ${{ env.CORE_TAG }}
19+
CORE_ARTIFACT: ${{ env.CORE_ARTIFACT }}
20+
BOARD_NAMES: ${{ env.BOARD_NAMES }}
1021
steps:
1122
- name: Install toolchain
1223
working-directory: /opt
1324
run: |
1425
sudo apt-get update
15-
sudo apt-get install -y --no-install-recommends git cmake wget python3-pip ninja-build
16-
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.8/zephyr-sdk-0.16.8_linux-x86_64_minimal.tar.xz
26+
sudo apt-get install -y --no-install-recommends git cmake wget python3-pip ninja-build ccache
27+
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
1728
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
1829
1930
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
persist-credentials: false
2034

2135
- name: Initialize
2236
run: |
23-
./extra/bootstrap.sh
24-
./extra/build_all.sh
25-
./extra/package.sh `git describe --always`
26-
mv ../arduino-core-zephyr-llext* .
37+
./extra/bootstrap.sh -o=--filter=tree:0
38+
echo "CORE_TAG=$(git describe --always)" >> "$GITHUB_ENV"
39+
echo "CORE_ARTIFACT=ArduinoCore-zephyr-$(git describe --always)" >> "$GITHUB_ENV"
40+
echo "BOARD_NAMES=[ $(cat boards.txt | grep '^[^#]*\.build\.variant' | cut -d '.' -f 1 | xargs printf '"%s",' | sed -e 's/,$//') ]" >> "$GITHUB_ENV"
41+
42+
- name: ccache
43+
uses: hendrikmuhs/[email protected]
44+
with:
45+
verbose: 1
46+
47+
- name: Build variants
48+
run: |
49+
./extra/build_all.sh -f
50+
51+
- name: Package
52+
run: |
53+
./extra/package.sh ${{ env.CORE_TAG }}
54+
mv ../${{ env.CORE_ARTIFACT }}.tar.bz2 .
2755
2856
- name: Archive core
2957
uses: actions/upload-artifact@v4
3058
with:
31-
name: Core
32-
path: arduino-core-zephyr-llext*
59+
name: ${{ env.CORE_ARTIFACT }}
60+
path: ${{ env.CORE_ARTIFACT }}.tar.bz2
61+
62+
test-core:
63+
name: Test arduino:zephyr:${{ matrix.board }}
64+
runs-on: ubuntu-latest
65+
needs: package-core
66+
strategy:
67+
matrix:
68+
board: ${{ fromJSON( needs.package-core.outputs.BOARD_NAMES ) }}
69+
fail-fast: false
70+
env:
71+
FQBN: arduino:zephyr:${{ matrix.board }}
72+
steps:
73+
- uses: actions/download-artifact@v4
74+
with:
75+
name: ${{ needs.package-core.outputs.CORE_ARTIFACT }}
76+
77+
- name: Set up core
78+
run: |
79+
tar xf ${{ needs.package-core.outputs.CORE_ARTIFACT }}.tar.bz2
3380
3481
- name: Create Blink sketch
3582
run: |
36-
mkdir extra/Blink/
37-
wget https://raw.githubusercontent.com/arduino/arduino-examples/refs/heads/main/examples/01.Basics/Blink/Blink.ino
38-
mv Blink.ino extra/Blink/
83+
mkdir Blink/
84+
wget -nv https://raw.githubusercontent.com/arduino/arduino-examples/refs/heads/main/examples/01.Basics/Blink/Blink.ino -P Blink/
3985
40-
- name: Compile Blink
41-
uses: arduino/compile-sketches@main
86+
- name: Compile Blink for ${{ env.FQBN }}
87+
uses: pillo79/compile-sketches@main
4288
with:
43-
fqbn: arduino:zephyr:giga
89+
fqbn: ${{ env.FQBN }}
4490
platforms: |
4591
# Use Board Manager to install the latest release of Arduino Zephyr Boards to get the toolchain
4692
- name: "arduino:zephyr"
4793
source-url: "https://downloads.arduino.cc/packages/package_zephyr_index.json"
48-
- source-path: "./"
49-
name: "arduino:zephyr"
50-
sketch-paths: |
51-
extra/Blink
94+
- name: "arduino:zephyr"
95+
source-path: "ArduinoCore-zephyr"
96+
sketch-paths: Blink
5297
verbose: 'false'
5398
enable-deltas-report: 'false'
99+
enable-warnings-report: 'true'
100+
enable-warnings-log: 'true'
101+
102+
- name: Clean up log
103+
run: |
104+
sed -i -e 's!/home/runner/.arduino15/packages/arduino/hardware/zephyr/[^/]*/!!g' sketches-reports/*
105+
106+
- uses: actions/upload-artifact@v4
107+
with:
108+
name: test-report-${{ needs.package-core.outputs.CORE_TAG }}-${{ matrix.board }}
109+
path: sketches-reports/*
110+
111+
collect-logs:
112+
name: Test summary
113+
runs-on: ubuntu-latest
114+
needs:
115+
- package-core
116+
- test-core
117+
if: ${{ !cancelled() && needs.package-core.result == 'success' }}
118+
env:
119+
BOARD_NAMES: ${{ needs.package-core.outputs.BOARD_NAMES }}
120+
steps:
121+
- uses: actions/download-artifact@v4
122+
with:
123+
path: .
124+
pattern: test-report-*
125+
merge-multiple: true
126+
127+
- run: |
128+
echo "### Core test results" >> "$GITHUB_STEP_SUMMARY"
129+
for BOARD in $(echo $BOARD_NAMES | jq -cr '.[]'); do
130+
FQBN="arduino:zephyr:$BOARD"
131+
REPORT_FILE="arduino-zephyr-$BOARD.json"
132+
if [ ! -f $REPORT_FILE ]; then
133+
echo ":x: $BOARD - No report found?" >> "$GITHUB_STEP_SUMMARY"
134+
else
135+
REPORT=$(jq -cr '.boards[0].sketches[0]' $REPORT_FILE)
136+
if ! $(echo $REPORT | jq -cr '.compilation_success') ; then
137+
echo ":x: $BOARD - **Build failed**" >> "$GITHUB_STEP_SUMMARY"
138+
else
139+
WARNINGS=$(echo $REPORT | jq -cr '.warnings.current.absolute // 0')
140+
if [ $WARNINGS -eq 0 ]; then
141+
echo ":white_check_mark: $BOARD - Build successful" >> "$GITHUB_STEP_SUMMARY"
142+
else
143+
echo "<details><summary>:warning: $BOARD - $WARNINGS Warnings:</summary>" >> "$GITHUB_STEP_SUMMARY"
144+
echo >> "$GITHUB_STEP_SUMMARY"
145+
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
146+
echo $REPORT | jq -cr '.warnings_log[]' >> "$GITHUB_STEP_SUMMARY"
147+
echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY"
148+
echo >> "$GITHUB_STEP_SUMMARY"
149+
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
150+
fi
151+
fi
152+
fi
153+
done
154+
155+
publish-artifacts:
156+
name: Publish artifacts
157+
runs-on: ubuntu-latest
158+
if: ${{ github.event_name == 'push' && github.repository == 'arduino/ArduinoCore-zephyr' }}
159+
needs:
160+
- package-core
161+
- test-core
162+
env:
163+
CORE_ARTIFACT: ${{ needs.package-core.outputs.CORE_ARTIFACT }}
164+
CORE_TAG: ${{ needs.package-core.outputs.CORE_TAG }}
165+
PACKAGE_INDEX_JSON: zephyr-core-${{ needs.package-core.outputs.CORE_TAG }}.json
166+
steps:
167+
- uses: actions/download-artifact@v4
168+
with:
169+
name: ${{ env.CORE_ARTIFACT }}
170+
171+
- name: Configure AWS credentials
172+
uses: aws-actions/configure-aws-credentials@v4
173+
with:
174+
role-to-assume: ${{ secrets.IAM_ROLE }}
175+
aws-region: ${{ secrets.AWS_REGION }}
176+
177+
- name: Upload artifact
178+
run: aws s3 sync ${{ env.CORE_ARTIFACT }}.tar.bz2 s3://${{ secrets.S3_BUCKET }}
179+
180+
- name: Prepare package index snippet
181+
run: ./extra/gen_package_index_json.sh
182+
183+
- name: Archive package index snippet
184+
uses: actions/upload-artifact@v4
185+
with:
186+
name: ${{ env.PACKAGE_INDEX_JSON }}
187+
path: ${{ env.PACKAGE_INDEX_JSON }}

Diff for: extra/bootstrap.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ python3 -m venv venv
99
source venv/bin/activate
1010
pip install west
1111
west init -l .
12-
west update
12+
west update "$@"
1313
west zephyr-export
1414
pip install -r ../zephyr/scripts/requirements-base.txt
1515
# download slim toolchain from https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8

Diff for: extra/build.sh

+5-11
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,25 @@ if [ x$ZEPHYR_SDK_INSTALL_DIR == x"" ]; then
1313
fi
1414

1515
if [[ $# -eq 0 ]]; then
16-
board=arduino_giga_r1//m7
16+
board=$(jq -cr '.[0].board' < ./extra/targets.json)
17+
args=$(jq -cr '.[0].args' < ./extra/targets.json)
1718
else
18-
board=$1
19-
shift
19+
board=$1
20+
shift
2021
fi
2122

2223
source venv/bin/activate
2324

2425
ZEPHYR_BASE=$(west topdir)/zephyr
2526

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

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

36-
echo && echo && echo
37-
echo ${variant}
38-
echo ${variant} | sed -e 's/./=/g'
39-
echo
40-
4135
# Build the loader
4236
BUILD_DIR=build/${variant}
4337
VARIANT_DIR=variants/${variant}

Diff for: extra/build_all.sh

+58-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
1-
# Update this file if a new board gets supported
2-
3-
set -e
4-
5-
./extra/build.sh arduino_giga_r1//m7 --shield giga_display_shield
6-
./extra/build.sh arduino_nano_33_ble//sense
7-
./extra/build.sh arduino_nicla_sense_me
8-
./extra/build.sh arduino_portenta_c33
9-
./extra/build.sh [email protected]//m7
10-
./extra/build.sh ek_ra8d1
11-
./extra/build.sh frdm_mcxn947/mcxn947/cpu0
12-
./extra/build.sh frdm_rw612
1+
#!/bin/bash
2+
3+
FORCE=false
4+
5+
while getopts "hfl" opt; do
6+
case $opt in
7+
h)
8+
echo "Usage: $0 [-hfl]"
9+
echo " -h Show this help message"
10+
echo " -f Force build all targets"
11+
exit 0
12+
;;
13+
f)
14+
FORCE=true
15+
;;
16+
*)
17+
echo "Invalid option: -$OPTARG" >&2
18+
exit 1
19+
;;
20+
esac
21+
done
22+
23+
if [ ! -z "$GITHUB_STEP_SUMMARY" ] ; then
24+
echo "### Variant build results:" >> "$GITHUB_STEP_SUMMARY"
25+
fi
26+
27+
jq -cr '.[]' < ./extra/targets.json | while read -r item; do
28+
board=$(jq -cr '.board // ""' <<< "$item")
29+
args=$(jq -cr '.args // ""' <<< "$item")
30+
31+
variant=$(extra/get_variant_name.sh "$board" || echo "$board")
32+
if [ -z "$GITHUB_STEP_SUMMARY" ] ; then
33+
echo && echo
34+
echo ${variant}
35+
echo ${variant} | sed -e 's/./=/g'
36+
else
37+
echo "::group::=== ${variant} ==="
38+
fi
39+
40+
./extra/build.sh "$board" $args
41+
result=$?
42+
43+
if [ -z "$GITHUB_STEP_SUMMARY" ] ; then
44+
echo
45+
echo "${variant} result: $result"
46+
else
47+
echo "::endgroup::"
48+
if [ $result -eq 0 ] ; then
49+
echo "- :white_check_mark: \`${variant}\`" >> "$GITHUB_STEP_SUMMARY"
50+
else
51+
echo "^^^$(echo ${variant} | sed -e 's/./^/g')^^ FAILED with $result!"
52+
echo "- :x: \`${variant}\`" >> "$GITHUB_STEP_SUMMARY"
53+
fi
54+
fi
55+
[ $result -ne 0 ] && ! $FORCE && exit $result
56+
done
57+
58+
exit 0

Diff for: extra/gen_package_index_json.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
if [ -z "$CORE_TAG" ]; then
4+
echo "This script can be used in Github CI only."
5+
exit 1
6+
fi
7+
8+
export ARTIFACT_HASH=$(sha256sum $CORE_ARTIFACT)
9+
export ARTIFACT_SIZE=$(stat -c %s $CORE_ARTIFACT)
10+
11+
envsubst < extra/zephyr-core-template.json > $PACKAGE_INDEX_JSON

Diff for: extra/get_variant_name.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source venv/bin/activate
5+
6+
# Get the variant name (NORMALIZED_BOARD_TARGET in Zephyr)
7+
tmpdir=$(mktemp -d)
8+
variant=$(cmake "-DBOARD=$1" -P extra/get_variant_name.cmake 2>/dev/null | grep 'VARIANT=' | cut -d '=' -f 2)
9+
rm -rf ${tmpdir}
10+
11+
echo $variant

0 commit comments

Comments
 (0)