Skip to content

Commit 1afbe4d

Browse files
committed
Improve Arduino Examples
1 parent a98006e commit 1afbe4d

File tree

7 files changed

+641
-52
lines changed

7 files changed

+641
-52
lines changed

.github/workflows/arduino.yml

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
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: Show wolfssl-examples
182+
# TODO
183+
184+
# end Show wolfssl-examples
185+
186+
# - name: Shallow clone wolfssl
187+
# (not used, as wolfssl source is already here in wolfssl repo)
188+
#
189+
190+
191+
- name: Get wolfssl-examples
192+
run: |
193+
# Fetch Arduino examples from the wolfssl-examples repo
194+
echo "Start pwd:"
195+
pwd
196+
# we're typically in $GITHUB_WORKSPACE=/home/runner/work/wolfssl/wolfssl
197+
# goto /home/runner/work to fetch wolfssl-examples
198+
199+
echo "Current pwd for wolfssl-examples clone fetch: $(pwd)"
200+
GITHUB_WORK=$(realpath "$GITHUB_WORKSPACE/../..")
201+
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
202+
203+
# Typically /home/runner/work
204+
echo "GITHUB_WORK=$GITHUB_WORK"
205+
206+
pushd "$GITHUB_WORK"
207+
echo "Updated pwd for wolfssl-examples clone fetch: $(pwd)"
208+
209+
# git clone --depth 1 https://github.com/$REPO_OWNER/wolfssl-examples.git wolfssl-examples-publish
210+
git clone --depth 1 https://github.com/gojimmypi/wolfssl-examples.git wolfssl-examples-publish
211+
212+
cd ./wolfssl-examples-publish
213+
echo "WOLFSSL_EXAMPLES_ROOT=$(pwd)"
214+
215+
# TODO remove after merge
216+
# fetch open PR changes
217+
git remote add gojimmypi https://github.com/gojimmypi/wolfssl-examples.git
218+
git fetch --depth 1 gojimmypi pr-arduino-testing
219+
git checkout pr-arduino-testing
220+
# TODO End
221+
222+
echo "Path for wolfssl-examples-publish: $(pwd)"
223+
popd # GITHUB_WORK
224+
225+
226+
# ** END ** Get wolfssl-examples
227+
228+
- name: Install wolfSSL Arduino library
229+
run: |
230+
# Run the local wolfssl-arduino.sh install script to install wolfssl Arduino library.
231+
232+
# Methods of installing Arduino library:
233+
# 1) arduino-cli lib install "wolfSSL"
234+
# 2) manual copy of files (typical of the Arduino-wolfssl repo)
235+
# 3) run ./wolfssl-arduino.sh INSTALL (typical of the wolfssl repo)
236+
237+
echo "Current pwd for wolfssl-examples clone fetch: $(pwd)"
238+
GITHUB_WORK=$(realpath "$GITHUB_WORKSPACE/../..")
239+
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
240+
241+
# Typically /home/runner/work
242+
echo "GITHUB_WORK=$GITHUB_WORK"
243+
pwd
244+
pushd ./IDE/ARDUINO
245+
246+
# Set default ARDUINO_ROOT to Arduino library.
247+
export ARDUINO_ROOT="$HOME/Arduino/libraries"
248+
export WOLFSSL_EXAMPLES_ROOT="$GITHUB_WORK/wolfssl-examples-publish"
249+
250+
echo "ARDUINO_ROOT: $WOLFSSL_EXAMPLES_ROOT"
251+
echo "WOLFSSL_EXAMPLES_ROOT: $WOLFSSL_EXAMPLES_ROOT"
252+
253+
bash ./wolfssl-arduino.sh INSTALL # Install wolfSSL library
254+
popd
255+
256+
# ** END ** Install wolfSSL Arduino library
257+
258+
- name: List installed Arduino libraries
259+
run: arduino-cli lib list
260+
261+
- name: Get compile-all-examples.sh
262+
run: |
263+
# Fetch compile script FROM THE CURRENT OWNER.
264+
# This repo is Arduino-wolfssl; we'll fetch the script from the wolfssl-examples for the same repository owner.
265+
echo "Repository owner: $REPO_OWNER"
266+
echo "Current directory: $PWD"
267+
echo "Current pwd for wolfssl-examples clone fetch: $PWD"
268+
WOLFSSL_EXAMPLES_DIRECTORY="$ARDUINO_ROOT/wolfssl/examples"
269+
THIS_BOARD_LIST="board_list.txt"
270+
echo "WOLFSSL_EXAMPLES_DIRECTORY=$WOLFSSL_EXAMPLES_DIRECTORY"
271+
272+
# Fetch script and board list into WOLFSSL_EXAMPLES_DIRECTORY
273+
# TODO edit PR branch path:
274+
# curl -L "https://raw.githubusercontent.com/$REPO_OWNER/wolfssl-examples/examples_dev/Arduino/sketches/board_list.txt" -o "$WOLFSSL_EXAMPLES_DIRECTORY/$THIS_BOARD_LIST"
275+
curl -L "https://raw.githubusercontent.com/gojimmypi/wolfssl-examples/pr-arduino-testing/Arduino/sketches/board_list.txt" -o "$WOLFSSL_EXAMPLES_DIRECTORY/$THIS_BOARD_LIST"
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/board_list.txt"
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+
# curl -L "https://raw.githubusercontent.com/$REPO_OWNER/wolfssl-examples/examples_dev/Arduino/sketches/compile-all-examples.sh" -o "$WOLFSSL_EXAMPLES_DIRECTORY/compile-all-examples.sh"
293+
curl -L "https://raw.githubusercontent.com/gojimmypi/wolfssl-examples/pr-arduino-testing/Arduino/sketches/compile-all-examples.sh" -o "$WOLFSSL_EXAMPLES_DIRECTORY/compile-all-examples.sh"
294+
295+
# Check if the first line is "404: Not Found" - which would indicate the curl path above is bad.
296+
FILE="$WOLFSSL_EXAMPLES_DIRECTORY/compile-all-examples.sh"
297+
298+
# Ensure the file exists
299+
if [[ ! -f "$FILE" ]]; then
300+
echo "File not found: $FILE"
301+
exit 1
302+
fi
303+
304+
# Check if the first line is "404: Not Found"
305+
if [[ $(head -n 1 "$FILE") == "404: Not Found" ]]; then
306+
echo "The first line is '404: Not Found'"
307+
exit 1
308+
fi
309+
310+
pushd "$WOLFSSL_EXAMPLES_DIRECTORY"
311+
echo "Current directory: $PWD"
312+
313+
echo "Current directory $PWD"
314+
echo "Contents:"
315+
ls -al
316+
find ./ -type f | sort
317+
318+
# ensure we can execute the script here (permissions lost during curl fetch)
319+
chmod +x ./compile-all-examples.sh
320+
echo "Found compile script: $(ls -al ./compile-all-examples.sh ./$THIS_BOARD_LIST)"
321+
popd
322+
323+
# ** END ** Get compile-all-examples.sh
324+
325+
# This will fail with Arduino published wolfSSL v5.7.6 and older
326+
# as the examples moved. See https://github.com/wolfSSL/wolfssl/pull/8514
327+
#
328+
- name: Compile Arduino Sketches for Various Boards
329+
run: |
330+
# 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
331+
332+
echo "Current directory: $PWD"
333+
echo "ARDUINO_ROOT: $ARDUINO_ROOT"
334+
WOLFSSL_EXAMPLES_DIRECTORY="$ARDUINO_ROOT/wolfssl/examples"
335+
echo "WOLFSSL_EXAMPLES_DIRECTORY: $WOLFSSL_EXAMPLES_DIRECTORY"
336+
337+
echo "Change directory to Arduino examples..."
338+
pushd "$WOLFSSL_EXAMPLES_DIRECTORY"
339+
echo "Current directory: $PWD"
340+
echo "Calling ./compile-all-examples.sh"
341+
bash ./compile-all-examples.sh
342+
popd
343+
# End Compile Arduino Sketches for Various Boards

0 commit comments

Comments
 (0)