Skip to content

Commit acd4b68

Browse files
authored
Merge pull request #20 from gojimmypi/pr-arduino-testing
Improve Arduino Examples
2 parents 2a3603b + e2c8428 commit acd4b68

File tree

3 files changed

+331
-11
lines changed

3 files changed

+331
-11
lines changed

.github/SECURITY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
5+
If you discover a vulnerability, please report it to [email protected]
6+
7+
1. Include a detailed description
8+
2. Include method to reproduce and/or method of discovery
9+
3. We will evaluate the report promptly and respond to you with findings.
10+
4. We will credit you with the report if you would like.
11+
12+
**Please keep the vulnerability private** until a fix has been released.

.github/workflows/arduino.yml

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

.gitignore

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
################################################################################
2-
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3-
################################################################################
4-
5-
/.vs
6-
/src/wolfcrypt/src/fips.c
7-
/src/wolfcrypt/src/fips_test.c
8-
/src/wolfcrypt/src/selftest.c
9-
/src/wolfcrypt/src/wolfcrypt_first.c
10-
/src/wolfcrypt/src/wolfcrypt_last.c
11-
/src/wolfssl/wolfcrypt/fips.h
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
/.vs
6+
/src/wolfcrypt/src/fips.c
7+
/src/wolfcrypt/src/fips_test.c
8+
/src/wolfcrypt/src/selftest.c
9+
/src/wolfcrypt/src/wolfcrypt_first.c
10+
/src/wolfcrypt/src/wolfcrypt_last.c
11+
/src/wolfssl/wolfcrypt/fips.h
12+
/**/*.bak

0 commit comments

Comments
 (0)