Skip to content

Commit 892f05d

Browse files
Add trusted publishing
- Publish to npmjs.org from tags. - Pin GitHub Actions by Git SHA. - Refactor permissions.
1 parent dec037a commit 892f05d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: build
33
on:
44
push:
55
branches: [ dev ]
6+
tags: [ '*' ]
67
paths-ignore:
78
- '**/*.gitattributes'
89
- '**/*.gitignore'
@@ -11,33 +12,47 @@ on:
1112
branches: [ dev ]
1213
workflow_dispatch:
1314

14-
permissions:
15-
contents: read
15+
permissions: {}
1616

1717
jobs:
1818
build:
1919
name: build
2020
runs-on: ubuntu-latest
2121

22+
permissions:
23+
contents: read
24+
id-token: write
25+
2226
steps:
2327

2428
- name: Checkout code
25-
uses: actions/checkout@v4
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
with:
31+
filter: 'tree:0'
32+
persist-credentials: false
33+
show-progress: false
2634

2735
- name: Setup Node
28-
uses: actions/setup-node@v4
36+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2937
with:
3038
node-version: '22.x'
39+
registry-url: 'https://registry.npmjs.org'
3140

3241
- name: Install packages
3342
run: |
3443
npm ci
3544
3645
- name: Setup .NET SDK
37-
uses: actions/setup-dotnet@v4
46+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
3847
with:
3948
dotnet-version: '9.0.x'
4049

4150
- name: Test
4251
run: |
4352
npm test
53+
54+
- name: Publish
55+
if: |
56+
github.event.repository.fork == false &&
57+
startsWith(github.ref, 'refs/tags/')
58+
run: npm publish

0 commit comments

Comments
 (0)