Skip to content

Commit 95dfaf9

Browse files
committed
feat(docs): enhance example build script and CI workflow with diagram generation and updated requirements
1 parent 0fd405b commit 95dfaf9

File tree

3 files changed

+43
-57
lines changed

3 files changed

+43
-57
lines changed

.github/scripts/docs_build_examples.py

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import argparse
1010
from argparse import RawDescriptionHelpFormatter
11+
from esp_docs.generic_extensions.docs_embed.tool.wokwi_tool import DiagramSync
1112
import json
1213
import os
1314
import shutil
@@ -20,6 +21,9 @@
2021
# Determine SDKCONFIG_DIR like the shell script
2122
ARDUINO_ESP32_PATH = os.environ.get("ARDUINO_ESP32_PATH")
2223
GITHUB_WORKSPACE = os.environ.get("GITHUB_WORKSPACE")
24+
DOCS_DEPLOY_URL_BASE = os.environ.get("DOCS_PROD_URL_BASE")
25+
REPO_URL_PREFIX = os.environ.get("REPO_URL_PREFIX")
26+
2327

2428
if ARDUINO_ESP32_PATH and (Path(ARDUINO_ESP32_PATH) / "tools" / "esp32-arduino-libs").is_dir():
2529
SDKCONFIG_DIR = Path(ARDUINO_ESP32_PATH) / "tools" / "esp32-arduino-libs"
@@ -31,10 +35,15 @@
3135
# Wrapper functions to call sketch_utils.sh
3236
SKETCH_UTILS = SCRIPT_DIR / "sketch_utils.sh"
3337

34-
KEEP_FILES = ["*.merged.bin", "ci.json"]
38+
KEEP_FILES = [
39+
"*.merged.bin",
40+
"ci.json",
41+
"launchpad.toml",
42+
"diagram*.json",
43+
]
3544
DOCS_BINARIES_DIR = Path("docs/_static/binaries")
3645
GENERATE_DIAGRAMS = False
37-
LAUNCHPAD_STORAGE_URL = ""
46+
GENERATE_LAUNCHPAD_CONFIG = False
3847

3948

4049
def run_cmd(cmd, check=True, capture_output=False, text=True):
@@ -117,8 +126,9 @@ def parse_args(argv):
117126
)
118127
p.add_argument(
119128
"-l",
120-
dest="launchpad_storage_url",
121-
help="LaunchPad storage URL to include in generated config",
129+
dest="generate_launchpad_config",
130+
action="store_true",
131+
help="Generate LaunchPad config with configured storage URL",
122132
)
123133
return p.parse_args(argv)
124134

@@ -233,42 +243,18 @@ def build_example_for_target(sketch_dir, target, relative_path, args):
233243
shutil.copy(ci_json, output_dir / 'ci.json')
234244
if GENERATE_DIAGRAMS:
235245
print(f"Generating diagram for {relative_path} ({target})...")
236-
rc = run_cmd(
237-
[
238-
"docs-embed",
239-
"--path",
240-
str(output_dir),
241-
"diagram-from-ci",
242-
"--platform",
243-
target,
244-
"--override",
245-
],
246-
check=False,
247-
)
248-
if rc.returncode == 0:
249-
print("Diagram generated successfully for {relative_path} ({target})")
250-
else:
251-
print("WARNING: Failed to generate diagram for {relative_path} ({target})")
252-
if LAUNCHPAD_STORAGE_URL:
246+
try:
247+
sync = DiagramSync(output_dir)
248+
sync.generate_diagram_from_ci(target)
249+
except Exception as e:
250+
print(f"WARNING: Failed to generate diagram for {relative_path} ({target}): {e}")
251+
if GENERATE_LAUNCHPAD_CONFIG:
253252
print(f"Generating LaunchPad config for {relative_path} ({target})...")
254-
rc = run_cmd(
255-
[
256-
"docs-embed",
257-
"--path",
258-
str(output_dir),
259-
"launchpad-config",
260-
LAUNCHPAD_STORAGE_URL,
261-
"--repo-url-prefix",
262-
"https://github.com/espressif/arduino-esp32/tree/master",
263-
"--override",
264-
],
265-
check=False,
266-
)
267-
if rc.returncode == 0:
268-
print("LaunchPad config generated successfully for {relative_path} ({target})")
269-
else:
270-
print("WARNING: Failed to generate LaunchPad config for {relative_path} ({target})")
271-
return True
253+
try:
254+
sync = DiagramSync(output_dir)
255+
sync.generate_launchpad_config(DOCS_DEPLOY_URL_BASE, REPO_URL_PREFIX)
256+
except Exception as e:
257+
print(f"WARNING: Failed to generate LaunchPad config for {relative_path} ({target}): {e}")
272258
else:
273259
print(f"ERROR: Failed to build {relative_path} for {target}")
274260
return False
@@ -320,14 +306,14 @@ def build_all_examples(args):
320306

321307

322308
def main(argv):
323-
global GENERATE_DIAGRAMS, LAUNCHPAD_STORAGE_URL
309+
global GENERATE_DIAGRAMS, GENERATE_LAUNCHPAD_CONFIG
324310
args = parse_args(argv)
325311
if args.cleanup:
326312
cleanup_binaries()
327313
return
328314
validate_prerequisites(args)
329315
GENERATE_DIAGRAMS = args.generate_diagrams
330-
LAUNCHPAD_STORAGE_URL = args.launchpad_storage_url or ""
316+
GENERATE_LAUNCHPAD_CONFIG = args.generate_launchpad_config
331317
DOCS_BINARIES_DIR.mkdir(parents=True, exist_ok=True)
332318
result = build_all_examples(args)
333319
if result == 0:

.github/workflows/docs_build.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ jobs:
3535
cache: "pip"
3636
python-version: "3.10"
3737

38-
- name: Build
39-
run: |
40-
sudo apt update
41-
sudo apt install python3-pip python3-setuptools
42-
# GitHub CI installs pip3 and setuptools outside the path.
43-
# Update the path to include them and run.
44-
cd ./docs
45-
PATH=/home/runner/.local/bin:$PATH pip3 install -r requirements.txt --prefer-binary
46-
PATH=/home/runner/.local/bin:$PATH SPHINXOPTS="-W" build-docs -l en
47-
4838
- name: Build Examples
4939
run: |
5040
source .github/scripts/install-arduino-cli.sh
@@ -55,6 +45,16 @@ jobs:
5545
run: |
5646
python3 .github/scripts/docs_build_examples.py -c
5747
48+
- name: Build
49+
run: |
50+
sudo apt update
51+
sudo apt install python3-pip python3-setuptools
52+
# GitHub CI installs pip3 and setuptools outside the path.
53+
# Update the path to include them and run.
54+
cd ./docs
55+
PATH=/home/runner/.local/bin:$PATH pip3 install -r requirements.txt --prefer-binary
56+
PATH=/home/runner/.local/bin:$PATH SPHINXOPTS="-W" build-docs -l en
57+
5858
- name: Archive Docs
5959
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
6060
with:

docs/requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
sphinx==4.5.0
1+
sphinx
22
esp-docs @ git+https://github.com/JakubAndrysek/esp-docs.git@extensions/wokwi_embed
3-
sphinx-copybutton==0.5.0
4-
sphinx-tabs==3.2.0
5-
numpydoc==1.5.0
6-
standard-imghdr==3.13.0
7-
Sphinx-Substitution-Extensions==2022.2.16
3+
sphinx-copybutton
4+
sphinx-tabs
5+
numpydoc
6+
standard-imghdr
7+
Sphinx-Substitution-Extensions

0 commit comments

Comments
 (0)