Skip to content

Commit 787163b

Browse files
committed
feat(docs): Add documentation build examples script and update CI workflows
1 parent 7a9a10c commit 787163b

File tree

10 files changed

+702
-41
lines changed

10 files changed

+702
-41
lines changed

.github/scripts/docs_build_examples.py

Lines changed: 499 additions & 0 deletions
Large diffs are not rendered by default.

.github/scripts/sketch_utils.sh

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ function check_requirements { # check_requirements <sketchdir> <sdkconfig_path>
5454
}
5555

5656
function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
57+
local first_only=false
58+
5759
while [ -n "$1" ]; do
5860
case "$1" in
5961
-ai )
@@ -92,6 +94,36 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
9294
shift
9395
debug_level="DebugLevel=$1"
9496
;;
97+
-b )
98+
shift
99+
custom_build_dir=$1
100+
;;
101+
--first-only )
102+
first_only=true
103+
;;
104+
-h )
105+
echo "Usage: build_sketch [options]"
106+
echo ""
107+
echo "Build an Arduino sketch for ESP32 targets."
108+
echo ""
109+
echo "Required options:"
110+
echo " -ai <path> Arduino IDE path"
111+
echo " -au <path> Arduino user path"
112+
echo " -s <path> Sketch directory containing .ino file and ci.yml"
113+
echo " -t <target> Target chip (esp32, esp32s2, esp32c3, esp32s3, esp32c6, esp32h2, esp32p4, esp32c5)"
114+
echo " Required unless -fqbn is specified"
115+
echo ""
116+
echo "Optional options:"
117+
echo " -fqbn <fqbn> Fully qualified board name (alternative to -t)"
118+
echo " -o <options> Board options (PSRAM, USBMode, etc.) [default: chip-specific]"
119+
echo " -i <index> Chunk index for parallel builds [default: none]"
120+
echo " -l <file> Log compilation output to JSON file [default: none]"
121+
echo " -d <level> Debug level (DebugLevel=...) [default: none]"
122+
echo " -b <path> Custom build directory [default: \$ARDUINO_BUILD_DIR or \$HOME/.arduino/tests/\$target/\$sketchname/build.tmp]"
123+
echo " --first-only Build only the first FQBN from ci.yml configurations [default: false]"
124+
echo " -h Show this help message"
125+
exit 0
126+
;;
95127
* )
96128
break
97129
;;
@@ -128,7 +160,15 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
128160

129161
len=$(yq eval ".fqbn.${target} | length" "$sketchdir"/ci.yml 2>/dev/null || echo 0)
130162
if [ "$len" -gt 0 ]; then
131-
fqbn=$(yq eval ".fqbn.${target} | sort | @json" "$sketchdir"/ci.yml)
163+
if [ "$first_only" = true ]; then
164+
# Get only the first FQBN from the array (original order)
165+
fqbn=$(yq eval ".fqbn.${target} | .[0]" "$sketchdir"/ci.yml 2>/dev/null)
166+
fqbn="[\"$fqbn\"]"
167+
len=1
168+
else
169+
# Build all FQBNs
170+
fqbn=$(yq eval ".fqbn.${target} | sort | @json" "$sketchdir"/ci.yml)
171+
fi
132172
fi
133173
fi
134174

@@ -219,12 +259,14 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
219259
fi
220260

221261
# The directory that will hold all the artifacts (the build directory) is
222-
# provided through:
223-
# 1. An env variable called ARDUINO_BUILD_DIR.
224-
# 2. Created at the sketch level as "build" in the case of a single
225-
# configuration test.
226-
# 3. Created at the sketch level as "buildX" where X is the number
227-
# of configuration built in case of a multiconfiguration test.
262+
# determined by the following priority:
263+
# 1. Custom build directory via -b flag:
264+
# - If path contains "docs/_static/binaries", use as exact path (for docs builds)
265+
# - Otherwise, append target name to custom directory
266+
# 2. ARDUINO_BUILD_DIR environment variable (if set)
267+
# 3. Default: $HOME/.arduino/tests/$target/$sketchname/build.tmp
268+
#
269+
# For multiple configurations, subsequent builds use .1, .2, etc. suffixes
228270

229271
sketchname=$(basename "$sketchdir")
230272
local has_requirements
@@ -253,22 +295,34 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
253295
fi
254296

