|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Publishes @wdio/browserstack-service to npm via OIDC Trusted Publishing |
| 4 | +# (no long-lived NPM_TOKEN). One-time setup by an @wdio npm org admin on npmjs.com: |
| 5 | +# @wdio/browserstack-service -> Settings -> Trusted Publisher -> GitHub Actions |
| 6 | +# Organization/user: browserstack |
| 7 | +# Repository: wdio-browserstack-service |
| 8 | +# Workflow filename: release.yml |
| 9 | +# Environment: (leave empty) |
| 10 | +# Requires: PUBLIC repo (for provenance), npm >= 11.5.1, Node >= 22.14.0. |
| 11 | +# |
| 12 | +# The gRPC/protobuf client is generated inline at build time (buf generate); there is no |
| 13 | +# separate core package for this workflow to version or publish. |
| 14 | +# |
| 15 | +# Release model (publishing is MANUAL): |
| 16 | +# * push to main / v8 -> opens/updates the "Version Packages" PR only. NEVER publishes; |
| 17 | +# merging that PR does NOT publish either. |
| 18 | +# * Run workflow (publish) -> publishes the merged version to npm (main -> `latest`, |
| 19 | +# v8 -> `v8`) with git tag + GitHub release + provenance. |
| 20 | +# * Run workflow (canary) -> snapshot prerelease to the npm `canary` dist-tag. |
| 21 | + |
| 22 | +on: |
| 23 | + push: |
| 24 | + branches: |
| 25 | + - main # v9 line -> opens Version PR (publish target: dist-tag "latest") |
| 26 | + - v8 # v8 line -> opens Version PR (publish target: dist-tag "v8" via publishConfig.tag) |
| 27 | + workflow_dispatch: |
| 28 | + inputs: |
| 29 | + publish: |
| 30 | + description: 'Publish the merged version to npm (main -> `latest`, v8 -> `v8`). Merge the "Version Packages" PR first so there are no pending changesets.' |
| 31 | + type: boolean |
| 32 | + default: false |
| 33 | + canary: |
| 34 | + description: 'Publish a canary prerelease to the npm `canary` dist-tag (validates OIDC + provenance end-to-end; never touches `latest`). Requires at least one pending changeset.' |
| 35 | + type: boolean |
| 36 | + default: false |
| 37 | + |
| 38 | +# Never run main and v8 releases on top of each other. |
| 39 | +concurrency: release-${{ github.ref }} |
| 40 | + |
| 41 | +permissions: |
| 42 | + contents: write # commit the "Version Packages" PR + create git tags |
| 43 | + pull-requests: write # open the "Version Packages" PR |
| 44 | + id-token: write # OIDC for npm trusted publishing + provenance |
| 45 | + |
| 46 | +jobs: |
| 47 | + release: |
| 48 | + name: Release |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 # Changesets needs full history/tags |
| 55 | + |
| 56 | + - name: Setup Node |
| 57 | + # NOTE: intentionally NO `registry-url:` here. setup-node's registry-url writes |
| 58 | + # `//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}` into ~/.npmrc; with no |
| 59 | + # NODE_AUTH_TOKEN that becomes an empty token line that can shadow OIDC Trusted |
| 60 | + # Publishing at `npm publish` time. npm already defaults to registry.npmjs.org and |
| 61 | + # publishConfig.access=public handles the scoped publish, so the line isn't needed. |
| 62 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 |
| 63 | + with: |
| 64 | + node-version: 22 # resolves to >= 22.14 on the runner (OIDC floor) |
| 65 | + cache: 'npm' |
| 66 | + |
| 67 | + # Trusted Publishing needs npm >= 11.5.1. Pin to the 11.x line so a future |
| 68 | + # npm major can never silently change publish behaviour. |
| 69 | + - name: Upgrade npm to an OIDC-capable version |
| 70 | + run: npm install -g npm@11 |
| 71 | + |
| 72 | + - name: Install |
| 73 | + run: npm ci |
| 74 | + |
| 75 | + - name: Build |
| 76 | + run: npm run build |
| 77 | + |
| 78 | + - name: Test |
| 79 | + run: npm test |
| 80 | + |
| 81 | + # Version PR (push to main / v8): run changesets in VERSION-ONLY mode — open or update the |
| 82 | + # "Version Packages" PR (version bump + CHANGELOG). This step NEVER publishes: with no |
| 83 | + # `publish:` input, once the Version PR is merged (a push with no pending changesets) the |
| 84 | + # action simply no-ops. Publishing is the separate, manual step below. |
| 85 | + - name: Open/update the "Version Packages" PR |
| 86 | + if: github.event_name == 'push' |
| 87 | + uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d # v1 |
| 88 | + with: |
| 89 | + version: npm run version # changeset version — manages the Version PR only |
| 90 | + createGithubReleases: false |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + # Publish (manual, workflow_dispatch with publish=true): publish the already-versioned |
| 95 | + # package to npm — main -> `latest`, v8 -> `v8` (via publishConfig.tag) — with git tag, |
| 96 | + # GitHub release, and provenance, over the OIDC trusted publisher (no NPM_TOKEN). |
| 97 | + # Merge the "Version Packages" PR first: this publishes only when there are no pending |
| 98 | + # changesets. If any remain, the action safely opens/updates the Version PR instead. |
| 99 | + - name: Publish to npm |
| 100 | + if: github.event_name == 'workflow_dispatch' && inputs.publish |
| 101 | + uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d # v1 |
| 102 | + with: |
| 103 | + publish: npm run release # changeset publish (honors publishConfig.tag per branch) |
| 104 | + createGithubReleases: true |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + # No NPM_TOKEN: auth is OIDC via id-token: write above. |
| 108 | + NPM_CONFIG_PROVENANCE: 'true' |
| 109 | + |
| 110 | + # Canary (manual, workflow_dispatch with canary=true): snapshot-version the pending |
| 111 | + # changesets and publish a prerelease to the `canary` dist-tag via the SAME OIDC trusted |
| 112 | + # publisher. Validates OIDC + provenance end-to-end without touching `latest`. |
| 113 | + # snapshot.useCalculatedVersion=true in .changeset/config.json makes the version |
| 114 | + # <next>-canary-<datetime> (e.g. 9.30.0-canary-...). Requires >=1 pending changeset. |
| 115 | + - name: Canary publish to `canary` dist-tag |
| 116 | + if: github.event_name == 'workflow_dispatch' && inputs.canary |
| 117 | + run: | |
| 118 | + npx changeset version --snapshot canary |
| 119 | + npx changeset publish --no-git-tag --tag canary |
| 120 | + env: |
| 121 | + NPM_CONFIG_PROVENANCE: 'true' |
0 commit comments