Skip to content

Commit a952a6a

Browse files
authored
ci: harden npm trusted publishing workflow (#577)
1 parent afb29c8 commit a952a6a

1 file changed

Lines changed: 63 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@ on:
88
pull_request: {}
99
workflow_dispatch:
1010

11-
permissions: {}
12-
11+
permissions:
12+
contents: read
1313
concurrency:
1414
group: ${{ github.workflow }}-${{ github.ref }}
1515
cancel-in-progress: true
1616

1717
jobs:
18-
build_test_release:
18+
build_test:
1919
permissions:
20-
id-token: write # to enable use of OIDC (npm trusted publishing and provenance)
21-
actions: write # to cancel/stop running workflows (styfle/cancel-workflow-action)
22-
contents: write # to create release tags (cycjimmy/semantic-release-action)
23-
issues: write # to post release that resolves an issue (cycjimmy/semantic-release-action)
24-
pull-requests: write # to be able to comment on released pull requests
20+
contents: read
2521

2622
strategy:
2723
matrix:
@@ -58,8 +54,66 @@ jobs:
5854
- name: lint
5955
run: npm run lint
6056
timeout-minutes: 5
57+
58+
build-release-artifact:
59+
needs: build_test
60+
runs-on: ubuntu-latest
61+
permissions:
62+
contents: read
63+
if: ${{ github.repository == 'testing-library/angular-testing-library' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta') && github.event_name == 'push' }}
64+
steps:
65+
- name: Checkout repo
66+
uses: actions/checkout@v6
67+
68+
- name: Setup node
69+
uses: actions/setup-node@v5
70+
with:
71+
node-version: 24
72+
73+
- name: Update npm
74+
run: npm install -g npm@latest
75+
76+
- name: Install dependencies
77+
run: npm install --force --ignore-scripts
78+
79+
- name: 📦 Prepare package
80+
run: npm run build
81+
timeout-minutes: 5
82+
83+
- name: 📦 Upload package artifact
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: npm-package-dist
87+
path: dist/@testing-library/angular
88+
if-no-files-found: error
89+
retention-days: 7
90+
91+
release:
92+
needs: build-release-artifact
93+
runs-on: ubuntu-latest
94+
permissions:
95+
id-token: write # to enable use of OIDC (npm trusted publishing and provenance)
96+
contents: write # to create release tags (cycjimmy/semantic-release-action)
97+
issues: write # to post release that resolves an issue (cycjimmy/semantic-release-action)
98+
pull-requests: write # to be able to comment on released pull requests
99+
if: ${{ github.repository == 'testing-library/angular-testing-library' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta') && github.event_name == 'push' }}
100+
steps:
101+
- name: Checkout repo
102+
uses: actions/checkout@v6
103+
104+
- name: Setup node
105+
uses: actions/setup-node@v5
106+
with:
107+
node-version: 24
108+
registry-url: 'https://registry.npmjs.org'
109+
110+
- name: 📦 Download package artifact
111+
uses: actions/download-artifact@v4
112+
with:
113+
name: npm-package-dist
114+
path: dist/@testing-library/angular
115+
61116
- name: 🚀 Release
62-
if: github.repository == 'testing-library/angular-testing-library' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta')
63117
uses: cycjimmy/semantic-release-action@v6
64118
with:
65119
semantic_version: 25

0 commit comments

Comments
 (0)