From 0132a63d675c71898a642265a4582382359aa5e2 Mon Sep 17 00:00:00 2001 From: Mateusz Sikorski Date: Sun, 29 Nov 2026 01:27:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20ci:=20publish=20to=20npm=20and?= =?UTF-8?q?=20create=20the=20GitHub=20release=20on=20a=20version=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - runs on v* tags, or by hand for an existing tag - checks the tag against package.json, then tests, build and publish - npm trusted publishing with provenance, no token stored --- .github/workflows/release.yml | 58 +++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 7 +++++ 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f672166 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: Release + +on: + push: + tags: ['v*'] + workflow_dispatch: + inputs: + tag: + description: Existing tag to publish, e.g. v0.2.0 + required: true + +permissions: + contents: write + id-token: write + +concurrency: + group: release-${{ inputs.tag || github.ref_name }} + cancel-in-progress: false + +jobs: + publish: + runs-on: ubuntu-latest + env: + TAG: ${{ inputs.tag || github.ref_name }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ env.TAG }} + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: pnpm + registry-url: https://registry.npmjs.org + # Trusted publishing (OIDC, no token) needs npm 11.5.1 or newer. + - run: npm install -g npm@latest + - run: pnpm install --frozen-lockfile + + - name: Check the tag matches package.json + run: | + version="$(node -p "require('./package.json').version")" + if [ "v${version}" != "${TAG}" ]; then + echo "Tag ${TAG} does not match package.json version ${version}" >&2 + exit 1 + fi + + # prepublishOnly runs typecheck, tests and build. + - run: npm publish --provenance --access public + + - name: Create the GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + if gh release view "${TAG}" >/dev/null 2>&1; then + echo "Release ${TAG} already exists" + else + gh release create "${TAG}" --verify-tag --generate-notes --title "${TAG}" + fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dea25c5..350884f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,3 +34,10 @@ vendor/bin/pest ``` Both test suites must pass. The JavaScript and PHP results have to match exactly. + +## Releasing + +1. Bump `version` in `package.json` and commit it as `🔖 chore(release): x.y.z`. +2. Push a signed tag: `git tag -s vx.y.z -m vx.y.z && git push origin master vx.y.z`. + +The tag starts `.github/workflows/release.yml`, which checks the tag against `package.json`, runs the tests, publishes to npm with provenance and creates the GitHub release. Packagist picks up the tag by itself. To publish a tag that already exists, run the workflow by hand with that tag.