Repository navigation
feat(ci): migrate AVR8JS + QEMU emulation to fbuild test-emu - #2296
Conversation
Replaces the Docker-based emulation CI pipeline (avr8js_docker_template.yml, qemu_docker_template.yml) with direct `fbuild test-emu` invocations. fbuild 2.1.16+ ships a native `test-emu` subcommand that: - Compiles the sketch and runs it under avr8js / qemu / simavr. - Handles --timeout, --halt-on-success, --halt-on-error, --expect natively, replacing ~400 lines of bash+Python-inline orchestration per template. - Auto-downloads the Espressif QEMU binary on first use, eliminating the espressif/idf Docker image pull. - Auto-installs the avr8js npm package into ~/.fbuild/cache/, so the niteris/fastled-avr8js Docker image is no longer needed. - Reads firmware from its own .fbuild/build/<env>/release/ layout directly, obviating the .pio/build/ path-mirror workarounds added in #2285 and patched in #2291. Both templates drop from ~400 lines to ~150, preserving: - The trusted/pr-code security checkout split. - Python 3.11 + uv pinning, `uv sync` for deps. - Halt / success / error regexes (AVR8JS: "Test setup starting" + "Test loop"; QEMU: "Test finished.*completed.*iterations|Starting loop iteration 2" + "Guru Meditation|abort()"). - Artifact uploads for both success and failure paths. Dependencies: - FastLED/fbuild#85 (ESP32-C3 RISC-V QEMU support) — required for the qemu_esp32c3_test.yml path. Once merged, the C3 job starts passing. - FastLED/fbuild#86 (avr8js auto-install robustness) — required for the avr8js path. Belt-and-suspenders `npm install [email protected]` added to the workflow as a hedge until #86 lands. Follow-ups (not in this PR): - Remove `_mirror_fbuild_artifacts_to_pio` (ci/compiler/pio.py:56-99) and its call site, plus the `use_fbuild = False` override in build_with_merged_bin (lines 1189-1196), once CI is confirmed green. - Close #2291 as obsolete (mirror-ordering fix is no longer on the emulation code path). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughTwo GitHub Actions workflow templates replaced Docker-based emulation with Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/qemu_docker_template.yml:
- Around line 9-11: The comment about ESP32-C3 QEMU support being blocked by
FastLED/fbuild#85 is stale; update the comment that mentions "Until that ships,
C3 runs will fail" to reflect that the fix landed (fbuild#90 / fbuild ≥ 2.1.16)
or remove the hedge entirely so the matrix entry for "esp32c3" correctly
indicates it is expected to work; locate the existing comment referencing
"esp32c3" and fbuild#85 and either delete the sentence or replace it with a
concise note like "ESP32-C3 QEMU support available as of fbuild ≥ 2.1.16
(fbuild#90)."
- Around line 129-132: The grep-count substitutions double-print zeros because
`grep -c` outputs "0" but exits nonzero, triggering `|| echo 0`; update the four
echo lines that use `$(grep -c '...' qemu_output.log || echo 0)` (the Boot
messages, Setup messages, Loop iterations and any similar lines) to either
remove the `|| echo 0` fallback entirely (since `grep -c` prints 0 itself) or
replace the fallback with `|| true` so the command returns success without
emitting an extra "0"; ensure you change the exact command substitutions in
those echo lines (e.g., the `grep -c 'rst:'`, `grep -c 'setup starting'`, and
`grep -c 'Starting loop iteration'` usages).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 55068228-adb2-4950-bbd4-b8039ce14851
📒 Files selected for processing (2)
.github/workflows/avr8js_docker_template.yml.github/workflows/qemu_docker_template.yml
| # ESP32-C3 support depends on FastLED/fbuild#85. Until that ships, C3 runs | ||
| # will fail — esp32c3 is kept in the matrix so the green signal (once the | ||
| # fbuild fix lands) re-enables it automatically. |
There was a problem hiding this comment.
Stale comment: fbuild#85 has already shipped.
Per the PR description, ESP32-C3 QEMU support (FastLED/fbuild#85) was merged via fbuild#90, so this comment's "Until that ships, C3 runs will fail" is now misleading. Please either delete the hedge or reword it to note that esp32c3 is expected to work as of fbuild ≥ 2.1.16.
📝 Suggested rewrite
-# ESP32-C3 support depends on FastLED/fbuild#85. Until that ships, C3 runs
-# will fail — esp32c3 is kept in the matrix so the green signal (once the
-# fbuild fix lands) re-enables it automatically.
+# ESP32-C3 support requires FastLED/fbuild#85 (merged via fbuild#90), which
+# is included in fbuild >= 2.1.16. Pin via pyproject.toml so esp32c3 stays
+# green.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # ESP32-C3 support depends on FastLED/fbuild#85. Until that ships, C3 runs | |
| # will fail — esp32c3 is kept in the matrix so the green signal (once the | |
| # fbuild fix lands) re-enables it automatically. | |
| # ESP32-C3 support requires FastLED/fbuild#85 (merged via fbuild#90), which | |
| # is included in fbuild >= 2.1.16. Pin via pyproject.toml so esp32c3 stays | |
| # green. |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/qemu_docker_template.yml around lines 9 - 11, The comment
about ESP32-C3 QEMU support being blocked by FastLED/fbuild#85 is stale; update
the comment that mentions "Until that ships, C3 runs will fail" to reflect that
the fix landed (fbuild#90 / fbuild ≥ 2.1.16) or remove the hedge entirely so the
matrix entry for "esp32c3" correctly indicates it is expected to work; locate
the existing comment referencing "esp32c3" and fbuild#85 and either delete the
sentence or replace it with a concise note like "ESP32-C3 QEMU support available
as of fbuild ≥ 2.1.16 (fbuild#90)."
| echo "Lines: $(wc -l < qemu_output.log)" | ||
| echo "Boot messages: $(grep -c 'rst:' qemu_output.log || echo 0)" | ||
| echo "Setup messages: $(grep -c 'setup starting' qemu_output.log || echo 0)" | ||
| echo "Loop iterations: $(grep -c 'Starting loop iteration' qemu_output.log || echo 0)" |
There was a problem hiding this comment.
grep -c ... || echo 0 double-prints on zero matches.
grep -c already prints 0 to stdout when there are no matches, but it also exits with status 1, which triggers || echo 0. Command substitution captures both outputs, and the unquoted echo word-splits them, so a zero-match case renders as Boot messages: 0 0. Either drop the fallback (grep -c is self-sufficient for printing) or replace with || true.
🔧 Suggested fix
- echo "Boot messages: $(grep -c 'rst:' qemu_output.log || echo 0)"
- echo "Setup messages: $(grep -c 'setup starting' qemu_output.log || echo 0)"
- echo "Loop iterations: $(grep -c 'Starting loop iteration' qemu_output.log || echo 0)"
+ echo "Boot messages: $(grep -c 'rst:' qemu_output.log 2>/dev/null || true)"
+ echo "Setup messages: $(grep -c 'setup starting' qemu_output.log 2>/dev/null || true)"
+ echo "Loop iterations: $(grep -c 'Starting loop iteration' qemu_output.log 2>/dev/null || true)"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| echo "Lines: $(wc -l < qemu_output.log)" | |
| echo "Boot messages: $(grep -c 'rst:' qemu_output.log || echo 0)" | |
| echo "Setup messages: $(grep -c 'setup starting' qemu_output.log || echo 0)" | |
| echo "Loop iterations: $(grep -c 'Starting loop iteration' qemu_output.log || echo 0)" | |
| echo "Lines: $(wc -l < qemu_output.log)" | |
| echo "Boot messages: $(grep -c 'rst:' qemu_output.log 2>/dev/null || true)" | |
| echo "Setup messages: $(grep -c 'setup starting' qemu_output.log 2>/dev/null || true)" | |
| echo "Loop iterations: $(grep -c 'Starting loop iteration' qemu_output.log 2>/dev/null || true)" |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/qemu_docker_template.yml around lines 129 - 132, The
grep-count substitutions double-print zeros because `grep -c` outputs "0" but
exits nonzero, triggering `|| echo 0`; update the four echo lines that use
`$(grep -c '...' qemu_output.log || echo 0)` (the Boot messages, Setup messages,
Loop iterations and any similar lines) to either remove the `|| echo 0` fallback
entirely (since `grep -c` prints 0 itself) or replace the fallback with `||
true` so the command returns success without emitting an extra "0"; ensure you
change the exact command substitutions in those echo lines (e.g., the `grep -c
'rst:'`, `grep -c 'setup starting'`, and `grep -c 'Starting loop iteration'`
usages).
… mirror Replaces the ``_mirror_fbuild_artifacts_to_pio`` workaround with a direct read from whichever backend produced the artifacts. Adds ``PioCompiler._artifacts_dir(env_name)`` returning either ``.fbuild/build/<env>/release/`` (when use_fbuild=True) or ``.pio/build/<env>/`` (PlatformIO). ``build_with_merged_bin`` and ``get_merged_bin_path`` both use the helper, so esptool merge_bin runs against fbuild's output without any cross-directory copy. The mirror was added in #2285 and extended in #2292 to bridge fbuild output into ``.pio/build/`` so legacy consumers (QEMU/AVR8JS workflows, crash decoder, ``build_with_merged_bin``) kept working. The new ``fbuild test-emu`` workflows (#2296) read fbuild's release dir directly, leaving ``build_with_merged_bin`` as the only remaining consumer — and that is now also fbuild-aware, so the mirror has no callers left. Diagnostic dump in the missing-artifacts branch now labels the active backend's dir explicitly and lists both possible locations, so the debug story when artifacts vanish is at least as good as before. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Replaces the Docker-based AVR8JS + ESP32 QEMU CI pipeline with direct
fbuild test-emuinvocations. fbuild 2.1.16+ ships a nativetest-emusubcommand with built-in--timeout,--halt-on-success,--halt-on-error,--expect, plus auto-download of Espressif QEMU binaries and auto-npm-install ofavr8js. That replaces ~550 lines of hand-rolled bash + Python-inline Docker orchestration per template.Both templates drop from ~400 lines to ~150, net -559 lines across the two files.
Why not just keep patching pio.py?
Prior fixes (#2285, #2291 open) taught FastLED's
ci/compiler/pio.pyto mirror fbuild artifacts from.fbuild/build/<env>/release/into the legacy.pio/build/<env>/path that the Docker workflows expected. That's fighting the tool. fbuild already knows where to find its own output — we just need to let it drive the emulator itself.After this PR, the mirror helper (
_mirror_fbuild_artifacts_to_pio) and theuse_fbuild = Falseoverride inbuild_with_merged_binbecome dead code for the emulation path. Cleanup tracked as a follow-up once CI is green (so we don't destabilize in a single PR).Dependencies
qemu_esp32c3_test.ymlpath (C3 is RISC-V; stock fbuild only supported xtensa ESP32/S3). PR Wrong red LED colour for WS2812 #90 adds RISC-V + also enables c6/h2.ERR_MODULE_NOT_FOUND: Cannot find package 'avr8js'because fbuild's first-timenpm install avr8jsinto~/.fbuild/prod/cache/avr8js-node/silently no-op'd. Workaround: I added a belt-and-suspendersnpm install [email protected]step toavr8js_docker_template.ymlthat unconditionally populates the cache before test-emu. Once pixel value of 1 not visible when dithering is set to 0. #86 lands and fbuild is re-released, that step can be removed.What the new workflows do
avr8js_docker_template.yml(renamed internally "AVR8JS Test Template (fbuild)", filename kept for trigger-workflow compatibility):trusted/+pr-code/+ safe-file merge) — unchanged.uv sync+actions/setup-node@v4@ node 20.npm install [email protected]into~/.fbuild/prod/cache/avr8js-node/.uv run ci/ci-compile.py uno --examples Test— stages + builds firmware.uv run fbuild test-emu --emulator avr8js --environment uno --timeout 30 --halt-on-success "Test loop" --halt-on-error "PANIC|ABORT|assert" --expect "Test setup starting" .build/pio/unoavr8js_output.logon success + failure paths.qemu_docker_template.yml(renamed "ESP32 QEMU Test Template (fbuild)"):uv sync.uv run ci/ci-compile.py <env> --examples <sketch> --merged-bin --defines FASTLED_ESP32_IS_QEMU— stages + builds with the merged flash image and the QEMU feature define.uv run fbuild test-emu --emulator qemu --environment <env> --timeout 120 --halt-on-success "setup starting" --halt-on-error "Guru Meditation|abort()|Backtrace:" .build/pio/<env>qemu_output.log.Success semantics
Matches what the legacy Docker pipeline effectively did: reaching
setup()is enough. For BlinkParallel and other driver-backed sketches, the RMT peripheral is not fully modeled in QEMU andshowPixels()stalls beforeloop()— the previous pipeline treated "setup starting + no crash" as pass; so do we, via--halt-on-success "setup starting"which short-circuits the stall. For AVR8JS the sketch is fast enough to reachloop()so we use the stricter"Test loop"pattern.Verification
fbuild test-emu --emulator qemu --environment esp32s3 --timeout 30 --halt-on-success "setup starting" .build/pio/esp32s3→ exit 0 in ~10s,"QEMU ESP32S3 test-emu passed: halt-on-success pattern matched: BlinkParallel setup starting".Out of scope (follow-ups)
_mirror_fbuild_artifacts_to_pioand theuse_fbuild = Falsebranch inci/compiler/pio.py, then close fix(ci): mirror fbuild artifacts AFTER pio metadata gen (AVR8JS+QEMU still red) #2291 as obsolete.fbuild>=2.1.12to a post-Wrong red LED colour for WS2812 #90 release once it publishes on PyPI.npm installstep once pixel value of 1 not visible when dithering is set to 0. #86 lands.🤖 Generated with Claude Code
Summary by CodeRabbit