From b4f569ab600af3dd3df0c64d77e9a3b1457091ee Mon Sep 17 00:00:00 2001 From: Alpha Olomi <10551599+alphaolomi@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:43:13 +0300 Subject: [PATCH] Add tag-triggered publish workflow and prepublishOnly script --- .github/workflows/publish.yml | 55 +++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 56 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ee797fa --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,55 @@ +name: publish + +# Runs when a GitHub release is published (or by hand, from a tag ref). +# Skipped unless the repository variable PUBLISH_ENABLED is set to "true". + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +jobs: + publish: + name: publish to npm + if: vars.PUBLISH_ENABLED == 'true' + runs-on: ubuntu-latest + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + - name: Release tag matches the package version + env: + TAG: ${{ github.event.release.tag_name || github.ref_name }} + run: | + version="$(node -p "require('./package.json').version")" + if [ "$TAG" != "v$version" ]; then + echo "::error::tag '$TAG' does not match package version '$version'" + exit 1 + fi + - run: npm ci + - name: Lint, test and build (prepublishOnly runs them again before publish) + run: | + npm run lint + npm run typecheck + npm test + npm run build + # Trusted publishing (OIDC) is used unless the NPM_TOKEN secret exists, in + # which case that token is used instead. + - name: Publish with trusted publishing + if: env.NPM_TOKEN == '' + run: npm publish --provenance --access public + - name: Publish with token + if: env.NPM_TOKEN != '' + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish --provenance --access public diff --git a/package.json b/package.json index 77edc78..0ffad5a 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "lint": "biome check .", "format": "biome check --write .", "test": "vitest run", + "prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run build", "check:package": "publint && attw --pack . --profile node16", "sync-vectors": "node scripts/sync-vectors.mjs", "check-vectors": "node scripts/check-vectors.mjs"