255297
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
256-
if [ -n "$ARDUINO_BUILD_DIR" ]; then
257-
build_dir="$ARDUINO_BUILD_DIR"
258-
elif [ "$len" -eq 1 ]; then
259-
# build_dir="$sketchdir/build"
260-
build_dir="$HOME/.arduino/tests/$target/$sketchname/build.tmp"
298+
299+
# Determine base build directory
300+
if [ -n "$custom_build_dir" ]; then
301+
# If custom_build_dir contains docs/_static/binaries, use it as exact path
302+
if [[ "$custom_build_dir" == *"docs/_static/binaries"* ]]; then
303+
build_dir_base="$custom_build_dir"
304+
else
305+
build_dir_base="$custom_build_dir/$target"
306+
fi
307+
elif [ -n "$ARDUINO_BUILD_DIR" ]; then
308+
build_dir_base="$ARDUINO_BUILD_DIR"
309+
else
310+
build_dir_base="$HOME/.arduino/tests/$target/$sketchname/build.tmp"
261311
fi
262312

263313
output_file="$HOME/.arduino/cli_compile_output.txt"
264314
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
265315

266316
mkdir -p "$ARDUINO_CACHE_DIR"
267317
for i in $(seq 0 $((len - 1))); do
268-
if [ "$len" -ne 1 ]; then
269-
# build_dir="$sketchdir/build$i"
270-
build_dir="$HOME/.arduino/tests/$target/$sketchname/build$i.tmp"
318+
# Calculate build directory for this configuration
319+
if [ "$i" -eq 0 ]; then
320+
build_dir="$build_dir_base"
321+
else
322+
build_dir="${build_dir_base}.${i}"
271323
fi
324+
325+
# Prepare build directory
272326
rm -rf "$build_dir"
273327
mkdir -p "$build_dir"
274328

.github/workflows/docs_build.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- master
77
- release/v2.x
8+
- docs-embed
89
paths:
910
- "docs/**"
1011
- ".github/workflows/docs_build.yml"
@@ -34,18 +35,38 @@ jobs:
3435
cache: "pip"
3536
python-version: "3.10"
3637

37-
- name: Build
38+
# Install Arduino CLI and set environment variables
39+
- name: Install Arduino CLI
40+
run: |
41+
source .github/scripts/install-arduino-cli.sh
42+
echo "ARDUINO_IDE_PATH=$ARDUINO_IDE_PATH" >> $GITHUB_ENV
43+
echo "ARDUINO_USR_PATH=$ARDUINO_USR_PATH" >> $GITHUB_ENV
44+
45+
# Install Python dependencies needed for docs_build_examples.py
46+
- name: Install Python Dependencies
3847
run: |
3948
sudo apt update
4049
sudo apt install python3-pip python3-setuptools
41-
# GitHub CI installs pip3 and setuptools outside the path.
42-
# Update the path to include them and run.
4350
cd ./docs
4451
PATH=/home/runner/.local/bin:$PATH pip3 install -r requirements.txt --prefer-binary
52+
53+
# Build examples using environment variables from install script
54+
- name: Build Examples
55+
run: |
56+
PATH=/home/runner/.local/bin:$PATH python3 .github/scripts/docs_build_examples.py --build --diagram --launchpad
57+
58+
- name: Cleanup Binaries
59+
run: |
60+
PATH=/home/runner/.local/bin:$PATH python3 .github/scripts/docs_build_examples.py -c
61+
62+
63+
- name: Build
64+
run: |
65+
cd ./docs
4566
PATH=/home/runner/.local/bin:$PATH SPHINXOPTS="-W" build-docs -l en
4667
4768
- name: Archive Docs
4869
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
4970
with:
5071
name: docs
51-
path: docs
72+
path: docs

.github/workflows/docs_deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Documentation Build and Production Deploy CI
22

33
on:
4+
workflow_dispatch:
45
workflow_run:
56
workflows: ["ESP32 Arduino Release"]
67
types:

docs/conf_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"sphinx_tabs.tabs",
3636
"sphinx_substitution_extensions", # For allowing substitutions inside code blocks
3737
"esp_docs.esp_extensions.dummy_build_system",
38+
"esp_docs.generic_extensions.docs_embed",
3839
]
3940

