Skip to content

ci: test.yml with a completion check, and PR-based releases with npm trusted publishing - #401

Merged
JP-Ellis merged 5 commits into
mainfrom
ci/test-and-release-workflows
Oct 19, 2026
Merged

JP-Ellis merged 5 commits into
mainfrom
ci/test-and-release-workflows

Conversation

@JP-Ellis

@JP-Ellis JP-Ellis commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Goal

Split CI into one test.yml behind a single required status, and release through a draft PR:

  1. A draft release PR stays open and up to date with main.
  2. The files on that PR are the release. Hand edits to the version or changelog survive.
  3. Merging the PR tags the merge commit.
  4. The tag publishes to npm through trusted publishing and creates the GitHub release.

Sequence

  1. ci: split CI into test.yml jobs behind a completion check
    • The jobs are Biome (biome ci .), Build (tsc plus check:pack), and Test (unit tests and the Cypress example on Node 22, 24 and 26).
    • Draft PRs run only Biome. Build and Test start when the PR is marked ready (ready_for_review) and on pushes to main.
    • Test completion check fails when any job failed or was cancelled. The branch rule requires this one status.
    • The old push: branches: '*' trigger never matched a branch name with a slash. test.yml runs on pushes to main and on pull requests.
    • check:pack fails when the npm tarball lacks main, types, or any .js or .d.ts file under dist/. It catches both packaging faults fixed in chore(deps): Cypress 16 and TypeScript 7, plus build and release fixes #400.
  2. ci: release through a draft release PR, with npm trusted publishing
    • prepare runs on each push to main. git-cliff proposes the version. scripts/release.mts writes package.json and CHANGELOG.md and force-pushes release/pact-cypress-adapter behind a draft PR.
    • Once the release branch has a commit from anyone but the bot, prepare stops regenerating it and comments once.
    • prepare does nothing while the current version is untagged. That covers the gap between the merge and the tag.
    • Verify release runs on the ready release PR. It fails when the version is already tagged or CHANGELOG.md has no section for it.
    • tag tags the merge commit with the App token. Pushes made with GITHUB_TOKEN start no workflows.
    • publish builds, runs npm publish through OIDC in the npm environment, and creates the GitHub release from the version's CHANGELOG.md section. It skips a version npm already has, so a failed run can be re-run.
    • Removes release.yaml, publish.yaml, .versionrc and commit-and-tag-version. Adds RELEASING.md.

Alternatives weighed

  • release-please, as on pact-js's chore/move-to-release-please branch. Rejected. It regenerates the release PR on every push, which discards hand edits to the changelog or version.
  • Copy pact-msw-adapter's release.ts unchanged. Its script and cliff.toml are the base here, with three additions:
  • Tag on any push that lands an untagged version, as pact-reference#566 does. Rejected for this repo. A single package needs only the merge event, and the event names the commit to tag.
  • Keep scripts/ci/build-and-test.sh. Rejected. test.yml names each step, and the script had no other caller.

Verification

  • biome ci ., the 13 unit tests, a clean tsc build, check:pack, and actionlint all pass.
  • release.mts prepare --dry-run on current main proposes v1.4.0, because a feat(config) commit has landed since v1.3.0. It writes one new CHANGELOG.md section under a single header.
  • On the tagged v1.3.0, release.mts check fails as expected and tag --dry-run reports that the tag exists.
  • release.mts notes prints only the requested section for v1.3.0 and 1.2.6. The second-to-last commit raises standard-version's ### [x.y.z] patch headings to ##, so every release ends at the next ## heading.

The App-token and OIDC paths can only run on GitHub. They first run on the first release PR.

Setup before the first release

  • Install the PACTFLOW_CI_BOT App on this repository, and make vars.PACTFLOW_CI_BOT_APP_ID and secrets.PACTFLOW_CI_BOT_PRIVATE_KEY available to it.
  • Rulesets: allow the App to push release/pact-cypress-adapter and v* tags. Require Test completion check on main.
  • npm trusted publisher for @pactflow/pact-cypress-adapter: repository pactflow/pact-cypress-adapter, workflow release.yml, environment npm.
  • Create the npm environment.
  • After the first publish, delete the NPM_TOKEN and GH_TOKEN secrets.

The first release PR's changelog lists every commit since 2022. Trim it on the PR before merging.

