Skip to content

Commit f44e3f5

Browse files
committed
feat(ci): implement caching mechanism for documentation binaries and streamline preparation process in CI workflows
1 parent 1d9ddbb commit f44e3f5

File tree

4 files changed

+93
-82
lines changed

4 files changed

+93
-82
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/scripts/docs_build_examples.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ def parse_args(argv):
118118
action="store_true",
119119
help="Clean up docs binaries directory and exit",
120120
)
121+
p.add_argument(
122+
"-p",
123+
dest="prepare_cached",
124+
action="store_true",
125+
help="Prepare cached binaries from docs_binaries/ to docs/_static/binaries/",
126+
)
121127
p.add_argument(
122128
"-d",
123129
dest="generate_diagrams",
@@ -182,6 +188,55 @@ def cleanup_binaries():
182188
print("Cleanup completed")
183189

184190

191+
def prepare_cached_binaries():
192+
"""Copy cached binaries from docs_binaries/ to docs/_static/binaries/"""
193+
import re
194+
195+
docs_binaries = Path("docs_binaries")
196+
if not docs_binaries.exists():
197+
print("WARNING: No docs_binaries directory found, continuing without binaries.")
198+
return 0
199+
200+
DOCS_BINARIES_DIR.mkdir(parents=True, exist_ok=True)
201+
202+
bin_count = 0
203+
# Find all .merged.bin files
204+
for bin_file in docs_binaries.rglob("*.merged.bin"):
205+
bin_name = bin_file.name
206+
# Extract sketch name (remove .ino.merged.bin extension)
207+
sketch_name = bin_name.replace(".ino.merged.bin", "")
208+
209+
# Extract target from path
210+
target_match = re.search(r'/(esp32[a-z0-9]*)/', str(bin_file))
211+
if not target_match:
212+
continue
213+
target = target_match.group(1)
214+
215+
# Search for the sketch in libraries directory
216+
sketch_ino_files = list(Path('libraries').rglob(f'{sketch_name}.ino'))
217+
if not sketch_ino_files:
218+
continue
219+
220+
sketch_ino_file = sketch_ino_files[0]
221+
sketch_dir = sketch_ino_file.parent
222+
relative_path = str(sketch_dir).replace('libraries/', '', 1)
223+
224+
# Create output directory
225+
output_dir = DOCS_BINARIES_DIR / "libraries" / relative_path / target
226+
output_dir.mkdir(parents=True, exist_ok=True)
227+
228+
# Copy the .merged.bin file
229+
shutil.copy(bin_file, output_dir / bin_name)
230+
bin_count += 1
231+
232+
# Also copy ci.json if it exists in the same directory
233+
ci_json_file = bin_file.parent / "ci.json"
234+
if ci_json_file.exists():
235+
shutil.copy(ci_json_file, output_dir / "ci.json")
236+
237+
return bin_count
238+
239+
185240
def find_examples_with_upload_binary():
186241
res = []
187242
for ino in Path('.').rglob('*.ino'):
@@ -311,6 +366,16 @@ def main(argv):
311366
if args.cleanup:
312367
cleanup_binaries()
313368
return
369+
if args.prepare_cached:
370+
bin_count = prepare_cached_binaries()
371+
print(f'\nPrepared {bin_count} binaries for documentation')
372+
# Show project names
373+
print('\nProjects ready for documentation:')
374+
merged_bins = list(DOCS_BINARIES_DIR.rglob('*.ino.merged.bin'))
375+
project_names = sorted(set(f.name.replace('.ino.merged.bin', '') for f in merged_bins))
376+
for name in project_names:
377+
print(f' {name}')
378+
return
314379
validate_prerequisites(args)
315380
GENERATE_DIAGRAMS = args.generate_diagrams
316381
GENERATE_LAUNCHPAD_CONFIG = args.generate_launchpad_config

.github/workflows/docs_build.yml

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name: Documentation Build and Deploy CI
22

33
on:
4-
# # Wait for Compilation Tests workflow to complete (uses macOS binaries)
5-
# workflow_run:
6-
# workflows: ["Compilation Tests"]
7-
# types:
8-
# - completed
9-
# branches:
10-
# - master
11-
# - release/v2.x
12-
# - wokwi-embed-launchpad
4+
# Wait for Compilation Tests workflow to complete (uses macOS binaries)
5+
workflow_run:
6+
workflows: ["Compilation Tests"]
7+
types:
8+
- completed
9+
branches:
10+
- master
11+
- release/v2.x
12+
- wokwi-embed-launchpad
1313
# Manual trigger for testing docs changes without waiting for compilation
1414
workflow_dispatch:
1515
# Also run on direct pushes to docs or workflow files (for testing)
@@ -57,57 +57,11 @@ jobs:
5757
path: docs_binaries
5858
lookup-only: false
5959

60-
- name: Copy cached binaries to docs/_static/binaries/
61-
run: |
62-
mkdir -p docs/_static/binaries
63-
64-
if [ ! -d "docs_binaries" ]; then
65-
echo "WARNING: No docs_binaries directory found, continuing without binaries."
66-
exit 0
67-
fi
68-
69-
bin_count=0
70-
71-
while IFS= read -r bin_file; do
72-
bin_name=$(basename "$bin_file")
73-
sketch_name="${bin_name%.ino.merged.bin}"
74-
75-
if [[ "$bin_file" =~ /(esp32[a-z0-9]*)/ ]]; then
76-
target="${BASH_REMATCH[1]}"
77-
else
78-
continue
79-
fi
80-
81-
sketch_ino_file=$(find libraries -type f -name "${sketch_name}.ino" 2>/dev/null | head -1)
82-
if [ -z "$sketch_ino_file" ]; then
83-
continue
84-
fi
85-
86-
sketch_dir=$(dirname "$sketch_ino_file")
87-
relative_path="${sketch_dir#libraries/}"
88-
output_dir="docs/_static/binaries/libraries/${relative_path}/${target}"
89-
mkdir -p "$output_dir"
90-
91-
cp "$bin_file" "$output_dir/"
92-
bin_count=$((bin_count + 1))
93-
94-
ci_json_file=$(dirname "$bin_file")/ci.json
95-
if [ -f "$ci_json_file" ]; then
96-
cp "$ci_json_file" "$output_dir/"
97-
fi
98-
done < <(find docs_binaries -type f -name "*.merged.bin")
99-
100-
- name: Cleanup Binaries
60+
- name: Prepare cached binaries for documentation
10161
run: |
62+
python3 .github/scripts/docs_build_examples.py -p
10263
python3 .github/scripts/docs_build_examples.py -c
10364
104-
- name: Show processed projects
105-
run: |
106-
echo "Projects ready for documentation:"
107-
find docs/_static/binaries/libraries -type f -name "*.ino.merged.bin" 2>/dev/null | while read f; do
108-
basename "$f" .ino.merged.bin
109-
done | sort -u
110-
11165
- name: Build
11266
run: |
11367
sudo apt update

.github/workflows/docs_deploy.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: Documentation Build and Production Deploy CI
22

33
on:
44
workflow_run:
5-
workflows: ["ESP32 Arduino Release"]
5+
workflows: ["ESP32 Arduino Release", "Compilation Tests"]
66
types:
77
- completed
8+
workflow_dispatch:
89
push:
910
branches:
1011
- release/v2.x
@@ -40,6 +41,21 @@ jobs:
4041
cache: "pip"
4142
python-version: "3.10"
4243

44+
- name: Restore docs binaries from cache (macOS builds)
45+
id: cache-restore
46+
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
47+
with:
48+
key: docs-binaries-macos-${{ github.run_id }}
49+
restore-keys: |
50+
docs-binaries-macos-
51+
path: docs_binaries
52+
lookup-only: false
53+
54+
- name: Prepare cached binaries for documentation
55+
run: |
56+
python3 .github/scripts/docs_build_examples.py -p
57+
python3 .github/scripts/docs_build_examples.py -c
58+
4359
- name: Deploy Documentation
4460
env:
4561
# Deploy to production server

0 commit comments

Comments
 (0)