4041
# ESP32_DOCS = [

docs/en/api/gpio.rst

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,7 @@ Example Code
141141
GPIO Input and Output Modes
142142
***************************
143143

144-
.. code-block:: arduino
145-
146-
#define LED 12
147-
#define BUTTON 2
148-
149-
uint8_t stateLED = 0;
150-
151-
void setup() {
152-
pinMode(LED, OUTPUT);
153-
pinMode(BUTTON,INPUT_PULLUP);
154-
}
155-
156-
void loop() {
157-
158-
if(!digitalRead(BUTTON)){
159-
stateLED = stateLED^1;
160-
digitalWrite(LED,stateLED);
161-
}
162-
}
144+
.. wokwi-example:: libraries/ESP32/examples/GPIO/Blink
163145

164146
GPIO Interrupt
165147
**************

docs/en/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@
3131

3232
# Tracking ID for Google Analytics
3333
google_analytics_id = "G-F58JM78930"
34+
35+
# Documentation embedding settings
36+
docs_embed_public_root = "https://docs.espressif.com/projects/arduino-esp32-wokwi-test"
37+
docs_embed_esp32_relative_root = "../.."
38+
docs_embed_launchpad_url = "https://espressif.github.io/esp-launchpad/"
39+
docs_embed_github_base_url = "https://github.com/JakubAndrysek/arduino-esp32"
40+
docs_embed_github_branch = "docs-embed"

docs/requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
sphinx==4.5.0
2-
esp-docs>=1.4.0
1+
sphinx~=7.1.2
2+
3+
esp-docs @ git+https://github.com/JakubAndrysek/esp-docs.git@extensions/wokwi_embed
4+
35
sphinx-copybutton==0.5.0
4-
sphinx-tabs==3.2.0
6+
sphinx-tabs==3.4.7
57
numpydoc==1.5.0
68
standard-imghdr==3.13.0
79
Sphinx-Substitution-Extensions==2022.2.16
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#define LED 12
2+
#define BUTTON 2
3+
4+
uint8_t stateLED = 0;
5+
6+
void setup() {
7+
pinMode(LED, OUTPUT);
8+
pinMode(BUTTON, INPUT_PULLUP);
9+
}
10+
11+
void loop() {
12+
if (!digitalRead(BUTTON)) {
13+
stateLED = !stateLED;
14+
digitalWrite(LED, stateLED);
15+
}
16+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
upload-binary:
2+
targets:
3+
- esp32
4+
- esp32s3
5+
diagram:
6+
esp32:
7+
parts:
8+
- type: wokwi-pushbutton
9+
id: btn1
10+
top: 140.6
11+
left: 144
12+
attrs:
13+
color: green
14+
- type: wokwi-led
15+
id: led1
16+
top: 66
17+
left: 131.4
18+
rotate: 90
19+
attrs:
20+
color: red
21+
connections:
22+
- - btn1:1.l
23+
- esp:0
24+
- blue
25+
- - h-19.2
26+
- v-19.2
27+
- - btn1:2.r
28+
- esp:GND.1
29+
- black
30+
- - h19.4
31+
- v48.2
32+
- h-240
33+
- v-67.2
34+
- - esp:GND.2
35+
- led1:C
36+
- black
37+
- - h33.64
38+
- v114.8
39+
- - esp:4
40+
- led1:A
41+
- green
42+
- - h0
43+
esp32s3:
44+
parts:
45+
- type: wokwi-pushbutton
46+
id: btn1
47+
top: 140.6
48+
left: 115.2
49+
attrs:
50+
color: green
51+
- type: wokwi-led
52+
id: led1
53+
top: 66.4
54+
left: -56.2
55+
rotate: 270
56+
attrs:
57+
color: red
58+
flip: ""
59+
connections:
60+
- - btn1:1.l
61+
- esp:0
62+
- blue
63+
- - h-19.2
64+
- v0
65+
- h-4.57
66+
- - btn1:2.r
67+
- esp:GND.3
68+
- green
69+
- - h19.4
70+
- v48.38
71+
- - esp:4
72+
- led1:A
73+
- green
74+
- - h0
75+
- - esp:GND.1
76+
- led1:C
77+
- black
78+
- - h0

0 commit comments

Comments
 (0)