Skip to content

fix(ci): replace per-repo inline auto-merge engine with single reusable workflow - #14

Merged
github-actions[bot] merged 5 commits into
mainfrom
feat/auto-merge-reusable
Aug 21, 2026
Merged

github-actions[bot] merged 5 commits into
mainfrom
feat/auto-merge-reusable

Conversation

@atrawog

@atrawog atrawog commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

fix(ci): replace the per-repo inline auto-merge engine with a single reusable workflow

The change

The org-wide auto-merge engine previously existed as a 353-line inline run: block
in .github/workflows/auto-merge.yml, copy-pasted identically into all 14 opencharly
repos. This PR replaces that pattern with a single reusable workflow
(.github/workflows/auto-merge-reusable.yml, workflow_call) called by a ~20-line
dispatcher in each target repo.

The engine itself is rewritten to use proper GitHub Action mechanisms:

  • actions/github-script@v7 (Octokit) for ALL GitHub API interactions — finding
    the PR, checking state, updating the body, listing check-runs, creating tags.
    No raw gh api calls, no fragile JSON-grep pipelines.
  • github.graphql (GraphQL mutation enablePullRequestAutoMerge) to enable
    native auto-merge instead of the gh CLI --auto flag.
  • actions.createWorkflowDispatch to trigger the validator on the finalized
    head, replacing the fragile "find the action_required run and re-run it" dance.
  • Native auto-merge delegates ALL check-waiting to GitHub — the engine no longer
    polls check-runs in bash; GitHub's native auto-merge waits for every required status check.

Bugs fixed in the engine:

  1. Body-append ordering — the finalization note is now inserted BEFORE the
    ## Attribution section, so the Assisted-by: attribution footer remains
    the last line in the PR body (A1 compliance).
  2. Already-finalized guard — the marker check uses the file's own basename
    stamp (prose cannot collide with it).

New file structure:

File Purpose
.github/workflows/auto-merge-reusable.yml The canonical engine — ONE file for the whole org
.github/workflows/auto-merge.yml Dispatcher for this repo (calls the reusable engine)
org-wide-auto-merge-dispatcher.yml Template file to install in every other target repo
.github/workflows/pr-validator.yml Now supports workflow_call (for the same dispatcher pattern)

Deleted: .github/scripts/auto-merge-harness.sh, .github/scripts/auto-merge-runblock.sh
— no longer needed; the engine has no de-templated copy.

Change class

CI/workflow — workflow definitions (auto-merge-reusable.yml, auto-merge.yml,
pr-validator.yml), the dispatcher template, and one CHANGELOG entry. No code,
no candies, no runtime packaging.

How tested

  • The new engine uses the same CHANGELOG finalization logic (git mv + sed H1 rewrite
    • marker) that has been proven live on distro-arch#17 and charly#363.
  • The Octokit-based tag creation mirrors the exact tag scheme (normal repos:
    v<YYYY.DDD.HHMM>; SDK: v0.<YYYYDDD>.<HHMM stripped>).
  • This PR's own landing is the live proof: the old inline engine (still on main)
    processes this PR through the existing auto-merge workflow. Once merged, all future
    PRs use the new reusable engine.
  • The closed-PR path (tag-only, no finalization, no auto-merge) is guarded by
    if: steps.pr.outputs.state == 'open' on every subsequent step, so a merged
    PR that arrives via the workflow_run trigger is safely tagged without attempting
    auto-merge.

Project-rulebook compliance

  • R1/R10 — the mis-tag and body-append issues from the prior canary were
    root-caused in the engine rewrite; the new engine removes the fragile re-run
    dance entirely by using native auto-merge. The gate for this change-class
    (CI/workflow) is the engine's own landing through the existing auto-merge.
  • R2 — one coherent change: replace inline engine with reusable, update
    pr-validator, clean up old scripts.
  • R3 — no duplication: one reusable engine instead of 14 copies.
  • R4 — no workaround: uses proper GitHub mechanisms (Octokit, GraphQL,
    native auto-merge) instead of bash polling.
  • R5 — old .github/scripts/auto-merge-*.sh deleted; no stale references.
  • R6 — no force-push; the branch accumulates author commits, then the engine
    squash-merges.
  • R8 — N/A: no generated artifacts changed.
  • R9 — N/A: no binary produced.

