0.12.0-SNAPSHOT.2 #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to npm | |
| on: | |
| push: | |
| tags: | |
| - 'v0.[0-9]+.[0-9]+-SNAPSHOT.[0-9]+' | |
| - 'v0.[0-9]+.[0-9]+' | |
| permissions: {} | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| tarball-artifact-id: ${{ steps.upload-tarball.outputs.artifact-id }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-node@v6 | |
| with: | |
| package-manager-cache: false # IMPORTANT: prevents potential [cache poisoning](https://docs.zizmor.sh/audits/#cache-poisoning) attacks | |
| node-version: '24' | |
| - run: npm ci | |
| - name: Pack the package into a tarball | |
| run: | | |
| mkdir -vp pkg-outdir | |
| npm pack --pack-destination pkg-outdir --json | tee pkg-outdir/npm-pack-output.json | |
| - name: Check that KaitaiStream.js is included | |
| run: | | |
| jq --exit-status '.[0].files | map(.path) | any(. == "KaitaiStream.js")' pkg-outdir/npm-pack-output.json | |
| - name: Upload the package tarball as artifact | |
| id: upload-tarball | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| path: pkg-outdir/*.tgz | |
| archive: false | |
| if-no-files-found: error | |
| publish: | |
| name: Publish | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build | |
| permissions: | |
| id-token: write # Required for OIDC (see https://docs.npmjs.com/trusted-publishers) | |
| steps: | |
| - name: Download the package tarball | |
| uses: actions/download-artifact@v8 | |
| with: | |
| artifact-ids: ${{ needs.build.outputs.tarball-artifact-id }} | |
| path: pkg-outdir/ | |
| - uses: actions/setup-node@v6 | |
| with: | |
| package-manager-cache: false # IMPORTANT: prevents potential [cache poisoning](https://docs.zizmor.sh/audits/#cache-poisoning) attacks | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Select dist-tag | |
| id: select-tag | |
| run: | | |
| GIT_TAG=${GITHUB_REF#refs/tags/} | |
| if [[ "$GIT_TAG" == v0.+([0-9]).+([0-9])-SNAPSHOT.+([0-9]) ]]; then | |
| DIST_TAG=next | |
| elif [[ "$GIT_TAG" == v0.+([0-9]).+([0-9]) ]]; then | |
| DIST_TAG=latest | |
| else | |
| echo "Error: the tag name '$GIT_TAG' does not match any of the patterns" | |
| exit 1 | |
| fi | |
| echo "dist-tag=$DIST_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Publish to npm | |
| env: | |
| DIST_TAG: ${{ steps.select-tag.outputs.dist-tag }} | |
| run: npm publish ./pkg-outdir/*.tgz --tag "$DIST_TAG" --json |