Replace "Build and test" with test.yml. Its jobs:
- Biome runs `biome ci .`, which checks format and lint.
- Build runs tsc, then check:pack.
- Test runs the unit tests and the Cypress example on Node 22, 24 and
  26. It skips draft PRs.
- Test completion check fails when any other job failed or was
  cancelled. Branch protection requires this one job, so the job list
  can change without editing the ruleset.

The old workflow triggered on pushes to '*', which never matches a
branch name containing a slash. test.yml runs on pushes to main and on
pull requests. Concurrent runs for the same PR cancel each other.

check:pack (scripts/check-pack.mts) runs `npm pack --dry-run`. It fails
when the tarball lacks `main`, `types`, or any .js or .d.ts file that tsc
emitted. Users require `dist/plugin` by path, so every emitted module
counts. This check catches both packaging faults fixed in #400: the
unpublished types.d.ts and the dist/src/ layout.

scripts/ci/build-and-test.sh only ran the steps test.yml now names
individually, so it goes. The README badge points at test.yml.

Assisted-by: Claude Code:claude-opus-5-5
The old process ran `commit-and-tag-version` from a manual dispatch. It
pushed the bump straight to main with a PAT. A `workflow_run` hook then
published with a long-lived NPM_TOKEN and created no GitHub release.

release.yml replaces both workflows with four jobs:
- prepare (push to main) runs `scripts/release.mts prepare`. git-cliff
  proposes the next version from conventional commits. The script
  writes it to package.json, prepends a CHANGELOG.md section, and
  force-pushes release/pact-cypress-adapter behind a draft PR.
- dry-run (release PR marked ready) runs `release.mts check`. It fails
  when the version is already tagged or CHANGELOG.md has no section
  for it. It then builds and runs check:pack.
- tag (release PR merged) tags the merge commit with the version from
  its package.json.
- publish (v* tag) builds, publishes to npm through OIDC trusted
  publishing in the `npm` environment, and creates the GitHub release
  from the version's CHANGELOG.md section.

The files on the release branch are the release. Once the branch has a
commit from anyone but the bot, prepare stops regenerating it and
leaves a one-time comment. Hand edits to the version or changelog
therefore survive later pushes to main. Closing the PR gets a fresh
one.

prepare does nothing while package.json's version is untagged. Merging
the release PR pushes to main while the tag job is still running. In
that window git-cliff measures from the previous tag. With a
hand-edited version, it would open a second release PR for a version
nobody chose.

prepare and tag push with the PACTFLOW_CI_BOT App token. Pushes made
with GITHUB_TOKEN start no workflows, so the release PR would get no CI
and the tag would never publish. publish skips a version npm already
has, so the job can be re-run after a failed GitHub release step.

The script and git-cliff config follow pactflow/pact-msw-adapter. The
pause on manual edits follows pact-foundation/pact-reference#566.

CHANGELOG.md takes git-cliff's header. With the old standard-version
header, `git cliff --prepend` wrote a second header above the file.
`release.mts notes` also stops at standard-version's `### [x.y.z]`
patch headings, so old sections extract cleanly.

.versionrc and the commit-and-tag-version dependency are gone.
RELEASING.md describes the process and the one-time setup.

Assisted-by: Claude Code:claude-opus-5-5
standard-version wrote patch releases as `### [x.y.z]`, one level below
minor and major releases. Every release now has a `## ` heading, so a
release's section runs to the next `## ` heading. Only the heading
levels change.

Assisted-by: Claude Code:claude-opus-5-5
With every CHANGELOG.md release under a `## ` heading, changelogSection
ends a section at the next `## ` heading alone.

The release script has no unit tests. It is small and runs on every
push to main. Running `notes`, `check`, `tag --dry-run` and
`prepare --dry-run` against this repository's history verified it.
The test file was deleted in the previous commit, which staged it by
mistake.

Assisted-by: Claude Code:claude-opus-5-5
Build now skips draft PRs, like the Node test matrix. A draft PR runs
only the Biome check. The ready_for_review trigger runs Build and the
tests once the PR is marked ready. Pushes to main run every job.

Skipped jobs count as passing for Test completion check. A draft cannot
merge, so the sentinel's green result on a draft gates nothing.

Assisted-by: Claude Code:claude-opus-5-5
@JP-Ellis
JP-Ellis merged commit abbc985 into main Oct 19, 2026
13 checks passed
@JP-Ellis
JP-Ellis deleted the ci/test-and-release-workflows branch October 19, 2026 00:09
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