Attribution

Assisted-by: pi ollama-cloud deepseek-v4-flash:preview (analysed on a live system)

Auto-merge finalization

This run finalized the CHANGELOG at merge time: the placeholder was
renamed to CHANGELOG/2026.233.0511.md (H1 rewritten to # 2026.233.0511). The current diff
carries the finalized file.

…reusable workflow

BREAKING CHANGE: every opencharly repo must install the new dispatcher
at .github/workflows/auto-merge.yml (org-wide-auto-merge-dispatcher.yml).

The org-wide auto-merge engine now lives in ONE reusable workflow
(.github/workflows/auto-merge-reusable.yml, workflow_call) and is called
by a ~20-line dispatcher in each target repo.

Changes:
- .github/workflows/auto-merge-reusable.yml — THE canonical engine
- .github/workflows/auto-merge.yml — dispatcher for .github repo itself
- org-wide-auto-merge-dispatcher.yml — template for other repos
- .github/workflows/pr-validator.yml — added workflow_call support
- .github/scripts/auto-merge-*.sh — deleted (no more de-templated copy)

Engine improvements:
- Octokit for all API calls (no raw gh api, no fragile bash grep)
- GraphQL enablePullRequestAutoMerge mutation for native auto-merge
- createWorkflowDispatch for validator re-trigger (no re-run dance)
- Finalization note inserted BEFORE ## Attribution (preserves footer)
- All checks-waiting delegated to GitHub native auto-merge
@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: 4f1e53ee89b4c7ecd5cd6ad5bef07d7dd5516af6 (branch: fix/ci-reusable-auto-merge)

Change class: CI/workflow — replaces the per-repo inline auto-merge engine with a single reusable workflow_call engine, updates pr-validator.yml, deletes the old harness scripts.

Security screen: PASS — no new secrets, no exfiltration, no scope mismatch, no weakened credential handling. The engine's reliance on native auto-merge (which waits for required checks) instead of the old verify_all_green bash check is a behavioral change but not a verifiable gate weakening from the diff alone.

Blocks

  1. B19 — CHANGELOG missing. The diff contains no CHANGELOG/ entry (6 files changed: 2 deleted scripts, 2 modified workflows, 2 added workflow files — none under CHANGELOG/). Every PR must include a CHANGELOG entry. Add one.

  2. A1 — description↔code mismatch. The body's change class claims "CI/workflow — workflow definitions and one CHANGELOG entry", but the diff contains no CHANGELOG file. The body's accounting does not match the diff. Either add the CHANGELOG entry or correct the body.

  3. R10 misclassification (forbidden framing). The body states "R10 — documentation-only change class (workflow definitions)". Workflow definitions are config, not documentation — this is the banned "it's just a documentation change" framing used to skip the change-class gate. The change class is CI/workflow, not docs-only; the R10 claim must be corrected to name the actual gate (the engine's own landing) without the false "documentation-only" label.

Verdict: BLOCK


openrouter/deepseek/deepseek-v4-flash-0731 — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: a956b0bf94e0f08d9a0da7c6a9cb361f77313d7d (branch: fix/ci-reusable-auto-merge)

Change class: CI/workflow — replaces the per-repo inline auto-merge engine with a single reusable workflow_call engine, updates pr-validator.yml, deletes the old harness scripts, adds one CHANGELOG entry.

Security screen: PASS — no new secrets, no exfiltration, no scope mismatch, no weakened credential handling. GITHUB_TOKEN is passed via secrets: inherit (standard).

Blocks

  1. A2/R10 — forbidden "documentation-only" framing. The body's R10 line still claims "R10 — documentation-only change class (workflow definitions)". Workflow YAML is config, not documentation — this is the banned "it's just a documentation change" framing used to skip the change-class gate. The body's own change-class line correctly says "CI/workflow — workflow definitions and one CHANGELOG entry", so the R10 claim is internally contradictory and misclassified. Correct the R10 entry to name the actual gate (the engine's own landing) without the false "documentation-only" label.

  2. B16/defect — Step 8 "Enable auto-merge" has no if: guard, breaking the already-closed PR path. In .github/workflows/auto-merge-reusable.yml, Steps 2–7 are all guarded by if: steps.pr.outputs.state == 'open' (or 'closed'), but Step 8 (🚀 Enable auto-merge) runs unconditionally. For an already-merged/closed PR, Step 1 sets only state/merge_sha/merge_date — it never sets node_id or number — so Step 8 calls enablePullRequestAutoMerge with an undefined id and fails the job. The old inline engine handled this path with an explicit exit 0 after idempotent tagging; the reusable rewrite loses that and would fail on the closed-PR race. Add the if: steps.pr.outputs.state == 'open' guard to Step 8 (and confirm Step 9's closed-path handling).

Dispositions of prior comments

  • github-actions[bot] BLOCK (head 4f1e53ee89b4): findings B19 (CHANGELOG missing) and A1 (description↔code mismatch) are stale-superseded — the current head adds CHANGELOG/2026.233.0453.md (valid CalVer filename, H1 # 2026.233.0453 — Unified auto-merge engine matches). Finding R10 misclassification is verified-blocking — it reproduces against the current body.

Verdict: BLOCK


openrouter/deepseek/deepseek-v4-flash-0731 — pi-review-action.

View action run

The validator caught that Steps 8 (Enable auto-merge) and 9 (Wait for
merge and tag) ran unconditionally.  For an already-merged PR that
arrives via workflow_run, Step 2 handles the tag and the engine should
stop — not attempt auto-merge on a closed PR with no node_id/number set.
@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: 7651a59400bc238f4655b8e6e2a12f830c13c173 (branch: fix/ci-reusable-auto-merge)

Change class: CI/workflow — replaces the per-repo inline auto-merge engine with a single reusable workflow_call engine, updates pr-validator.yml, deletes the old harness scripts, adds one CHANGELOG entry.

Security screen: PASS — no new secrets, no exfiltration, no scope mismatch, no weakened credential handling. GITHUB_TOKEN via secrets: inherit is standard. The shift from the old verify_all_green bash check to native auto-merge is a behavioral change, but the primary gate (the engine only fires on workflow_run.conclusion == 'success' from the validator) is preserved; whether native auto-merge waits for the validator depends on branch-protection config not visible in the diff, so I do not block on it.

Blocks

  1. R5 — stale/false comment survived the cutover. In the new .github/workflows/auto-merge-reusable.yml (lines 5–6), the header comment reads:
    # Canonical source: opencharly/.github/.github/workflows/auto-merge.yml
    # Install the dispatcher: opencharly/.github/org-wide-auto-merge-dispatcher.yml
    
    This is factually wrong: auto-merge.yml is now the dispatcher (it uses: the reusable engine), not the canonical source. The canonical engine is auto-merge-reusable.yml itself. This is a false/outdated claim that survived the cutover — exactly what R5 requires sweeping in the same commit, and a comment divergence from reality (B5). Fix the comment to name the correct canonical source (or drop the line).

Dispositions of prior comments

  • github-actions[bot] BLOCK (head 4f1e53ee89b4): B19 (CHANGELOG missing) and A1 (description↔code mismatch) — stale-superseded: current head adds CHANGELOG/2026.233.0453.md (valid CalVer filename, H1 # 2026.233.0453 — Unified auto-merge engine matches) and the body now accounts for every diff file. R10 misclassification — stale-superseded: the current body's R10 line no longer claims "documentation-only"; it names the CI/workflow gate.
  • gpu-actions[bot] BLOCK (head a956b0bf94e0): A2/R10 framing — stale-superseded (same as above). B16 Step 8 guard — verified-non-blocking: the current head's commit 7651a59400bc adds if: steps.pr.outputs.state == 'open' to both Step 8 (🚀 Enable auto-merge) and Step 9 (⏳ Wait for merge and tag), so the closed-PR path tags and exits without touching node_id/number. Fixed.

Verdict: BLOCK


openrouter/deepseek/deepseek-v4-flash-0731 — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 334d3781b8718f48d660113727dc2a187c5eebb0 (branch: fix/ci-reusable-auto-merge)

Security screen: PASS — no new secrets, no exfiltration, no scope mismatch, no weakened guardrails. GITHUB_TOKEN via secrets: inherit is standard; the shift from bash verify_all_green to native auto-merge preserves the primary gate (engine only fires on validator conclusion == 'success').

Checklist: All applicable rules PASS or NA.

  • B19 — CHANGELOG/2026.233.0453.md present; filename matches ^\d{4}\.\d{3}\.\d{4}\.md$, H1 # 2026.233.0453 — Unified auto-merge engine matches.
  • A1/A2/A3 — body accounts for every diff file (new reusable engine, dispatcher, dispatcher template, pr-validator workflow_call, deleted scripts, CHANGELOG); change class correctly named CI/workflow (no banned "documentation-only" framing); attribution analysed on a live system is honest and non-inflated for a self-gating change; Assisted-by: footer present at end.
  • R5 — stale header comment fixed in the current head (reusable engine now correctly names itself canonical source and auto-merge.yml as dispatcher); old scripts deleted.
  • B16 — Steps 8/9 guarded with if: steps.pr.outputs.state == 'open', so the closed-PR path tags and exits without touching node_id/number.
  • R3/R4/R2/R6/R8/R9 — no duplication (removes 14 copies), proper GitHub mechanisms, no force-push, no generated artifacts/binary (N/A).
  • RDD/ADE/SDD — N/A (no candies, no CUE/schema, no Go).
  • Architecture gate — placement CORRECT: reusable engine lives in the org .github repo, called via workflow_call; no core/sdk/candy layer involved.
  • Self-gating — this PR modifies the auto-merge engine that gates its own merge; end-to-end proof is unobservable pre-merge (rule 3). Mechanism verified statically and is sound.

Prior reviewer findings all resolved in the current head: B19/A1 (CHANGELOG added, body corrected), R10 misclassification (corrected), B16 Step 8 guard (added), R5 stale comment (fixed).

Verdict: PASS


openrouter/deepseek/deepseek-v4-flash-0731 — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: d171d7e3fb78 (branch: fix/ci-reusable-auto-merge)

Security screen: PASS — no new secrets, no exfiltration, no scope mismatch, no weakened credential handling. GITHUB_TOKEN via secrets: inherit is standard. The shift from the old bash verify_all_green to native auto-merge preserves the primary gate (the engine only fires on validator conclusion == 'success'); whether native auto-merge additionally waits for the validator depends on branch-protection config not visible in the diff, so I do not block on it.

Checklist: All applicable rules PASS or NA.

  • B19 — CHANGELOG/2026.233.0511.md present; filename matches ^\d{4}\.\d{3}\.\d{4}\.md$, H1 # 2026.233.0511 — Unified auto-merge engine matches.
  • A1/A2/A3 — body accounts for every diff file (reusable engine, dispatcher, dispatcher template, pr-validator workflow_call, deleted scripts, CHANGELOG); change class correctly named CI/workflow (no banned "documentation-only" framing); attribution analysed on a live system is honest and non-inflated for a self-gating change.
  • R5 — stale header comment fixed in the current head (reusable engine correctly names itself canonical source and auto-merge.yml as dispatcher); old scripts deleted.
  • B16 — Steps 8/9 guarded with if: steps.pr.outputs.state == 'open', so the closed-PR path tags and exits without touching node_id/number.
  • R3/R4/R2/R6/R8/R9 — no duplication (removes 14 copies), proper GitHub mechanisms, no force-push, no generated artifacts/binary (N/A).
  • RDD/ADE/SDD — N/A (no candies, no CUE/schema, no Go).
  • Architecture gate — placement CORRECT: reusable engine lives in the org .github repo, called via workflow_call; no core/sdk/candy layer involved.
  • Self-gating — this PR modifies the auto-merge engine that gates its own merge; end-to-end proof is unobservable pre-merge (rule 3). Mechanism verified statically and is sound.

Prior reviewer findings all resolved in the current head: B19/A1 (CHANGELOG added, body corrected), R10 misclassification (corrected), B16 Step 8 guard (added), R5 stale comment (fixed).

Verdict: PASS


openrouter/deepseek/deepseek-v4-flash-0731 — pi-review-action.

View action run

@github-actions
github-actions Bot merged commit 71041ec into main Aug 21, 2026
1 check passed
@aitrawog
aitrawog deleted the feat/auto-merge-reusable branch September 25, 2026 19:08
charly-auto-merge Bot added a commit that referenced this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants