Skip to content

Require a main-only release environment and fail on diverged release tags - #40

Merged
jongio merged 8 commits into
mainfrom
jongio/release-hardening
Nov 20, 2026
Merged

jongio merged 8 commits into
mainfrom
jongio/release-hardening

Conversation

@jongio

@jongio jongio commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #38 addressing review findings that landed after merge:

  • Release environment gate: publish now requires the release environment to use custom branch policies (not "Protected branches only") with exactly one policy, branch:main. The previous deployment_branch_policy != null check also accepted "protected branches", which an org-wide ruleset can make true for every branch.
  • Diverged tags: automatic releases skip only when this commit is an ancestor of the newest version tag. If the tag and main have diverged, the run fails instead of silently skipping. Git errors other than exit 1 are rethrown.

Verification

  • Model-free checks and source-to-bundle verification pass: node --test tooling/release.test.mjs (12 passed); pnpm exec vitest run tests/example.test.ts (8 passed); pnpm lint and oxlint --deny-warnings tooling clean. No src//dist/ changes.
  • Native integration evidence is distinguished from synthetic controls: N/A, tooling and workflow only.
  • Credential, process and artifact boundaries were reviewed: publish permissions unchanged; the new read uses the job token and fails closed.
  • Documentation and packaged dist match source: CONTRIBUTING describes the required environment setting.

Limitations

The release environment doesn't exist yet, so publish fails closed until an admin creates it with the main branch policy. Whether the job token can read deployment branch policies is verified on the first hosted publish run.

…tags

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio
jongio requested a review from a team as a code owner November 19, 2026 22:26
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 22:26
@jongio
jongio requested a review from wbreza November 19, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new release test covers only exit-code mapping, leaving divergence rejection and behind-tag success without CLI regression coverage.

1 open issue
What changed in this PR

Hardens the Action’s release automation by requiring a main-only release environment and failing when the newest release tag has diverged from the target commit.

Changes:

  • Require custom deployment policies with exactly one branch rule: main.
  • Distinguish already-released commits from diverged histories and propagate unexpected Git errors.
  • Update setup documentation and release-related checks.
File Description
tooling/​release.test.mjs Tests ancestry helper results and Git error handling.
tooling/​release.mjs Adds two-way ancestry validation for automatic releases.
tests/​example.test.ts Updates the workflow contract check for the stricter environment policy.
CONTRIBUTING.md Documents the required release environment settings.
.github/​workflows/​release.yml Validates the exact main branch policy before publishing.

Review effort: Max (adaptive)

Comment thread tooling/release.test.mjs Resolved

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary

LGTM — both follow-ups from #38 are cleanly addressed and fail closed:

  • Main-only
    elease environment gate (.github/workflows/release.yml, ests/example.test.ts, CONTRIBUTING.md):
    Requires protected_branches == false, custom_branch_policies == true, and a single �ranch:main deployment branch policy before checkout or any tag/release write. Also confirmed against GitHub's REST API permissions reference that both GET .../environments/{environment_name} and GET .../environments/{environment_name}/deployment-branch-policies are governed by �ctions: read for GITHUB_TOKEN, which publish already declares.
  • Diverged release tags & Git errors ( ooling/release.mjs, ooling/release.test.mjs): isAncestor now treats only exit code 1 as non-ancestry (rethrowing unexpected Git failures), and �utomaticInput fails closed when latest and HEAD have diverged while preserving the skip path when HEAD is an ancestor of latest.

Non-blocking notes (Low)

  • .github/workflows/release.yml:138-140: GET .../environments/release/deployment-branch-policies returns HTTP 404 whenever custom_branch_policies is not rue (including an auto-created environment with deployment_branch_policy: null or Protected branches only). Under �ash -eo pipefail, line 139 still fails closed before any write, but exits with gh: Not Found (HTTP 404) before reaching line 140's ::error:: annotation. Gating the deployment-branch-policies lookup on [ "$policy" = "false true" ] would preserve the explicit ::error:: diagnostic in those cases.
  • ** ooling/release.test.mjs:10-17:** Adding temp-repo CLI assertions for the diverged-tag failure and HEAD-behind-tag skip (already noted inline on the PR) would guard �utomaticInput directly alongside the isAncestor unit check.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio
jongio requested review from a team and wbreza and an adaptive review from Copilot November 19, 2026 23:04

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary (Re-review on 1c4addf)

LGTM — 1c4addf cleanly adds end-to-end temporary-repository CLI coverage in ooling/release.test.mjs for both diverged release tags (failing closed with the expected diagnostic) and a HEAD behind the newest release tag (
elease=false), with commit/tag signing disabled and GITHUB_OUTPUT isolated from the host environment.

All CI checks pass and there are zero Critical, High, or Medium findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The release workflow can exit before reporting invalid branch-policy configurations, and the release script suppresses Git diagnostics for unexpected failures.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Low severity Fetch branch policies only when custom policies are enabled

.github/​workflows/​release.yml:139

