-
Notifications
You must be signed in to change notification settings - Fork 0
305 lines (298 loc) · 10.6 KB
/
build-js.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: Build
on:
workflow_call:
inputs:
node-code-pre-test:
required: false
type: string
secrets:
SNYK_TOKEN:
required: false
NPM_TOKEN:
required: false
permissions: {}
jobs:
call-workflow:
uses: ./.github/workflows/build-general.yml
secrets: inherit
permissions:
security-events: write
id-token: write
actions: read
contents: read
issues: read
pull-requests: read
with:
node-code-pre-test: DISABLE
sbom:
if: "inputs.node-code-pre-test != 'DISABLE'"
needs: call-workflow
name: Generate SBOM
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
github.com:443
objects.githubusercontent.com:443
raw.githubusercontent.com:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
show-progress: false
- name: Move README and license
run: mv README.md src && mv LICENSE src
- name: Generate SBOM
uses: anchore/sbom-action@55dc4ee22412511ee8c3142cbea40418e6cec693
with:
path: src
output-file: /tmp/sbom.spdx.json
upload-artifact: false
upload-release-assets: false
syft-version: v1.16.0
- name: Upload SBOM
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: SBOM
path: /tmp/sbom.spdx.json
test-unit:
if: "inputs.node-code-pre-test != 'DISABLE'"
needs: call-workflow
name: Run unit tests
permissions:
pull-requests: write
checks: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
registry.npmjs.org:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
show-progress: false
- name: Run unit tests
uses: warriors-life/.warriors-life-workflows/run-unit-tests@dev
with:
node-code-pre-test: ${{ inputs.node-code-pre-test }}
report: coverage/coverage.json
install-src: true
- name: Upload coverage file
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: Test coverage
path: test/coverage/coverage.json
- name: Move coverage file
run: mv test/coverage/coverage.json /tmp
- name: Checkout base ref
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
show-progress: false
ref: ${{ github.base_ref || 'dev' }}
- name: Run units tests on base
uses: warriors-life/.warriors-life-workflows/run-unit-tests@dev
with:
node-code-pre-test: ${{ inputs.node-code-pre-test }}
report: coverage/coverage.json
install-src: true
- id: coverage-report
name: Generate coverage report
uses: ArtiomTr/jest-coverage-report-action@262a7bb0b20c4d1d6b6b026af0f008f78da72788
with:
coverage-file: /tmp/coverage.json
base-coverage-file: test/coverage/coverage.json
output: ${{ github.event_name == 'pull_request' && 'comment' || 'report-markdown' }}
- name: Show coverage report
if: "github.event_name != 'pull_request'"
run: echo "$REPORT" >> $GITHUB_STEP_SUMMARY
env:
REPORT: ${{ steps.coverage-report.outputs.report }}
push:
if: github.ref_type == 'tag'
needs: [sbom, test-unit]
name: Publish package in the registry
runs-on: ubuntu-latest
permissions:
packages: write
id-token: write
attestations: write
contents: read
steps:
- name: Harden runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
*.sigstore.dev:443
api.github.com:443
npm.pkg.github.com:443
github.com:443
objects.githubusercontent.com
registry.npmjs.org:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
sparse-checkout: src
persist-credentials: false
show-progress: false
- name: Setup Node # TODO: do we need this? maybe this is required when we're publishing package that has GPR dependencies?
uses: warriors-life/.warriors-life-workflows/setup-node@dev
- name: Move README and license
run: mv README.md src && mv LICENSE src
- name: Pack package
id: package
run: |
npm pack src/
files=(*.tgz)
mv "$files[0]" "../$files[0]"
echo "archive-name=../$files[0]" >> $GITHUB_OUTPUT
- name: Upload package archive
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: Package
path: ${{ steps.package.outputs.archive-name }}
- name: Publish package to NPM
if: "!github.event.repository.private"
uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c
with:
token: ${{ secrets.NPM_TOKEN }}
package: src
provenance: true
access: public
- name: Modify package name
uses: maxgfr/github-change-json@8aedf0b5fe704df20d6e7bd9a55278a5c4a653d0
with:
key: name
value: ${{ format('@{0}', github.repository) }}
path: src/package.json
- name: Pack package (scoped)
id: package-scoped
run: |
npm pack src/
files=(*.tgz)
mv "$files[0]" "../$files[0]"
echo "archive-name=../$files[0]" >> $GITHUB_OUTPUT
- name: Upload package archive (scoped)
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: Package (scoped)
path: ${{ steps.package-scoped.outputs.archive-name }}
- name: Publish package to NPM (scoped)
if: "!github.event.repository.private"
uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c
with:
token: ${{ secrets.NPM_TOKEN }}
package: src
provenance: true
access: public
- name: Publish package to GPR
uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c
with:
registry: 'https://npm.pkg.github.com/'
token: ${{ github.token }}
package: src
provenance: ${{ !github.event.repository.private }}
access: ${{ github.event.repository.private && 'restricted' || 'public' }}
- name: Download SBOM
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: SBOM
path: /tmp
- name: Attest packages with SLSA provenance
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018
with:
subject-path: |
${{ steps.package.outputs.archive-name }}
${{ steps.package-scoped.outputs.archive-name }}
- name: Attest packages with SBOM
uses: actions/attest-sbom@5026d3663739160db546203eeaffa6aa1c51a4d6
with:
subject-path: |
${{ steps.package.outputs.archive-name }}
${{ steps.package-scoped.outputs.archive-name }}
sbom-path: /tmp/sbom.spdx.json
release:
if: github.ref_type == 'tag'
needs: push
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Harden runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
uploads.github.com:443
github.com:443
objects.githubusercontent.com:443
registry.npmjs.org:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
show-progress: false
- name: Setup Node # TODO: do we need this? maybe this is required when we're publishing package that has GPR dependencies?
uses: warriors-life/.warriors-life-workflows/setup-node@dev
- name: Extract release notes
id: extract-release-notes
uses: ffurrer2/extract-release-notes@9989ccec43d726ef05aa1cd7b2854fb96b6df6ab
- name: Download SBOM
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: SBOM
path: /tmp
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Get archive name
id: archive-name
run: |
echo "name=$repository-${tag#v}" >> $GITHUB_OUTPUT
env:
tag: ${{ github.ref_name }}
repository: ${{ github.event.repository.name }}
- name: Sign files
run: |
git -c tar.tar.gz.command='gzip -cn' archive --format=tar.gz --prefix="$archivename/" -o "../$archivename.tar.gz" "$tag"
gpg --armor --detach-sign "../$archivename.tar.gz"
mv README.md src && mv LICENSE src
npm pack src/
gpg --armor --detach-sign *.tgz
gpg --armor --detach-sign /tmp/sbom.spdx.json
env:
tag: ${{ github.ref_name }}
archivename: ${{ steps.archive-name.outputs.name }}
- name: Release
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974
with:
files: |
*.tgz
*.tgz.asc
../${{ steps.archive-name.outputs.name }}.tar.gz.asc
/tmp/sbom.spdx.json
/tmp/sbom.spdx.json.asc
body: ${{ steps.extract-release-notes.outputs.release_notes }}
fail_on_unmatched_files: true