Skip to content

Commit 8cfbd05

Browse files
committed
ci: harden npm trusted publishing workflow
1 parent 80dbb49 commit 8cfbd05

1 file changed

Lines changed: 47 additions & 14 deletions

File tree

.github/workflows/release.yml

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ concurrency:
1616
cancel-in-progress: false
1717

1818
permissions:
19-
id-token: write # to enable use of OIDC (npm trusted publishing and provenance)
20-
contents: write # to be able to publish a GitHub release
21-
issues: write # to be able to comment on released issues
22-
pull-requests: write # to be able to comment on released pull requests
19+
contents: read
2320

2421
jobs:
2522
verifications:
2623
name: Verifications
24+
permissions:
25+
contents: read
26+
id-token: write # required by Codecov in the reusable workflow
2727
uses: ./.github/workflows/verifications.yml
2828

29-
publish:
30-
name: Publish package
29+
build-release-artifact:
30+
name: Build release artifact
3131
runs-on: ubuntu-latest
3232
needs: [verifications]
33-
# Avoid publishing in forks
33+
permissions:
34+
contents: read
3435
if: github.repository == 'testing-library/eslint-plugin-testing-library'
3536
steps:
3637
- name: Checkout
@@ -45,18 +46,50 @@ jobs:
4546
cache: 'pnpm'
4647
node-version-file: '.nvmrc'
4748

48-
# Ensure npm 11.5.1 or later is installed for correct OIDC publishing
49-
- name: Update npm
50-
# (using v11.10.0 to avoid Node.js bug causing an installation failure) https://github.com/npm/cli/issues/9151
51-
run: npm install -g npm@~11.10.0
52-
5349
- name: Install dependencies
54-
run: pnpm install
50+
run: pnpm install --ignore-scripts
5551

5652
- name: Build package
5753
run: pnpm run build
5854

55+
- name: Upload package artifact
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: npm-package-dist
59+
path: dist
60+
if-no-files-found: error
61+
retention-days: 7
62+
63+
publish:
64+
name: Publish package
65+
runs-on: ubuntu-latest
66+
needs: [build-release-artifact]
67+
permissions:
68+
id-token: write # to enable use of OIDC (npm trusted publishing and provenance)
69+
contents: write # to be able to publish a GitHub release
70+
issues: write # to be able to comment on released issues
71+
pull-requests: write # to be able to comment on released pull requests
72+
if: github.repository == 'testing-library/eslint-plugin-testing-library'
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
76+
77+
- name: Set up Node
78+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
79+
with:
80+
node-version-file: '.nvmrc'
81+
registry-url: 'https://registry.npmjs.org'
82+
83+
- name: Update npm
84+
run: npm install -g npm@~11.10.0
85+
86+
- name: Download package artifact
87+
uses: actions/download-artifact@v4
88+
with:
89+
name: npm-package-dist
90+
path: dist
91+
5992
- name: Release new version
60-
run: pnpm exec semantic-release
93+
run: npx --yes semantic-release@25.0.3
6194
env:
6295
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)