When the environment uses No restriction or Protected branches only, this endpoint returns 404 because custom branch policies are disabled. The failing assignment exits the step before the targeted configuration error is printed, leaving operators with only the HTTP error. Fetch branch policies only when $policy is false true so invalid configurations reach the actionable message below.

Low severity Preserve Git stderr for ancestry-check failures

tooling/​release.mjs:81

stdio: 'ignore' discards Git's stderr, so errors rethrown for statuses other than 1 omit the reason for the failure. Pipe stderr so the release job reports Git's diagnostic while still treating exit 1 as a normal ancestry result.

1 resolved since last review

Review effort: Max (adaptive)

@jongio

jongio commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review disposition ledger — body-only findings

Revalidated Copilot reviews 5984552173 and 5984917959 on current head 1c4addf707fa94a259810a798d8a1c6d46add717.

  • Fetch branch policies only when custom policies are enabled (.github/workflows/release.yml:139): The release job reaches this path when the release environment is unrestricted or protected-branches-only. The custom-policy endpoint returns 404, stopping the job before its intended actionable configuration error. Publication still fails closed, but the operator loses the targeted diagnostic. Minimal fix: reject any policy other than false true before querying custom branch policies, then require exactly branch:main.
  • Preserve Git stderr for ancestry-check failures (tooling/release.mjs:81): automaticInput reaches isAncestor during release planning; unexpected Git errors are rethrown, but stdio: 'ignore' discards the underlying diagnostic. Minimal fix: capture stderr for non-exit-1 failures and include it in the surfaced error, with a focused regression assertion.

Both findings are tightly coupled to this PR's release validation. The fixes will preserve the main-only policy and fail-closed release behavior without changing release authorization or accepted inputs.

Disposition on current head 11d2e7d66c7cd54241fbf36022e477f7e415aa4b

  • Reviews 5984552173 and 5984917959, Fetch branch policies only when custom policies are enabled: fixed in 11d2e7d; the workflow rejects an invalid policy before querying the endpoint.
  • Reviews 5984552173 and 5984917959, Preserve Git stderr for ancestry-check failures: fixed in 11d2e7d; non-exit-1 failures now surface stderr, covered by a regression assertion.

Targeted release tests passed (13/13), direct Oxlint passed, build check passed, and git diff --check passed. The new head still needs exact-head reviews before merge.

Re-review disposition (5986273737, revalidated against 17957fee)

Fail closed when a deployment rule’s ref type is missing: the Copilot review says the documented response omits type, but the current official List deployment branch policies response schema lists type as a required branch/tag field (checked 2026-11-20). Independently of that stale premise, .github/workflows/release.yml currently uses .type // "branch"; an unexpected missing type therefore passes as branch:main instead of proving the ref type. Minimal fix: remove the fallback and require the API-provided type to equal branch, with a regression assertion that the fallback is absent.
Implemented in d48e6d6: removed the .type // "branch" fallback so an absent API type cannot satisfy the main-branch gate, and added workflow assertions for the exact branch:main comparison and absent fallback. Focused release tests passed 13/13, workflow contract tests passed 8/8, and git diff --check passed.

Re-review finding (5986610189, head d48e6d6)

Stale release plan after a new higher-major tag: the workflow plan may be created with prerelease=true; if a newer major version tag is added while the verify job runs, recheckPlan in tooling/release.mjs recalculates only moveAlias and latest. For prereleases, latest remains false, and a higher major does not change the alias decision within the planned version's major line, so the stale lower version can pass recheck and publish. The concurrency: release group serializes this workflow's runs but does not serialize external tag writes. Minimal fix: reject the publish recheck when a current version tag is at or above the planned version (excluding the planned tag itself for idempotent retries), and add a prerelease regression test where a new higher-major tag leaves both booleans unchanged. Revalidated at tooling/release.mjs:61-65, .github/workflows/release.yml:155-163, and planRelease at lines 19-28.
Implemented in c26f444: recheckPlan now rejects when the newest existing version tag (excluding the planned tag for idempotent resume) is at or above the planned version; added a prerelease regression where a new v1.0.0 makes a v0.3.0 plan stale.

Concern-token reconciliation (revalidated on c26f444)

  • 5984513806 concern:41513b352acd1f9b (CLI divergence/behind-tag coverage): covered in 1c4addf by tooling/release.test.mjs:122-157.
  • 5984917959 concern:50937d120c2f81ad (policy diagnostic, Git stderr): fixed in 11d2e7d, as recorded above.
  • 5986273737 concern:5d86419f750a5f3f (missing rule type as branch): fixed in d48e6d6, as recorded above.
  • 5986755261 concern:72d37323d748299b / concern:c03770463683904a (document newer-version retry rejection): valid; CONTRIBUTING.md:139-141 omits the c26f444 guard. Fixed in 318cb5c.

