Skip to content

ci: gate Dependabot auto-merge on full CI and breaking/danger checks - #28

Merged
Schero94 merged 2 commits into
mainfrom
ci/dependency-gate-v2
Nov 19, 2026
Merged

Schero94 merged 2 commits into
mainfrom
ci/dependency-gate-v2

Conversation

@Schero94

Copy link
Copy Markdown
Owner

Dependency auto-merge, version 2

Dependabot updates are merged automatically only when nothing dangerous or breaking is in them, and only after the full CI is green on the PR head commit. Identical logic in all eight plugin repositories: .github/scripts/ is byte-identical, and so is everything in dependency-auto-merge.yml except this repository's own verify job and the NPM_CI_FLAGS value.

What changes

  • .github/scripts/dependency-gate.mjs: dependency-free gate script (subcommands policy, surface, decide, route, wait-ci, review-changes), with dependency-gate.test.mjs (24 node --test tests, fixture lockfiles in fixtures/) and a local .prettierrc.json so the same bytes pass Prettier in every repository.
  • .github/workflows/dependency-auto-merge.yml: the verify job is unchanged (except that the actor must also be dependabot[bot]); new jobs surface, gate and merge.
  • CI (ci.yml / test.yml): new step "Dependency gate unit tests".
  • Docs: a "Dependency updates and the auto-merge gate" section.

Merge mechanism: wait for every check on the head commit, then merge that exact commit

The merge job polls the REST API for the head SHA (workflow runs, check runs, commit statuses), excludes this workflow's own runs, takes the latest run per workflow and event, and needs two green polls in a row (timeout 75 minutes). Then it runs gh pr merge --squash --delete-branch --match-head-commit <sha>, so a newer push can never be merged unverified. A failing check, or a timeout, holds the PR.

Why not workflow_run: it fires once per finished workflow, so the merge decision would have to be rebuilt from several events. It runs the default-branch file with a write token and finds the PR only through the head SHA or an artifact from the PR run (the pattern GitHub warns about), and the decision would no longer be tied to the same run as the gate. Polling inside the same run keeps gate, wait and merge bound to one head SHA. The cost is one runner that waits while CI runs.

Hold reasons (label needs-review and a comment, never merged)

Breaking-change guard:

  • engines: a changed package's engines.node (lockfile and, for direct dependencies, npm view) drops a Node version the plugin's own engines.node supports.
  • peer, peer-floor: new or raised peerDependencies that the installed tree does not satisfy, or (for shipped packages) that exceed the plugin's peer floor.
  • breaking-text: the PR body or release notes mention a breaking change.
  • surface: the published surface differs between merge base and head: npm pack --dry-run file list (chunk hashes normalized), exports/main/files, peerDependencies, engines, static exports of every entry file, runtime export shape of every CommonJS entry.
  • zero-minor: a runtime dependencies entry on 0.x gets a minor bump (or a 0.0.x patch bump).

Danger guard:

  • vulnerability, license, dependency-review: actions/dependency-review-action (v5.0.0, fail-on-severity: moderate, all scopes) plus the same check in the script on the dependency-graph comparison: advisories of moderate or higher, licenses outside the allowlist (MPL-2.0 and CC-BY for development dependencies only; reviewed exceptions for @strapi/*, sharp's LGPL binaries, npm, json-schema, normalize-package-data). The allowlist was checked against all eight current trees.
  • signatures: npm audit signatures fails (missing or invalid registry signatures or provenance attestations).
  • install-script, new-packages, registry, integrity: the lockfile adds a package with hasInstallScript, adds more than 15 package names that are new to the tree, or resolves a changed package outside https://registry.npmjs.org/ or without a sha512 integrity hash.

Also held: verify or gate failed, an empty or unknown Dependabot update-type, failing CI, CI timeout. Majors (Dependabot update-type or a direct dependency major in the lockfile) keep the major-update label and comment as before.

Security

  • The gate script and its inputs come from the default branch (sparse-checkout: .github/scripts), never from the PR.
  • Only the surface job runs PR code (install with --ignore-scripts, then npm run build), with the read-only token and no secrets; its report is parsed as data.
  • The gate job installs with --ignore-scripts only (for npm audit signatures) and holds the token with contents: read.
  • Write permissions (contents, pull-requests) and the read scopes for the CI wait (actions, checks, statuses) are on the merge job only, which checks out no PR code.
  • All actions are pinned by commit SHA. All jobs require pull_request.user.login == 'dependabot[bot]' and github.actor == 'dependabot[bot]', so they are skipped for every other PR (including this one) and for human pushes to a Dependabot branch.

Evidence

Docs read

  • GitHub Actions: events that trigger workflows (pull_request, workflow_run), Dependabot on Actions (read-only token, permissions key), GITHUB_TOKEN permissions, secure use (SHA pinning, untrusted input).
  • dependabot/fetch-metadata v3.1.0 README; actions/dependency-review-action v5.0.0 action.yml, README and src/main.ts, src/licenses.ts, src/purl.ts; actions/upload-artifact v7 and download-artifact v8 READMEs.
  • npm audit signatures (docs and installed npm 10.9.8 source: needs the installed tree, exit 1 on missing or invalid).
  • REST: workflow runs (head_sha), check runs for a ref, combined status, dependency-graph compare; gh pr merge --match-head-commit (gh 2.103.3).

Needs the owner

  • Labels needs-review and major-update were created in the repository.
  • No branch protection on main and allow_auto_merge=false: the gate does not depend on them. Branch protection with required checks would add a second barrier for human merges.

Commit type ci:: no release.

🤖 Generated with Claude Code

Schero94 and others added 2 commits November 20, 2026 00:03
Dependency auto-merge version 2. A Dependabot patch/minor update is merged
only when every other check on the PR head commit is green and the new
dependency gate (.github/scripts/dependency-gate.mjs, byte-identical in all
plugin repositories, dependency-free, 24 node:test tests with fixture
lockfiles) finds nothing breaking or dangerous. Otherwise the PR gets the
needs-review label and a comment with the reasons. Majors keep the
major-update label and are never merged automatically.

- surface job (read-only, runs PR code): builds merge base and head and
  records the npm pack file list, exports, peerDependencies, engines and the
  exports of the built entries.
- gate job (trusted, script from the default branch, data only): engines,
  peerDependencies and peer floor, 0.x runtime minors, breaking-change
  wording, surface diff, dependency-review-action (moderate, license
  allowlist), npm audit signatures, install scripts, >15 new packages,
  non-registry or integrity-less resolutions.
- merge job: waits for all workflow runs, check runs and statuses on the
  head SHA (two green polls, 75 min timeout), then merges with
  --match-head-commit.
- CI runs the gate unit tests; docs describe the gate.

Docs read (2026-11-19): GitHub Actions events (pull_request, workflow_run),
Dependabot on Actions, GITHUB_TOKEN permissions, secure use;
dependabot/fetch-metadata v3.1.0; dependency-review-action v5.0.0 (action.yml,
README, src/main.ts, src/licenses.ts, src/purl.ts); upload-artifact v7,
download-artifact v8; npm audit signatures (docs and npm 10.9.8 source);
REST workflow runs, check runs, combined status, dependency-graph compare;
gh pr merge --match-head-commit (gh 2.103.3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeQL js/incomplete-sanitization flagged replace('@', ...). npm names
carry at most one leading @, so the result was already correct; make
the intent explicit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Schero94
Schero94 merged commit 0f22144 into main Nov 19, 2026
10 checks passed
@Schero94
Schero94 deleted the ci/dependency-gate-v2 branch November 19, 2026 23:32
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.

1 participant