From 41dd8454da93d762de6ed14d391796e68b0e755a Mon Sep 17 00:00:00 2001 From: Maksym Stoianov Date: Tue, 3 Nov 2026 13:40:50 +0100 Subject: [PATCH] ci: publish releases to npm with trusted publishing release-please only creates GitHub releases; npm versions were published by hand. The publish job builds, tests and publishes the released tag with provenance through npm trusted publishing (OIDC, no stored token); workflow_dispatch publishes an existing tag. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-please.yml | 52 +++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 86901e8e..e348e377 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -5,6 +5,12 @@ on: push: branches: - main + # Publishes an existing release by hand (for example one released before this job existed). + workflow_dispatch: + inputs: + tag: + description: "Release tag to publish to npm, e.g. apps-script-utils-v2.1.1" + required: true permissions: contents: write @@ -15,9 +21,12 @@ name: release-please jobs: release-please: - if: github.server_url == 'https://github.com' && github.actor != 'github-actions[bot]' + if: github.event_name == 'push' && github.server_url == 'https://github.com' && github.actor != 'github-actions[bot]' runs-on: ubuntu-latest timeout-minutes: 8 + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} steps: # Manifest mode, not `release-type`. Without a manifest the action looks for @@ -25,6 +34,7 @@ jobs: # window it searches no longer reaches v1.10.0 — it concluded nothing had # ever been released and proposed 1.0.0. - name: release-please-action + id: release uses: googleapis/release-please-action@v4.4.0 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -32,3 +42,43 @@ jobs: manifest-file: .release-please-manifest.json # versioning-strategy: auto # changelog-path: CHANGELOG.md + + # npm trusted publishing (OIDC): no npm token is stored in GitHub. Needs a trusted publisher on + # npmjs.com → apps-script-utils → Settings → Trusted publishing: GitHub Actions, + # MaksymStoianov/apps-script-utils, workflow release-please.yml, environment npm, Publish allowed. + publish: + needs: release-please + if: >- + always() && github.server_url == 'https://github.com' && + ((github.event_name == 'push' && needs.release-please.outputs.release_created == 'true') || + github.event_name == 'workflow_dispatch') + runs-on: ubuntu-latest + timeout-minutes: 10 + environment: npm + permissions: + contents: read + id-token: write + + steps: + - name: checkout + uses: actions/checkout@v7 + with: + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || needs.release-please.outputs.tag_name }} + + - name: setup-node + uses: actions/setup-node@v7 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + + - name: install + run: npm ci + + - name: build + run: npm run build + + - name: test + run: npm test + + - name: publish + run: npm publish --provenance --access public