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.