Skip to content

Commit 639f965

Browse files
kody-botkentcdodds
andauthored
chore: Harden npm trusted publishing workflow (#178)
* ci: harden npm release workflow * ci: fix workflow utf-8 encoding * ci: address workflow review feedback * ci: include next-major in release gate * ci: align release workflow guards * Apply suggestion from @kentcdodds * Apply suggestion from @kentcdodds --------- Co-authored-by: Kent C. Dodds <me@kentcdodds.com>
1 parent 1b87c9b commit 639f965

1 file changed

Lines changed: 57 additions & 14 deletions

File tree

.github/workflows/release.yml

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
permissions:
13-
actions: write
14-
contents: write # to be able to publish a GitHub release
15-
id-token: write # to enable use of OIDC for npm provenance
16-
issues: write # to be able to comment on released issues
17-
pull-requests: write # to be able to comment on released pull requests
13+
contents: read
1814

1915
defaults:
2016
run:
@@ -48,31 +44,78 @@ jobs:
4844
- uses: codecov/codecov-action@v6
4945
if: ${{ matrix.coverage }}
5046

51-
publish:
52-
name: ⚙️ Release
47+
build-release-artifact:
48+
name: 📦 Build release artifact
5349
needs: [test]
5450
runs-on: ubuntu-latest
51+
permissions:
52+
contents: read
53+
if: ${{ github.repository == 'epicweb-dev/cachified' && github.event_name == 'push' }}
54+
steps:
55+
- name: ⬇️ Checkout repo
56+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
57+
58+
- name: ⎔ Setup node
59+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
60+
with:
61+
node-version: lts/*
62+
package-manager-cache: false
63+
64+
- name: 📥 Install deps
65+
run: npm install --ignore-scripts
66+
67+
- name: 📦 Prepare package
68+
run: npm run build
69+
70+
- name: 📦 Upload package artifact
71+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
72+
with:
73+
name: npm-package-artifact
74+
path: dist
75+
if-no-files-found: error
76+
retention-days: 7
77+
78+
publish:
79+
name: 🚀 Release
80+
needs: [build-release-artifact]
81+
runs-on: ubuntu-latest
5582
permissions:
5683
contents: write # to be able to publish a GitHub release
5784
id-token: write # to enable use of OIDC for npm provenance
5885
issues: write # to be able to comment on released issues
5986
pull-requests: write # to be able to comment on released pull requests
87+
if: ${{ github.repository == 'epicweb-dev/cachified' && github.event_name == 'push' }}
6088
steps:
6189
- name: ⬇️ Checkout repo
62-
uses: actions/checkout@v6
90+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
6391

6492
- name: ⎔ Setup node
65-
uses: actions/setup-node@v6
93+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
6694
with:
67-
node-version: lts/*
95+
node-version: 24
96+
registry-url: https://registry.npmjs.org
97+
package-manager-cache: false
6898

69-
- name: 📥 Download deps
70-
uses: bahmutov/npm-install@v1
99+
- name: 📦 Download package artifact
100+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
101+
with:
102+
name: npm-package-artifact
103+
path: dist
71104

72-
- name: ⚙️ Semantic Release
73-
uses: cycjimmy/semantic-release-action@v6.0.0
105+
- name: 🚀 Release
106+
uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0
74107
with:
75108
semantic_version: 25
109+
branches: |
110+
[
111+
'+([0-9])?(.{+([0-9]),x}).x',
112+
'main',
113+
'next',
114+
'next-major',
115+
{name: 'beta', prerelease: true},
116+
{name: 'alpha', prerelease: true}
117+
]
76118
env:
77119
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78120
NPM_CONFIG_PROVENANCE: true
121+
NPM_CONFIG_IGNORE_SCRIPTS: true

0 commit comments

Comments
 (0)