From 325f09080b26db8ef8b2aaaca8bffd0d6b994159 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 22 Sep 2026 13:56:29 -0700 Subject: [PATCH] Zephyr autogen auto-update fixes Mainly sort the module deps so the autogen is deterministic. Also, detect an existing PR and update it instead of making a new one. --- .github/workflows/zephyr-autogen-pr.yml | 25 +++++++++++++++++++ .../zephyr-cp/cptools/build_circuitpython.py | 10 ++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/zephyr-autogen-pr.yml b/.github/workflows/zephyr-autogen-pr.yml index 0294cd2c4f0..25a0e9e686e 100644 --- a/.github/workflows/zephyr-autogen-pr.yml +++ b/.github/workflows/zephyr-autogen-pr.yml @@ -71,6 +71,25 @@ jobs: echo "changed=true" >> "$GITHUB_OUTPUT" git status --short -- 'ports/zephyr-cp/boards/**/autogen_board_info.toml' fi + - name: Find existing open autogen PR + id: pr + env: + GH_TOKEN: ${{ github.token }} + run: | + pr=$(gh pr list --state open --head zephyr-autogen-board-info --json number --jq '.[0].number // empty') + echo "number=$pr" >> "$GITHUB_OUTPUT" + if [ -n "$pr" ]; then + echo "Found existing open autogen PR #$pr; will push to it." + fi + - name: Delete stale autogen branch + # A new pull request cannot be created from a head branch that already + # had one. If the previous autogen PR was closed without merging, the + # branch lingers on; delete it so create-pull-request can start over. + if: steps.diff.outputs.changed == 'true' && steps.pr.outputs.number == '' + run: | + if git ls-remote --heads origin zephyr-autogen-board-info | grep -q zephyr-autogen-board-info; then + git push origin --delete zephyr-autogen-board-info + fi - name: Create PR if: steps.diff.outputs.changed == 'true' uses: peter-evans/create-pull-request@v8 @@ -78,9 +97,15 @@ jobs: add-paths: ports/zephyr-cp/boards/**/autogen_board_info.toml commit-message: Regenerate zephyr-cp autogen_board_info.toml files title: Regenerate zephyr-cp autogenerated board info + # create-pull-request pushes to the branch of an existing open PR, + # so a still-open autogen PR is updated in place instead of spawning + # a second one. body: | The `autogen_board_info.toml` files changed after building all zephyr-cp boards on `main`. Created by the "Update Zephyr autogenerated files" workflow. + + Based on commit: ${{ github.sha }} + Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} branch: zephyr-autogen-board-info delete-branch: true diff --git a/ports/zephyr-cp/cptools/build_circuitpython.py b/ports/zephyr-cp/cptools/build_circuitpython.py index 06271cadcc1..04f3996cf42 100644 --- a/ports/zephyr-cp/cptools/build_circuitpython.py +++ b/ports/zephyr-cp/cptools/build_circuitpython.py @@ -331,13 +331,19 @@ def determine_enabled_modules(board_info, portdir, srcdir): enabled_modules.add("ssl") module_reasons["ssl"] = "Zephyr networking enabled" - for port_module in (portdir / "bindings").iterdir(): + # Iterate the shared-bindings directory in a stable (sorted) order. Several + # modules can enable the same reverse dependency, and the "reason" comment + # recorded in autogen_board_info.toml belongs to whichever module enabled it + # first. Directory iteration order is filesystem dependent (it differs + # between machines and CI runners), so an unsorted walk made the generated + # comments - and therefore the committed toml files - change between builds. + for port_module in sorted((portdir / "bindings").iterdir(), key=lambda x: x.name): if not board_info.get(port_module.name, False): continue enabled_modules.add(port_module.name) module_reasons[port_module.name] = f"Zephyr board has {port_module.name}" - for shared_module in (srcdir / "shared-bindings").iterdir(): + for shared_module in sorted((srcdir / "shared-bindings").iterdir(), key=lambda x: x.name): if not board_info.get(shared_module.name, False) or not shared_module.glob("*.c"): continue enabled_modules.add(shared_module.name)