Skip to content

Commit f49a0d9

Browse files
committed
Improve Arduino Examples, add workflow testing
1 parent f33814b commit f49a0d9

File tree

7 files changed

+608
-52
lines changed

7 files changed

+608
-52
lines changed

.github/workflows/arduino.yml

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
name: Arduino CI Build (1 of 4) wolfssl
2+
3+
#
4+
# Test fetches wolfssl-examples/Arduino and uses local, latest github master branch wolfssl
5+
#
6+
# These 4 workflows across 3 repos are interdependent for the current $REPO_OWNER:
7+
#
8+
# THIS Arduino CI Build 1: https://github.com/$REPO_OWNER/wolfssl # /.github/workflows/arduino.yml
9+
# - Builds Arduino library from local clone of wolfssl master branch
10+
# - Fetches examples from https://github.com/$REPO_OWNER/wolfssl-examples
11+
#
12+
# Arduino CI Build 2: https://github.com/$REPO_OWNER/wolfssl-examples # /.github/workflows/arduino-release.yml
13+
# - Tests examples based on latest published release of Arduino library, NOT latest on wolfssl github.
14+
# - Should be identical to Arduino CI Build 3 in every way but wolfssl install.
15+
# - Copies only compile script from wolfssl-examples
16+
# - Builds local examples
17+
# - No other repos used
18+
#
19+
# Arduino CI Build 3: https://github.com/$REPO_OWNER/wolfssl-examples # /.github/workflows/arduino.yml
20+
# - Fetches current wolfSSL from https://github.com/$REPO_OWNER/wolfssl
21+
# - Creates an updated Arduino library
22+
# - Compiles local examples
23+
# - Contains the source of `compile-all-examples.sh` and respective board-list.txt
24+
#
25+
# Arduino CI Build 4: https://github.com/$REPO_OWNER/Arduino-wolfssl # /.github/workflows/arduino.yml
26+
# - Assembles and installs an updated Arduino wolfssl library from LOCAL wolfssl master source
27+
# - Copies only compile script copied from wolfssl-examples
28+
# - Builds local examples
29+
# - No other repos used
30+
#
31+
#
32+
# ** NOTE TO MAINTAINERS **
33+
#
34+
# Consider using winmerge or similar tool to keep the 4 arduino[-release].yml files in relative sync.
35+
# Although there are some specific differences, most of the contents are otherwise identical.
36+
#
37+
# See https://github.com/wolfSSL/Arduino-wolfSSL
38+
#
39+
# To test locally:
40+
# cd [your WOLFSSL_ROOT], e.g. cd /mnt/c/workspace/wolfssl-$USER
41+
# [optional checkout] e.g. git checkout tags/v5.8.2-stable
42+
# pushd ./IDE/ARDUINO
43+
# export ARDUINO_ROOT="$HOME/Arduino/libraries"
44+
# ./wolfssl-arduino.sh INSTALL
45+
# cd [your WOLFSSL_EXAMPLES_ROOT] e.g. /mnt/c/workspace/wolfssl-examples-$USER
46+
#
47+
48+
# START OF COMMON SECTION
49+
on:
50+
push:
51+
branches: [ '**', 'master', 'main', 'release/**' ]
52+
paths:
53+
- '.github/workflows/arduino.yml'
54+
- 'IDE/ARDUINO/**'
55+
- 'src/**'
56+
- 'wolfcrypt/**'
57+
- 'wolfssl/**'
58+
pull_request:
59+
branches: [ '**' ]
60+
paths:
61+
- 'github/workflows/arduino.yml'
62+
- 'IDE/ARDUINO/**'
63+
- 'src/**'
64+
- 'wolfcrypt/**'
65+
- 'wolfssl/**'
66+
workflow_dispatch:
67+
68+
concurrency:
69+
group: ${{ github.workflow }}-${{ github.ref }}
70+
cancel-in-progress: true
71+
# END OF COMMON SECTION
72+
73+
jobs:
74+
build:
75+
if: github.repository_owner == 'wolfssl'
76+
runs-on: ubuntu-latest
77+
env:
78+
REPO_OWNER: ${{ github.repository_owner }}
79+
steps:
80+
- name: Checkout Repository
81+
uses: actions/checkout@v4
82+
83+
- name: Install Arduino CLI
84+
run: |
85+
# Script to fetch and run install.sh from arduino/arduino-cli
86+
87+
# The install script will test to see if the recently installed apps in in the path
88+
# So set it up in advance:
89+
mkdir -p "${PWD}/bin"
90+
echo "${PWD}/bin" >> $GITHUB_PATH
91+
92+
# Sets the install directory to a consistent path at the repo root.
93+
ROOT_BIN="$GITHUB_WORKSPACE/bin"
94+
95+
# Ensures that BINDIR exists before the installer runs
96+
mkdir -p "$ROOT_BIN"
97+
98+
# Save as a lobal environment variable
99+
echo "$ROOT_BIN" >> "$GITHUB_PATH"
100+
101+
# Download and run install script from Arduino:
102+
# -S show errors; -L follow redirects; -v Verbose
103+
set +e # don't abort on error
104+
set -o pipefail
105+
106+
curl -vSL --retry 5 --retry-delay 10 \
107+
https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh \
108+
| sh -x
109+
rc=$?
110+
c_rc=${PIPESTATUS[0]} # curl's exit code
111+
s_rc=${PIPESTATUS[1]} # sh's exit code
112+
113+
set -e # restore default abort-on-error
114+
115+
# If there was a curl error, we have our own local copy that is more reliable and can add our own debugging
116+
if [ "$rc" -ne 0 ]; then
117+
echo "Primary install failed: curl=$c_rc, sh=$s_rc. Falling back..." >&2
118+
echo "Using local copy of arduino_install.sh"
119+
pushd ./Arduino/sketches
120+
chmod +x ./arduino_install.sh
121+
122+
# Mimic curl install, does not use current directory:
123+
BINDIR="$ROOT_BIN" sh -x ./arduino_install.sh
124+
popd
125+
else
126+
echo "Alternative install script not needed."
127+
fi
128+
129+
- name: Confirm Arduino CLI install
130+
run: arduino-cli version
131+
132+
- name: Setup Arduino CLI
133+
run: |
134+
arduino-cli config init
135+
arduino-cli core update-index
136+
arduino-cli config add board_manager.additional_urls https://www.pjrc.com/teensy/package_teensy_index.json
137+
arduino-cli core update-index
138+
arduino-cli config add board_manager.additional_urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
139+
arduino-cli core update-index
140+
arduino-cli core install esp32:esp32 # ESP32
141+
arduino-cli core install arduino:avr # Arduino Uno, Mega, Nano
142+
arduino-cli core install arduino:sam # Arduino Due
143+
arduino-cli core install arduino:samd # Arduino Zero
144+
arduino-cli core install teensy:avr # PJRC Teensy
145+
arduino-cli core install esp8266:esp8266 # ESP8266
146+
arduino-cli core install arduino:mbed_nano # nanorp2040connect
147+
arduino-cli core install arduino:mbed_portenta # portenta_h7_m7
148+
arduino-cli core install arduino:mbed_edge
149+
# sudo "/home/$USER/.arduino15/packages/arduino/hardware/mbed_nano/4.2.4/post_install.sh"
150+
arduino-cli core install arduino:renesas_uno
151+
arduino-cli lib install "ArduinoJson" # Example dependency
152+
arduino-cli lib install "WiFiNINA" # ARDUINO_SAMD_NANO_33_IOT
153+
arduino-cli lib install "Ethernet" # Install Ethernet library
154+
arduino-cli lib install "Bridge" # Pseudo-network for things like arduino:samd:tian
155+
156+
- name: Set job environment variables
157+
run: |
158+
# Script to assign some common environment variables after everything is installed
159+
160+
ICON_OK=$(printf "\xE2\x9C\x85")
161+
ICON_FAIL=$(printf "\xE2\x9D\x8C")
162+
163+
echo "GITHUB_WORK=$(realpath "$GITHUB_WORKSPACE/../..")" >> "$GITHUB_ENV"
164+
echo "ARDUINO_ROOT=$(realpath "$HOME/Arduino/libraries")" >> "$GITHUB_ENV"
165+
166+
# Show predefined summary:
167+
echo "GITHUB_WORKSPACE = $GITHUB_WORKSPACE"
168+
169+
# Show assigned build:env values (e.g. "wolfssl", "gojimmpi" or other owners):
170+
echo "REPO_OWNER = $REPO_OWNER"
171+
172+
echo "GITHUB_ENV=$GITHUB_ENV"
173+
174+
# Show our custom values:
175+
echo "GITHUB_WORK = $GITHUB_WORK"
176+
echo "ARDUINO_ROOT = $ARDUINO_ROOT"
177+
178+
# WOLFSSL_EXAMPLES_ROOT is the report root, not example location
179+
echo "WOLFSSL_EXAMPLES_ROOT = $WOLFSSL_EXAMPLES_ROOT"
180+
181+
- name: Get wolfssl-examples
182+
run: |
183+
# Fetch Arduino examples from the wolfssl-examples repo
184+
echo "Start pwd:"
185+
pwd
186+
# we're typically in $GITHUB_WORKSPACE=/home/runner/work/wolfssl/wolfssl
187+
# goto /home/runner/work to fetch wolfssl-examples
188+
189+
echo "Current pwd for wolfssl-examples clone fetch: $(pwd)"
190+
GITHUB_WORK=$(realpath "$GITHUB_WORKSPACE/../..")
191+
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
192+
193+
# Typically /home/runner/work
194+
echo "GITHUB_WORK=$GITHUB_WORK"
195+
196+
pushd "$GITHUB_WORK"
197+
echo "Updated pwd for wolfssl-examples clone fetch: $(pwd)"
198+
199+
git clone --depth 1 https://github.com/$REPO_OWNER/wolfssl-examples.git wolfssl-examples-publish
200+
201+
cd ./wolfssl-examples-publish
202+
echo "WOLFSSL_EXAMPLES_ROOT=$(pwd)"
203+
204+
echo "Path for wolfssl-examples-publish: $(pwd)"
205+
popd # GITHUB_WORK
206+
207+
208+
# ** END ** Get wolfssl-examples
209+
210+
- name: Install wolfSSL Arduino library
211+
run: |
212+
# Run the local wolfssl-arduino.sh install script to install wolfssl Arduino library.
213+
214+
# Methods of installing Arduino library:
215+
# 1) arduino-cli lib install "wolfSSL"
216+
# 2) manual copy of files (typical of the Arduino-wolfssl repo)
217+
# 3) run ./wolfssl-arduino.sh INSTALL (typical of the wolfssl repo)
218+
219+
echo "Current pwd for wolfssl-examples clone fetch: $(pwd)"
220+
GITHUB_WORK=$(realpath "$GITHUB_WORKSPACE/../..")
221+
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
222+
223+
# Typically /home/runner/work
224+
echo "GITHUB_WORK=$GITHUB_WORK"
225+
pwd
226+
pushd ./IDE/ARDUINO
227+
228+
# Set default ARDUINO_ROOT to Arduino library.
229+
export ARDUINO_ROOT="$HOME/Arduino/libraries"
230+
export WOLFSSL_EXAMPLES_ROOT="$GITHUB_WORK/wolfssl-examples-publish"
231+
232+
echo "ARDUINO_ROOT: $WOLFSSL_EXAMPLES_ROOT"
233+
echo "WOLFSSL_EXAMPLES_ROOT: $WOLFSSL_EXAMPLES_ROOT"
234+
235+
bash ./wolfssl-arduino.sh INSTALL # Install wolfSSL library
236+
popd
237+
238+
# ** END ** Install wolfSSL Arduino library
239+
240+
- name: List installed Arduino libraries
241+
run: arduino-cli lib list
242+
243+
- name: Get compile-all-examples.sh
244+
run: |
245+
# Fetch compile script FROM THE CURRENT OWNER.
246+
# This repo is Arduino-wolfssl; we'll fetch the script from the wolfssl-examples for the same repository owner.
247+
echo "Repository owner: $REPO_OWNER"
248+
echo "Current directory: $PWD"
249+
echo "Current pwd for wolfssl-examples clone fetch: $PWD"
250+
WOLFSSL_EXAMPLES_DIRECTORY="$ARDUINO_ROOT/wolfssl/examples"
251+
THIS_BOARD_LIST="board_list.txt"
252+
echo "WOLFSSL_EXAMPLES_DIRECTORY=$WOLFSSL_EXAMPLES_DIRECTORY"
253+
254+
# Fetch script and board list into WOLFSSL_EXAMPLES_DIRECTORY
255+
echo "Fetching board_list.txt from REPO_OWNER=$REPO_OWNER"
256+
curl -L "https://raw.githubusercontent.com/$REPO_OWNER/wolfssl-examples/master/Arduino/sketches/board_list.txt" -o "$WOLFSSL_EXAMPLES_DIRECTORY/$THIS_BOARD_LIST"
257+
258+
# Check if the first line is "404: Not Found" - which would indicate the curl path above is bad.
259+
FILE="$WOLFSSL_EXAMPLES_DIRECTORY/board_list.txt"
260+
261+
# Ensure the file exists
262+
if [[ ! -f "$FILE" ]]; then
263+
echo "File not found: $FILE"
264+
exit 1
265+
fi
266+
267+
# Check if the first line is "404: Not Found"
268+
if [[ $(head -n 1 "$FILE") == "404: Not Found" ]]; then
269+
echo "The first line is '404: Not Found'"
270+
exit 1
271+
fi
272+
273+
# Fetch the compile script from report https://github.com/[$USER]/wolfssl-examples/
274+
echo "Fetching compile-all-examples.sh from REPO_OWNER=$REPO_OWNER"
275+
curl -L "https://raw.githubusercontent.com/$REPO_OWNER/wolfssl-examples/master/Arduino/sketches/compile-all-examples.sh" -o "$WOLFSSL_EXAMPLES_DIRECTORY/compile-all-examples.sh"
276+
277+
# Check if the first line is "404: Not Found" - which would indicate the curl path above is bad.
278+
FILE="$WOLFSSL_EXAMPLES_DIRECTORY/compile-all-examples.sh"
279+
280+
# Ensure the file exists
281+
if [[ ! -f "$FILE" ]]; then
282+
echo "File not found: $FILE"
283+
exit 1
284+
fi
285+
286+
# Check if the first line is "404: Not Found"
287+
if [[ $(head -n 1 "$FILE") == "404: Not Found" ]]; then
288+
echo "The first line is '404: Not Found'"
289+
exit 1
290+
fi
291+
292+
pushd "$WOLFSSL_EXAMPLES_DIRECTORY"
293+
echo "Current directory: $PWD"
294+
295+
echo "Current directory $PWD"
296+
echo "Contents:"
297+
ls -al
298+
find ./ -type f | sort
299+
300+
# ensure we can execute the script here (permissions lost during curl fetch)
301+
chmod +x ./compile-all-examples.sh
302+
echo "Found compile script: $(ls -al ./compile-all-examples.sh ./$THIS_BOARD_LIST)"
303+
popd
304+
305+
# ** END ** Get compile-all-examples.sh
306+
307+
# This will fail with Arduino published wolfSSL v5.7.6 and older
308+
# as the examples moved. See https://github.com/wolfSSL/wolfssl/pull/8514
309+
#
310+
- name: Compile Arduino Sketches for Various Boards
311+
run: |
312+
# Call the compile-all-examples.sh script to compile all the examples for each of the fqbn names in the local copy of board_list.txt
313+
314+
echo "Current directory: $PWD"
315+
echo "ARDUINO_ROOT: $ARDUINO_ROOT"
316+
WOLFSSL_EXAMPLES_DIRECTORY="$ARDUINO_ROOT/wolfssl/examples"
317+
echo "WOLFSSL_EXAMPLES_DIRECTORY: $WOLFSSL_EXAMPLES_DIRECTORY"
318+
319+
echo "Change directory to Arduino examples..."
320+
pushd "$WOLFSSL_EXAMPLES_DIRECTORY"
321+
echo "Current directory: $PWD"
322+
echo "Calling ./compile-all-examples.sh"
323+
bash ./compile-all-examples.sh
324+
popd
325+
# End Compile Arduino Sketches for Various Boards

0 commit comments

Comments
 (0)