Skip to content

Commit 3898d89

Browse files
committed
Improve Arduino Examples
1 parent 3289b6b commit 3898d89

File tree

6 files changed

+622
-51
lines changed

6 files changed

+622
-51
lines changed

.github/workflows/arduino.yml

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

IDE/ARDUINO/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# wolfSSL with Arduino
22

3-
See the [example sketches](./sketches/README.md):
4-
5-
NOTE: Moving; See https://github.com/wolfSSL/wolfssl-examples/pull/499
3+
See the [example sketches](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino):
64

75
Bare-bones templates:
86

9-
- [sketches/wolfssl_version](./sketches/wolfssl_version/README.md) single file.
10-
- [sketches/template](./sketches/template/README.md) multiple file example.
7+
- [sketches/wolfssl_version](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/wolfssl_version/README.md) single file.
8+
- [sketches/template](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/template/README.md) multiple file example.
119

1210
Functional examples:
13-
- [sketches/wolfssl_AES_CTR](./sketches/wolfssl_AES_CTR/README.md) AES CTR Encrypt / decrypt.
14-
- [sketches/wolfssl_client](./sketches/wolfssl_client/README.md) TLS Client.
15-
- [sketches/wolfssl_server](./sketches/wolfssl_server/README.md) TLS Server.
11+
- [sketches/wolfssl_AES_CTR](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/wolfssl_AES_CTR/README.md) AES CTR Encrypt / decrypt.
12+
- [sketches/wolfssl_client](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/wolfssl_client/README.md) TLS Client.
13+
- [sketches/wolfssl_server](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/wolfssl_server/README.md) TLS Server.
14+
- [sketches/wolfssl_client_dtls](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/wolfssl_client_dtls/README.md) DTLS Client.
15+
- [sketches/wolfssl_server_dtls](https://github.com/wolfSSL/wolfssl-examples/tree/master/Arduino/sketches/wolfssl_server_dtls/README.md) DTLS Server.
1616

1717
Both the `template` and `wolfssl_AES_CTR` examples include VisualGDB project files.
1818

0 commit comments

Comments
 (0)