Skip to content

Commit 6af29b5

Browse files
committed
GH Actions: split into "Build" and "Publish" jobs
Inspired by the existing CI workflow in the compiler repo: https://github.com/kaitai-io/kaitai_struct_compiler/blob/a677e5dc76034ded1f976726cf031d6f2418792a/.github/workflows/publish.yml
1 parent 2fd0815 commit 6af29b5

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

.github/workflows/publish.yml

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ on:
99
permissions: {}
1010

1111
jobs:
12-
publish-npm:
12+
build:
13+
name: Build
1314
runs-on: ubuntu-latest
1415
permissions:
15-
id-token: write # Required for OIDC (see https://docs.npmjs.com/trusted-publishers)
1616
contents: read
17+
outputs:
18+
tarball-artifact-id: ${{ steps.upload-tarball.outputs.artifact-id }}
1719
steps:
1820
- uses: actions/checkout@v6
1921
with:
@@ -22,11 +24,44 @@ jobs:
2224
with:
2325
package-manager-cache: false # IMPORTANT: prevents potential [cache poisoning](https://docs.zizmor.sh/audits/#cache-poisoning) attacks
2426
node-version: '24'
25-
registry-url: https://registry.npmjs.org/
2627
- run: npm ci
28+
- name: Pack the package into a tarball
29+
run: |
30+
mkdir -vp pkg-outdir
31+
npm pack --pack-destination pkg-outdir --json | tee pkg-outdir/npm-pack-output.json
32+
- name: Check that KaitaiStream.js is included
33+
run: |
34+
jq --exit-status '.[0].files | map(.path) | any(. == "KaitaiStream.js")' pkg-outdir/npm-pack-output.json
35+
- name: Upload the package tarball as artifact
36+
id: upload-tarball
37+
uses: actions/upload-artifact@v7
38+
with:
39+
path: pkg-outdir/*.tgz
40+
archive: false
41+
if-no-files-found: error
42+
43+
publish:
44+
name: Publish
45+
runs-on: ubuntu-latest
46+
needs:
47+
- build
48+
permissions:
49+
id-token: write # Required for OIDC (see https://docs.npmjs.com/trusted-publishers)
50+
steps:
51+
- name: Download the package tarball
52+
uses: actions/download-artifact@v8
53+
with:
54+
artifact-ids: ${{ needs.build.outputs.tarball-artifact-id }}
55+
path: pkg-outdir/
56+
- uses: actions/setup-node@v6
57+
with:
58+
package-manager-cache: false # IMPORTANT: prevents potential [cache poisoning](https://docs.zizmor.sh/audits/#cache-poisoning) attacks
59+
node-version: '24'
60+
registry-url: 'https://registry.npmjs.org'
2761
- name: Select dist-tag
62+
id: select-tag
2863
run: |
29-
GIT_TAG=${GITHUB_REF#refs/tags/*}
64+
GIT_TAG=${GITHUB_REF#refs/tags/}
3065
if [[ "$GIT_TAG" == v0.+([0-9]).+([0-9])-SNAPSHOT.+([0-9]) ]]; then
3166
DIST_TAG=next
3267
elif [[ "$GIT_TAG" == v0.+([0-9]).+([0-9]) ]]; then
@@ -35,9 +70,8 @@ jobs:
3570
echo "Error: the tag name '$GIT_TAG' does not match any of the patterns"
3671
exit 1
3772
fi
38-
echo "DIST_TAG=$DIST_TAG" >> "$GITHUB_ENV"
39-
- name: Check that KaitaiStream.js will be included
40-
run: |
41-
npm publish --tag "$DIST_TAG" --dry-run --json | jq --exit-status '.files | map(.path) | any(. == "KaitaiStream.js")'
73+
echo "dist-tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
4274
- name: Publish to npm
43-
run: npm publish --tag "$DIST_TAG"
75+
env:
76+
DIST_TAG: ${{ steps.select-tag.outputs.dist-tag }}
77+
run: npm publish ./pkg-outdir/*.tgz --tag "$DIST_TAG" --json

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/node_modules/
22

3-
# Generated by Typescript compiler
3+
# Generated by TypeScript compiler
44
/KaitaiStream.d.ts
55
/KaitaiStream.js
6+
7+
# Output directory for package tarballs used by the publishing CI workflow
8+
/pkg-outdir/

0 commit comments

Comments
 (0)