|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + project: |
| 7 | + description: Package to release |
| 8 | + type: choice |
| 9 | + options: [angular, zone-js] |
| 10 | + default: angular |
| 11 | + version: |
| 12 | + description: Version specifier (e.g. 22.0.0, patch, minor) |
| 13 | + required: true |
| 14 | + dry-run: |
| 15 | + description: Dry run (preview only, no push/publish) |
| 16 | + type: boolean |
| 17 | + default: true |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: nx-release-${{ github.ref }} |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: write # push release commit + tag, create GitHub release |
| 25 | + id-token: write # npm provenance / trusted publishing (OIDC) |
| 26 | + |
| 27 | +env: |
| 28 | + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} |
| 29 | + |
| 30 | +jobs: |
| 31 | + release: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + environment: |
| 34 | + name: ${{ inputs.dry-run && 'npm-publish-dry-run' || 'npm-publish' }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v6 |
| 37 | + with: |
| 38 | + # nx release needs tags + full history to build the changelog |
| 39 | + fetch-depth: 0 |
| 40 | + - uses: actions/setup-node@v6 |
| 41 | + with: |
| 42 | + node-version: lts/* |
| 43 | + cache: npm |
| 44 | + registry-url: https://registry.npmjs.org |
| 45 | + - name: Update npm (required for OIDC trusted publishing) |
| 46 | + run: | |
| 47 | + npm install -g npm@^11.5.1 |
| 48 | + npm --version |
| 49 | + - run: npm install --force |
| 50 | + - name: Configure git author |
| 51 | + run: | |
| 52 | + git config user.name "github-actions[bot]" |
| 53 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 54 | + # Publishing is intentionally split out (--skip-publish) so the OIDC |
| 55 | + # token-clearing logic below wraps only the publish step. |
| 56 | + - name: nx release version + changelog |
| 57 | + run: > |
| 58 | + npx nx release ${{ inputs.version }} |
| 59 | + --groups=${{ inputs.project }} |
| 60 | + --skip-publish |
| 61 | + ${{ inputs.dry-run && '--dry-run' || '' }} |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + # OIDC trusted publishing (default): npm must find no token auth at all, |
| 65 | + # otherwise it uses the token instead of the OIDC exchange. |
| 66 | + - name: nx release publish (OIDC) |
| 67 | + if: ${{ vars.USE_NPM_TOKEN != 'true' }} |
| 68 | + shell: bash |
| 69 | + env: |
| 70 | + NPM_CONFIG_PROVENANCE: true |
| 71 | + NODE_AUTH_TOKEN: "" |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | + unset NODE_AUTH_TOKEN |
| 75 | + rm -f ~/.npmrc || true |
| 76 | + if [[ -n "${NPM_CONFIG_USERCONFIG:-}" ]]; then |
| 77 | + rm -f "$NPM_CONFIG_USERCONFIG" || true |
| 78 | + fi |
| 79 | +
|
| 80 | + npx nx release publish \ |
| 81 | + --groups=${{ inputs.project }} \ |
| 82 | + --access public \ |
| 83 | + ${{ inputs.dry-run && '--dry-run' || '' }} |
| 84 | + # Token fallback: only when explicitly enabled via repo variable USE_NPM_TOKEN=true. |
| 85 | + - name: nx release publish (token) |
| 86 | + if: ${{ vars.USE_NPM_TOKEN == 'true' }} |
| 87 | + env: |
| 88 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 89 | + NPM_CONFIG_PROVENANCE: true |
| 90 | + run: > |
| 91 | + npx nx release publish |
| 92 | + --groups=${{ inputs.project }} |
| 93 | + --access public |
| 94 | + ${{ inputs.dry-run && '--dry-run' || '' }} |
0 commit comments