99permissions : {}
1010
1111jobs :
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
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
0 commit comments