From 0f69e1b61cd5330fb7618b6373f63c7f030a37bc Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 08:09:43 -0500 Subject: [PATCH 01/14] chore(ci,docs): harden workflows and sync architecture docs - Expand the .github/scripts scope filter in ci.yml so edits to any Python script under .github/scripts/ run the script unit tests. - Run Peak memory in test-rust.yml when xtask changes too, building rustgis-cli first if nextest did not already build it. - Add explicit top-level `permissions: contents: read` to ci-label.yml and python.yml (preserving job-level write permissions in python.yml). - Serialize automerge label/unlabel events in automerge.yml, re-verify the automerge label before enabling/approving, and dismiss active approvals from the automerge account when the label is removed. - Sync the crate layer tables in docs/architecture.md and README.md (adding rustgis-keychain, rustgis-ui-touch, and rustgis-mobile) and update the cargo xtask ci summary to match xtask/src/main.rs. --- .github/workflows/automerge.yml | 31 ++++++++++++++++++++++++++----- .github/workflows/ci-label.yml | 3 +++ .github/workflows/ci.yml | 2 +- .github/workflows/python.yml | 3 +++ .github/workflows/test-rust.yml | 19 ++++++++++++++----- README.md | 8 +++++--- docs/architecture.md | 6 ++++-- 7 files changed, 56 insertions(+), 16 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 00c4d504be..36c1345a28 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -3,7 +3,7 @@ name: Auto-merge # A maintainer labels a pull request `automerge`: it's approved and joins the merge queue as soon # as the checks the `main` ruleset requires pass; the queue squash-merges it once its checks pass # on top of main. A later push drops the label and turns auto-merge off, -# so new commits need another look; removing the label turns it off too. +# so new commits need another look; removing the label turns it off and dismisses the approval too. # # `pull_request_target` so fork pull requests get the token; the pull request's code is never # checked out or run. The token is a maintainer's (`AUTOMERGE_TOKEN`), not GITHUB_TOKEN: Actions @@ -16,10 +16,11 @@ on: permissions: {} -# One group per action: a pending run is replaced by the next one in its group, so a push's revoke -# run mustn't share a group with runs for other labels. +# Serialize `automerge` label/unlabel events in one group so adding and quickly removing the label +# cannot race; keep `synchronize` and unrelated labels in separate groups so they cannot replace a +# pending revoke run. concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.action }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.action == 'synchronize' && 'synchronize' || (github.event.label.name == 'automerge' && 'label' || 'other') }} jobs: enable: @@ -35,6 +36,7 @@ jobs: SENDER: ${{ github.event.sender.login }} AUTHOR: ${{ github.event.pull_request.user.login }} run: | + set -euo pipefail # Triage can label too: only someone who could merge it themselves may use the label. perm=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$SENDER/permission" --jq .permission) case "$perm" in @@ -46,6 +48,12 @@ jobs: if [ "$SENDER" = "$AUTHOR" ] && [ "$AUTHOR" != "$owner" ]; then echo "::error::$SENDER can't use automerge on their own pull request."; exit 1 fi + # Re-verify the label is still present in case it was removed before this run started. + has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') + if [ "$has_label" != true ]; then + echo "automerge label was removed before enabling; skipping." + exit 0 + fi # Both pinned to the commit that was labelled: if the head has moved, enabling auto-merge # fails before anything is approved. gh pr merge "$PR" --auto --squash --match-head-commit "$SHA" @@ -65,7 +73,20 @@ jobs: - env: GH_TOKEN: ${{ secrets.AUTOMERGE_TOKEN }} PR: ${{ github.event.pull_request.html_url }} + NUMBER: ${{ github.event.pull_request.number }} ACTION: ${{ github.event.action }} run: | + set -euo pipefail gh pr merge "$PR" --disable-auto || echo "Auto-merge was off." - if [ "$ACTION" = synchronize ]; then gh pr edit "$PR" --remove-label automerge; fi + if [ "$ACTION" = synchronize ]; then + gh pr edit "$PR" --remove-label automerge + elif [ "$ACTION" = unlabeled ]; then + owner=$(gh api user --jq .login) + gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ + | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED") | .id' \ + | while read -r review_id; do + [ -n "$review_id" ] || continue + gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ + -f message="Automerge label removed" --silent + done + fi diff --git a/.github/workflows/ci-label.yml b/.github/workflows/ci-label.yml index 834cad0c18..88188f7b4f 100644 --- a/.github/workflows/ci-label.yml +++ b/.github/workflows/ci-label.yml @@ -13,6 +13,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.label.name }} cancel-in-progress: true +permissions: + contents: read + jobs: cancel: name: Cancel label CI diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66843bab2e..232e6ff360 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -172,7 +172,7 @@ jobs: echo "run=true" >> "$GITHUB_OUTPUT" exit 0 fi - if grep -qE '^(Cargo\.lock|(.*/)?Cargo\.toml|deny\.toml|about\.toml|xtask/src/(main|notices)\.rs|(.*/)?THIRD-PARTY-LICENSES\.txt|\.github/scripts/(check-cargo-sources|review-deferrals|ratchet-limits|test_[^/]+)\.py|\.github/workflows/ci\.yml|crates/map/src/color/(scientific|matplotlib)\.rs|crates/tiles/src/(symbols|style)\.rs|crates/data/src/(raster/crs|esripbf)\.rs)$|^(third-party/|\.cargo/)' <<<"$changed"; then + if grep -qE '^(Cargo\.lock|(.*/)?Cargo\.toml|deny\.toml|about\.toml|xtask/src/(main|notices)\.rs|(.*/)?THIRD-PARTY-LICENSES\.txt|\.github/scripts/[^/]+\.py|\.github/workflows/ci\.yml|crates/map/src/color/(scientific|matplotlib)\.rs|crates/tiles/src/(symbols|style)\.rs|crates/data/src/(raster/crs|esripbf)\.rs)$|^(third-party/|\.cargo/)' <<<"$changed"; then echo "run=true" >> "$GITHUB_OUTPUT" else echo "No dependency, licence or notice files changed; skipping." diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index a9f8ce846b..1b082a3f10 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -31,6 +31,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}-${{ github.event_name != 'pull_request' && github.run_id || 'pr' }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} +permissions: + contents: read + env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index c65a8cad48..0ba445498e 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -157,9 +157,18 @@ jobs: path: ${{ runner.temp }}/overlay-findings if-no-files-found: ignore # The command line's peak memory per workflow, as a multiple of loading alone, against - # xtask/memory-limits.txt (xtask/src/memory.rs). It runs the rustgis-cli the tests above - # built, so it costs only its own run; on Linux (GNU time), when the tests cover rustgis-cli, - # as they do whenever a package it uses changes. + # xtask/memory-limits.txt (xtask/src/memory.rs). On Linux (GNU time), when the tests cover + # rustgis-cli (as they do whenever a package it uses changes) or xtask itself (such as + # changes to memory-limits.txt or memory.rs). Reuses the rustgis-cli binary nextest built + # when present, building it only when xtask ran without rustgis-cli. - name: Peak memory - if: matrix.os == 'ubuntu-latest' && (inputs.packages == '--workspace' || contains(format('{0} ', inputs.packages), '-p rustgis-cli ')) - run: cargo xtask memory --cli target/debug/rustgis-cli + if: matrix.os == 'ubuntu-latest' && (inputs.packages == '--workspace' || contains(format('{0} ', inputs.packages), '-p rustgis-cli ') || contains(format('{0} ', inputs.packages), '-p xtask ')) + shell: bash + env: + PACKAGES: ${{ inputs.packages }} + run: | + set -euo pipefail + if [ ! -x target/debug/rustgis-cli ] || { [ "$PACKAGES" != --workspace ] && [[ " $PACKAGES " != *" -p rustgis-cli "* ]]; }; then + cargo build --locked -p rustgis-cli + fi + cargo xtask memory --cli target/debug/rustgis-cli diff --git a/README.md b/README.md index 858bcb1c68..495ce193e7 100644 --- a/README.md +++ b/README.md @@ -192,16 +192,18 @@ Layered crates, each depending only on the ones below it: | L1 | `rustgis-data` | features and typed attributes; GeoJSON, CSV, Shapefile, KML, GPX and more; GeoPackage, GeoParquet, FlatGeobuf, LiDAR, PostGIS and MySQL providers; GDAL formats and DuckDB queries through their programs; SQL where clauses; rasters (GeoTIFF, ASCII grid, Zarr) and their coordinate systems | | L2 | `rustgis-map`, `rustgis-analysis` | layers, symbology, labeling, camera, basemaps; geoprocessing (on `geo`) | | L2 | `rustgis-tiles` | web map tiles: XYZ/TMS/WMS, Mapbox Vector Tiles, PMTiles and MBTiles archives, MapLibre styles, the tile cache | +| L2 | `rustgis-keychain` | the system's secret store (macOS Keychain, Windows Credential Manager, Secret Service) | | L3 | `rustgis-render` | tiny-skia renderer, label placement, PNG export, fonts | | L3 | `rustgis-plugins` | sandboxed WebAssembly plugins and the plugin registry | | L3 | `rustgis-geolibre` | the GeoLibre tool suite as geoprocessing tools | | L4 | `rustgis-engine` | session, undo, command registry, sample project | | L5 | `rustgis-assistant` | the AI Assistant: a chat agent that acts through commands | | L6 | `rustgis-ui-egui` | the ribbon front end (swappable) | -| apps | `rustgis`, `rustgis-cli`, `rustgis-web`, `rustgis-python` | desktop, command line, browser (WebAssembly), the `rustgis` Python package | +| L7 | `rustgis-ui-touch` | the phone and tablet interface around `rustgis-ui-egui`'s map view | +| apps | `rustgis`, `rustgis-cli`, `rustgis-web`, `rustgis-python`, `rustgis-mobile` | desktop, command line, browser (WebAssembly), the `rustgis` Python package, Android and iOS | -`cargo xtask ci` runs formatting, clippy, the tests and the layering check. Contributor and -agent notes: [AGENTS.md](AGENTS.md). +`cargo xtask ci` runs test hygiene, formatting, clippy, the tests, layering, attribution, row-use +and schema checks. Contributor and agent notes: [AGENTS.md](AGENTS.md). ## Sponsor diff --git a/docs/architecture.md b/docs/architecture.md index bf89a12c48..70ac768ffe 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -9,13 +9,15 @@ engine scriptable and the front end swappable. | L1 | `rustgis-data` | Features, typed attributes, vector and spreadsheet I/O, SQL where clauses, LiDAR, rasters and EPSG reprojection; indexed file and remote data providers; live PostGIS, MySQL/MariaDB and SQL Server providers on the desktop; optional GDAL and DuckDB programs (see [Data formats](user-guide/data-formats.md)) | | L2 | `rustgis-map`, `rustgis-analysis` | Layers, symbology, labeling, camera, basemaps and web tile layers; geoprocessing tools | | L2 | `rustgis-tiles` | Web map tiles: XYZ/TMS/WMS raster tiles, Mapbox Vector Tiles, PMTiles and MBTiles archives and a subset of MapLibre styles; a cache that fetches in the background (worker threads natively, the browser's `fetch` on the web) | +| L2 | `rustgis-keychain` | OS credential store backend (macOS Keychain, Windows Credential Manager, Secret Service on Linux/BSD; see [Secrets](#secrets)) | | L3 | `rustgis-render` | tiny-skia renderer, label placement, font discovery, map and layout export, and UI-independent GPU scene preparation | | L3 | `rustgis-geolibre` | The [GeoLibre tools](user-guide/analysis.md#geolibre-tools) as geoprocessing tools: run by the optional `geolibre` program natively, by geolibre-rust's WASI runner in the browser | | L3 | `rustgis-plugins` | [Plugins](plugins.md): sandboxed WebAssembly modules, desktop process plugins and assistant skills packages; `.rgplugin` packages and the plugin registry | | L4 | `rustgis-engine` | Session, undo, command registry, projects, sample project | | L5 | `rustgis-assistant` | The [AI Assistant](user-guide/assistant.md): provider request/response formats, conversation loop, command tools, skills and agent integration; native HTTP transport and local agent/MCP connections, with browser I/O supplied by the web app | | L6 | `rustgis-ui-egui` | Ribbon, panes, map view, dialogs and the optional wgpu map backend | -| apps | `rustgis`, `rustgis-cli`, `rustgis-web`, `rustgis-python` | Desktop app, command line, browser (WebAssembly), and the PyO3-backed `rustgis` Python package | +| L7 | `rustgis-ui-touch` | Touch interface for phones and tablets built around `rustgis-ui-egui`'s map view | +| apps | `rustgis`, `rustgis-cli`, `rustgis-web`, `rustgis-python`, `rustgis-mobile` | Desktop app, command line, browser (WebAssembly), the PyO3-backed `rustgis` Python package, and the Android/iOS mobile app | | tooling | `xtask` | Workspace checks, third-party licence notices and web service-worker generation | ## Everything is a command @@ -175,7 +177,7 @@ model listing. ## Quality gates ```sh -cargo xtask ci # fmt, clippy -D warnings, tests, layering check +cargo xtask ci # test-hygiene, fmt, clippy -D warnings, tests, layers, attribution, rows, schema --check ``` `cargo xtask layers` checks that workspace dependencies point to lower layers and that crates From 5cfd53dbb60aab2a34804792ffd66b9761e7cbc6 Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 08:22:09 -0500 Subject: [PATCH 02/14] Address review feedback - Add `queue: max` to `.github/workflows/automerge.yml` concurrency so a later `labeled` run cannot replace a pending `unlabeled` revoke run. - Clarify the `Peak memory` step comment in `.github/workflows/test-rust.yml` to match the fresh rebuild behavior on xtask-only runs. --- .github/workflows/automerge.yml | 7 ++++--- .github/workflows/test-rust.yml | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 36c1345a28..99d21c47c9 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -16,11 +16,12 @@ on: permissions: {} -# Serialize `automerge` label/unlabel events in one group so adding and quickly removing the label -# cannot race; keep `synchronize` and unrelated labels in separate groups so they cannot replace a -# pending revoke run. +# Serialize `automerge` label/unlabel events in one FIFO queue so adding, removing, and re-adding +# the label cannot race or replace a pending revoke run; keep `synchronize` and unrelated labels in +# separate groups. concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.action == 'synchronize' && 'synchronize' || (github.event.label.name == 'automerge' && 'label' || 'other') }} + queue: max jobs: enable: diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 0ba445498e..463037f402 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -160,7 +160,8 @@ jobs: # xtask/memory-limits.txt (xtask/src/memory.rs). On Linux (GNU time), when the tests cover # rustgis-cli (as they do whenever a package it uses changes) or xtask itself (such as # changes to memory-limits.txt or memory.rs). Reuses the rustgis-cli binary nextest built - # when present, building it only when xtask ran without rustgis-cli. + # when the tests cover it. Otherwise (such as an xtask-only run) it builds rustgis-cli again, + # since a cached binary may be stale. - name: Peak memory if: matrix.os == 'ubuntu-latest' && (inputs.packages == '--workspace' || contains(format('{0} ', inputs.packages), '-p rustgis-cli ') || contains(format('{0} ', inputs.packages), '-p xtask ')) shell: bash From ff6e2ce3e96e85d3b7cb456c9ed5530e90befd7a Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 08:41:37 -0500 Subject: [PATCH 03/14] Address review feedback - Mark automerge-posted approvals with body "Approved via automerge." and restrict dismissal on unlabeled to matching reviews so manual approvals are preserved. - Re-check current label state in revoke on unlabeled so a stale unlabeled run does not undo a newer re-added automerge label. --- .github/workflows/automerge.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 99d21c47c9..616d7ae0c7 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -61,7 +61,7 @@ jobs: # The token owner can't approve their own pull requests, and needn't: they bypass the review. if [ "$AUTHOR" != "$owner" ]; then gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews" -f commit_id="$SHA" -f event=APPROVE \ - --silent || { gh pr merge "$PR" --disable-auto; exit 1; } + -f body="Approved via automerge." --silent || { gh pr merge "$PR" --disable-auto; exit 1; } fi revoke: @@ -78,13 +78,20 @@ jobs: ACTION: ${{ github.event.action }} run: | set -euo pipefail + if [ "$ACTION" = unlabeled ]; then + has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') + if [ "$has_label" = true ]; then + echo "automerge label was re-added before revoking; skipping." + exit 0 + fi + fi gh pr merge "$PR" --disable-auto || echo "Auto-merge was off." if [ "$ACTION" = synchronize ]; then gh pr edit "$PR" --remove-label automerge elif [ "$ACTION" = unlabeled ]; then owner=$(gh api user --jq .login) gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ - | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED") | .id' \ + | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id' \ | while read -r review_id; do [ -n "$review_id" ] || continue gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ From 52104199bcc15d2775a011f61afc1840892f81df Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 09:04:48 -0500 Subject: [PATCH 04/14] Address Claude review feedback - Always execute revocation on unlabeled in automerge.yml instead of skipping when the label is present, so an unauthorized re-label cannot block revoking auto-merge and dismissing the approval. --- .github/workflows/automerge.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 616d7ae0c7..ea84bf8aa2 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -78,13 +78,6 @@ jobs: ACTION: ${{ github.event.action }} run: | set -euo pipefail - if [ "$ACTION" = unlabeled ]; then - has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') - if [ "$has_label" = true ]; then - echo "automerge label was re-added before revoking; skipping." - exit 0 - fi - fi gh pr merge "$PR" --disable-auto || echo "Auto-merge was off." if [ "$ACTION" = synchronize ]; then gh pr edit "$PR" --remove-label automerge From 73e800f00e944bf5fbd6961fd956e360b0f9ef3a Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 09:25:47 -0500 Subject: [PATCH 05/14] Address Claude review feedback - Clarify in the automerge.yml header comment that only approvals marked by this workflow are dismissed on unlabeled, leaving manual approvals and older unmarked approvals untouched. --- .github/workflows/automerge.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index ea84bf8aa2..f3e2c240cb 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -3,7 +3,9 @@ name: Auto-merge # A maintainer labels a pull request `automerge`: it's approved and joins the merge queue as soon # as the checks the `main` ruleset requires pass; the queue squash-merges it once its checks pass # on top of main. A later push drops the label and turns auto-merge off, -# so new commits need another look; removing the label turns it off and dismisses the approval too. +# so new commits need another look; removing the label turns it off and dismisses the approval +# automerge posted (manual approvals and approvals created before this workflow marks them are +# left untouched). # # `pull_request_target` so fork pull requests get the token; the pull request's code is never # checked out or run. The token is a maintainer's (`AUTOMERGE_TOKEN`), not GITHUB_TOKEN: Actions From bc030a5fa822c3f99c7616f2fb86fe9fc2db0f1f Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 17:32:51 -0500 Subject: [PATCH 06/14] Drop permissions blocks duplicated by the main merge Main already sets contents: read on ci-label.yml and python.yml. --- .github/workflows/ci-label.yml | 3 --- .github/workflows/python.yml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/ci-label.yml b/.github/workflows/ci-label.yml index 434934b9a6..3a9eb5e892 100644 --- a/.github/workflows/ci-label.yml +++ b/.github/workflows/ci-label.yml @@ -16,9 +16,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.label.name }} cancel-in-progress: true -permissions: - contents: read - jobs: cancel: name: Cancel label CI diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 365749577b..1174ad90d8 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -34,9 +34,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}-${{ github.event_name != 'pull_request' && github.run_id || 'pr' }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} -permissions: - contents: read - env: CARGO_TERM_COLOR: always From eb651f8295643c36198f760206daf33f5dcc78e6 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 18:02:08 -0500 Subject: [PATCH 07/14] Attempt every automerge dismissal before failing the revoke step --- .github/workflows/automerge.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index f3e2c240cb..aa1c58c4d2 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -85,11 +85,13 @@ jobs: gh pr edit "$PR" --remove-label automerge elif [ "$ACTION" = unlabeled ]; then owner=$(gh api user --jq .login) - gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ - | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id' \ - | while read -r review_id; do - [ -n "$review_id" ] || continue - gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ - -f message="Automerge label removed" --silent - done + ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ + | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id') + # Try every dismissal even if one fails, then fail the step if any did. + failed=0 + for review_id in $ids; do + gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ + -f message="Automerge label removed" --silent || failed=1 + done + exit "$failed" fi From 1b11fb91afb058eb7267a117c49ac49ee1c912ac Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 18:28:36 -0500 Subject: [PATCH 08/14] Revoke only when the label is gone, and fail when disabling auto-merge fails --- .github/workflows/automerge.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index aa1c58c4d2..5a80a9bbed 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -80,7 +80,21 @@ jobs: ACTION: ${{ github.event.action }} run: | set -euo pipefail - gh pr merge "$PR" --disable-auto || echo "Auto-merge was off." + # A quick remove and re-add can run this after the new enable run: leave that one alone. + if [ "$ACTION" = unlabeled ]; then + has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') + if [ "$has_label" = true ]; then + echo "automerge label is present again; skipping revoke." + exit 0 + fi + fi + # Disable only when armed, so a real failure (token, API, network) fails the step. + armed=$(gh pr view "$PR" --json autoMergeRequest --jq '.autoMergeRequest != null') + if [ "$armed" = true ]; then + gh pr merge "$PR" --disable-auto + else + echo "Auto-merge was off." + fi if [ "$ACTION" = synchronize ]; then gh pr edit "$PR" --remove-label automerge elif [ "$ACTION" = unlabeled ]; then From 86e6ae0339eab1ce06750be07613cbf990ded7df Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 18:55:06 -0500 Subject: [PATCH 09/14] Always revoke on unlabel and attempt every revoke step before failing --- .github/workflows/automerge.yml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 5a80a9bbed..9e22fce504 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -80,32 +80,26 @@ jobs: ACTION: ${{ github.event.action }} run: | set -euo pipefail - # A quick remove and re-add can run this after the new enable run: leave that one alone. - if [ "$ACTION" = unlabeled ]; then - has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') - if [ "$has_label" = true ]; then - echo "automerge label is present again; skipping revoke." - exit 0 - fi - fi - # Disable only when armed, so a real failure (token, API, network) fails the step. - armed=$(gh pr view "$PR" --json autoMergeRequest --jq '.autoMergeRequest != null') - if [ "$armed" = true ]; then - gh pr merge "$PR" --disable-auto + # An unlabeled event always revokes: an authorized re-add's enable run waits behind this + # one in the label queue and arms again. Each step is attempted even if an earlier one + # fails, and the step fails at the end if any did. + failed=0 + # Disable only when armed (or when that can't be read), so a real failure is reported. + armed=$(gh pr view "$PR" --json autoMergeRequest --jq '.autoMergeRequest != null') || armed=unknown + if [ "$armed" != false ]; then + gh pr merge "$PR" --disable-auto || failed=1 else echo "Auto-merge was off." fi if [ "$ACTION" = synchronize ]; then - gh pr edit "$PR" --remove-label automerge + gh pr edit "$PR" --remove-label automerge || failed=1 elif [ "$ACTION" = unlabeled ]; then owner=$(gh api user --jq .login) ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id') - # Try every dismissal even if one fails, then fail the step if any did. - failed=0 for review_id in $ids; do gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ -f message="Automerge label removed" --silent || failed=1 done - exit "$failed" fi + exit "$failed" From a09d5f63675d59fe9f32dc8257073511e4559dc8 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 18:59:38 -0500 Subject: [PATCH 10/14] Count a failed reviews read as a revoke failure instead of stopping the step --- .github/workflows/automerge.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 9e22fce504..cf73daed6c 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -94,12 +94,15 @@ jobs: if [ "$ACTION" = synchronize ]; then gh pr edit "$PR" --remove-label automerge || failed=1 elif [ "$ACTION" = unlabeled ]; then - owner=$(gh api user --jq .login) - ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ - | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id') - for review_id in $ids; do - gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ - -f message="Automerge label removed" --silent || failed=1 - done + # Reads in an if condition, where set -e doesn't stop the step; a failed read counts. + if owner=$(gh api user --jq .login) && ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ + | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id'); then + for review_id in $ids; do + gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ + -f message="Automerge label removed" --silent || failed=1 + done + else + failed=1 + fi fi exit "$failed" From 17930f638334668fb8be7e447dadaf55bd9d18ee Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 19:27:31 -0500 Subject: [PATCH 11/14] Dismiss automerge approvals on push too, not only through the unlabel run --- .github/workflows/automerge.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index cf73daed6c..29a1ba54c4 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -93,16 +93,16 @@ jobs: fi if [ "$ACTION" = synchronize ]; then gh pr edit "$PR" --remove-label automerge || failed=1 - elif [ "$ACTION" = unlabeled ]; then - # Reads in an if condition, where set -e doesn't stop the step; a failed read counts. - if owner=$(gh api user --jq .login) && ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ - | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id'); then - for review_id in $ids; do - gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ - -f message="Automerge label removed" --silent || failed=1 - done - else - failed=1 - fi + fi + # Dismiss on both actions, so a push doesn't depend on the label removal succeeding. + # Reads in an if condition, where set -e doesn't stop the step; a failed read counts. + if owner=$(gh api user --jq .login) && ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ + | jq -r --arg owner "$owner" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id'); then + for review_id in $ids; do + gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ + -f message="Automerge label removed" --silent || failed=1 + done + else + failed=1 fi exit "$failed" From 97654eea9413fbd1f29dfc84287fc227c5ae8d86 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 19:54:28 -0500 Subject: [PATCH 12/14] Revoke checks the label as it is now; enable takes a refused label off GitHub doesn't guarantee the order of queued label runs, so the revoke skips while the label is present, and the enable run removes a label it refuses, which starts a revoke that finds it gone. --- .github/workflows/automerge.yml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 29a1ba54c4..cc960463ad 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -18,9 +18,9 @@ on: permissions: {} -# Serialize `automerge` label/unlabel events in one FIFO queue so adding, removing, and re-adding -# the label cannot race or replace a pending revoke run; keep `synchronize` and unrelated labels in -# separate groups. +# `automerge` label and unlabel runs share a queue, so a pending revoke run isn't replaced; GitHub +# doesn't guarantee their order, so each run checks the label as it is now rather than relying on +# it. `synchronize` and unrelated labels get their own groups. concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }}-${{ github.event.action == 'synchronize' && 'synchronize' || (github.event.label.name == 'automerge' && 'label' || 'other') }} queue: max @@ -40,16 +40,23 @@ jobs: AUTHOR: ${{ github.event.pull_request.user.login }} run: | set -euo pipefail + # A refused label is taken off: the unlabel run that follows finds it gone and revokes + # whatever an earlier, authorized label armed, whichever order the runs go in. + refuse() { + echo "::error::$1" + gh pr edit "$PR" --remove-label automerge || true + exit 1 + } # Triage can label too: only someone who could merge it themselves may use the label. perm=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$SENDER/permission" --jq .permission) case "$perm" in admin|maintain|write) ;; - *) echo "::error::$SENDER ($perm) can't use automerge."; exit 1 ;; + *) refuse "$SENDER ($perm) can't use automerge." ;; esac owner=$(gh api user --jq .login) # The approval stands in for someone else's review, so it isn't for the labeller's own work. if [ "$SENDER" = "$AUTHOR" ] && [ "$AUTHOR" != "$owner" ]; then - echo "::error::$SENDER can't use automerge on their own pull request."; exit 1 + refuse "$SENDER can't use automerge on their own pull request." fi # Re-verify the label is still present in case it was removed before this run started. has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') @@ -80,9 +87,17 @@ jobs: ACTION: ${{ github.event.action }} run: | set -euo pipefail - # An unlabeled event always revokes: an authorized re-add's enable run waits behind this - # one in the label queue and arms again. Each step is attempted even if an earlier one - # fails, and the step fails at the end if any did. + # The label is back: a re-add's enable run may already have armed it, and a refused + # re-add's run takes the label off again, which starts another revoke. Each step below is + # attempted even if an earlier one fails, and the step fails at the end if any did. + if [ "$ACTION" = unlabeled ]; then + has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') \ + || has_label=unknown + if [ "$has_label" = true ]; then + echo "automerge label is present again; skipping revoke." + exit 0 + fi + fi failed=0 # Disable only when armed (or when that can't be read), so a real failure is reported. armed=$(gh pr view "$PR" --json autoMergeRequest --jq '.autoMergeRequest != null') || armed=unknown From c6ee3cc00bebc57e915b0a1c0d9b6382e0887017 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 20:21:07 -0500 Subject: [PATCH 13/14] A refused automerge label revokes in its own run --- .github/workflows/automerge.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index cc960463ad..dd71c9780e 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -40,10 +40,19 @@ jobs: AUTHOR: ${{ github.event.pull_request.user.login }} run: | set -euo pipefail - # A refused label is taken off: the unlabel run that follows finds it gone and revokes - # whatever an earlier, authorized label armed, whichever order the runs go in. + # A refused label revokes whatever an earlier, authorized label armed, here rather than + # through the unlabel run, so it holds even if taking the label off fails. The step fails + # anyway, so each call is attempted and its own failure ignored. refuse() { echo "::error::$1" + gh pr merge "$PR" --disable-auto || true + if me=$(gh api user --jq .login) && ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews?per_page=100" \ + | jq -r --arg owner "$me" '.[] | select((.user.login // "") == $owner and .state == "APPROVED" and (.body // "") == "Approved via automerge.") | .id'); then + for review_id in $ids; do + gh api -X PUT "repos/$GITHUB_REPOSITORY/pulls/$NUMBER/reviews/$review_id/dismissals" \ + -f message="automerge label refused" --silent || true + done + fi gh pr edit "$PR" --remove-label automerge || true exit 1 } @@ -88,7 +97,7 @@ jobs: run: | set -euo pipefail # The label is back: a re-add's enable run may already have armed it, and a refused - # re-add's run takes the label off again, which starts another revoke. Each step below is + # re-add's run revokes by itself. Each step below is # attempted even if an earlier one fails, and the step fails at the end if any did. if [ "$ACTION" = unlabeled ]; then has_label=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq 'any(.labels[]; .name == "automerge")') \ From d172cb77601d4bbfb04991c0bea6ce32bca58921 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 28 Nov 2026 20:47:57 -0500 Subject: [PATCH 14/14] Refuse the label when the labeller's permission can't be read --- .github/workflows/automerge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index dd71c9780e..c523ee1331 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -57,7 +57,7 @@ jobs: exit 1 } # Triage can label too: only someone who could merge it themselves may use the label. - perm=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$SENDER/permission" --jq .permission) + perm=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$SENDER/permission" --jq .permission) || perm=unknown case "$perm" in admin|maintain|write) ;; *) refuse "$SENDER ($perm) can't use automerge." ;;