Review 5986836942 (🔵 Needs a closer look) — concern:18b86231740a3e5d

  • Path: automatic run where newest version tag is not on main history → automaticInput throws at tooling/release.mjs:99 (fail-closed, no tag writes). Live tags v0, v0.1.0, v0.2.0 are all ancestors of origin/main today.
  • Defect: the operator-facing error says "fix the release tag", contradicting CONTRIBUTING.md:146 ("Keep published version tags unchanged"); recovery is undocumented. Introduced by this PR's divergence check.
  • Smallest fix: reword the error to supersede via a manual release dispatched from main (manual path has no ancestry gate, release.mjs:127-129) and add one matching sentence to CONTRIBUTING. No logic change.
  • Fixed in fbd3f51: error and CONTRIBUTING now direct recovery to a superseding manual release from main; published tags stay unchanged (review 5986836942, concern:18b86231740a3e5d).

Review 5986887345 (🔵 Needs a closer look, No open issues) — concern:56b78b6e705da113

  • Disposition (no code change): advisory with no concrete defect. Human review of the interacting rules is the expected Wbreza review on this head. Hosted GITHUB_TOKEN write access cannot be proven locally; it is a post-merge verification gap: first run with dry_run=true, then the first unattended publish, checked by the R5 release-health monitor (evals-internal).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio
jongio requested review from wbreza and an adaptive review from Copilot November 20, 2026 01:35

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary (Re-review on 11d2e7d)

LGTM — 11d2e7d cleanly addresses both diagnostic refinements:

  • .github/workflows/release.yml: Rejects $policy != "false true" before querying deployment-branch-policies, so unrestricted or Protected branches only configurations emit the actionable ::error:: message instead of exiting early with HTTP 404.
  • ** ooling/release.mjs & ooling/release.test.mjs:** Captures and surfaces Git stderr diagnostics on unexpected non-1 failures in isAncestor, with unit test coverage alongside the temporary-repository CLI tests.

All CI checks pass with zero Critical, High, or Medium findings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The release gate treats a missing rule type as branch, allowing an untyped main rule to pass without verifying whether it targets a branch or a tag.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Fail closed when a deployment rule’s ref type is missing

.github/​workflows/​release.yml:143

A missing type is treated as branch, so an untyped rule named main passes without establishing whether it targets a branch or a tag. The documented list response omits this field, so the gate cannot rely on it always being present. Please obtain the ref type from an authoritative response or fail closed when it is unavailable.

Review effort: Max (adaptive)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary (Re-review on d48e6d6)

LGTM — 17957fe and d48e6d6 cleanly tighten the release-environment policy check and contract tests:

  • Fail-closed policy ref type (.github/workflows/release.yml): Drops .type // "branch" in favor of (.type):(.name) so a missing/unexpected ype evaluates to
    ull: and fails closed; verified against a live github.com deployment-branch-policies response that ype: "branch" is returned explicitly.
  • Workflow contract coverage ( ests/example.test.ts): Locks in the policy != "false true" guard ordering before deployment-branch-policies and asserts the .type // "branch" fallback stays absent.

All CI checks pass with zero Critical, High, or Medium findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because a critical release-time race can allow publishing when a higher-major tag created during verification points to a diverged commit.

No open issues 🎉

Review effort: Max (adaptive)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio
jongio requested review from wbreza and an adaptive review from Copilot November 20, 2026 02:40

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary (Re-review on c26f444)

LGTM — c26f444 cleanly hardens
echeckPlan in ooling/release.mjs so publish fails closed as stale whenever any version tag newer than the planned version appeared after �erify (closing the prerelease + higher-major race where moveAlias and latest both stay unchanged, while preserving idempotent resume by excluding the candidate tag itself), with a focused regression test in ooling/release.test.mjs.

All CI checks pass with zero Critical, High, or Medium findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The retry documentation omits the new guard’s rejection of a newer version tag even when the alias and latest decisions remain unchanged.

1 open issue

Review effort: Max (adaptive)

Comment thread tooling/release.mjs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jongio
jongio requested review from wbreza and an adaptive review from Copilot November 20, 2026 02:49

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary (Re-review on 318cb5c)

LGTM — 318cb5c aligns the retry recovery guidance in CONTRIBUTING.md with
echeckPlan's newer-version tag check (c26f444). All CI checks pass with zero findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to evaluate whether release-recovery guidance safely restores automatic releases while preserving published tags that diverge from main.

No open issues 🎉

1 resolved since last review

Review effort: Max (adaptive)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@wbreza wbreza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review Summary (Re-review on bd3f51)

LGTM — bd3f51 aligns both the diverged-tag error message in ooling/release.mjs and the recovery guidance in CONTRIBUTING.md with the immutable-tag policy by directing operators to supersede a diverged tag via a manual workflow_dispatch release from main rather than moving a published tag.

All CI checks pass with zero Critical, High, or Medium findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Interacting unattended-publication rules for environment authorization, tag ancestry, and partial-publication retries require human review, while hosted GITHUB_TOKEN access remains unverified and cannot be established by local tests.

No open issues 🎉

Review effort: Balanced (adaptive)

@jongio
jongio merged commit cd81fcd into main Nov 20, 2026
10 checks passed
@jongio
jongio deleted the jongio/release-hardening branch November 20, 2026 03:18
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.

3 participants