# Publishes to npm with provenance on release. `cli-v*` tags publish lmnr-cli; # every other tag publishes @lmnr-ai/types, @lmnr-ai/client and @lmnr-ai/lmnr. # # Supply-chain hardening (LAM-2384): # - each job checks out this repository at github.sha only, and fails unless # that commit is what the release tag points to, is already on main, and # carries the version the tag names; # - after publishing, the provenance npm serves for each package is verified # against this repository, commit, tag and workflow; # - third-party actions and the npm CLI are pinned. # # The verification steps live inline on purpose: a local composite action # would be loaded from the checked-out tree, i.e. from the code being verified. name: Publish to npm on: release: types: [published] permissions: contents: read jobs: publish-cli: if: github.repository == 'lmnr-ai/lmnr-ts' && startsWith(github.event.release.tag_name, 'cli-') runs-on: ubuntu-24.04-arm permissions: contents: read id-token: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ github.repository }} ref: ${{ github.sha }} # full history + tags, to check the tag and main below fetch-depth: 0 persist-credentials: false - name: Verify release source env: # From the event payload, not GITHUB_REF: that is intermittently # empty on release events (actions/runner#2788). RELEASE_TAG: ${{ github.event.release.tag_name }} run: | set -euo pipefail fail() { echo "::error::$*"; exit 1; } origin="$(git remote get-url origin)" [ "${origin%.git}" = "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" ] \ || fail "origin remote is not $GITHUB_SERVER_URL/$GITHUB_REPOSITORY" [ "$(git rev-parse HEAD)" = "$GITHUB_SHA" ] \ || fail "HEAD $(git rev-parse HEAD) is not GITHUB_SHA $GITHUB_SHA" tag_sha="$(git rev-parse --verify "refs/tags/$RELEASE_TAG^{commit}")" [ "$tag_sha" = "$GITHUB_SHA" ] \ || fail "tag $RELEASE_TAG points to $tag_sha, not GITHUB_SHA $GITHUB_SHA" git merge-base --is-ancestor "$GITHUB_SHA" origin/main \ || fail "$GITHUB_SHA is not on main" # Tags are cli-v, optionally with a -post.N re-release suffix. version="$(jq -r .version packages/lmnr-cli/package.json)" base="${RELEASE_TAG%%[.-]post*}" [ "${base#cli-v}" = "$version" ] \ || fail "tag $RELEASE_TAG does not match lmnr-cli version $version" echo "Publishing $GITHUB_REPOSITORY@$GITHUB_SHA ($RELEASE_TAG, lmnr-cli $version)" - name: Install pnpm uses: pnpm/setup@v3.1.1 # immutable tag with: version: 12.14.0 runtime: node@24 # github runners have old npm, get a new-ish version - run: npm install -g npm@12.2.1 - run: pnpm install --frozen-lockfile - run: pnpm --filter lmnr-cli build - name: Publish CLI package run: cd packages/lmnr-cli && pnpm publish --provenance --access public --no-git-checks - name: Verify npm provenance env: GH_TOKEN: ${{ github.token }} PACKAGES: packages/lmnr-cli RELEASE_TAG: ${{ github.event.release.tag_name }} run: &verify-provenance | # Downloads each published tarball and checks that npm's SLSA # provenance for it was signed by this workflow, in this repository, # for this commit and tag. Retries cover registry propagation. set -euo pipefail cd "$RUNNER_TEMP" for dir in $PACKAGES; do name="$(jq -r .name "$GITHUB_WORKSPACE/$dir/package.json")" version="$(jq -r .version "$GITHUB_WORKSPACE/$dir/package.json")" spec="$(jq -rn --arg s "$name@$version" '$s | @uri')" for attempt in $(seq 1 40); do if tgz="$(npm pack "$name@$version" --loglevel=error)" \ && curl -fsS "https://registry.npmjs.org/-/npm/v1/attestations/$spec" \ | jq -e 'first(.attestations[] | select(.predicateType == "https://slsa.dev/provenance/v1") | .bundle)' \ > bundle.json \ && gh attestation verify "$tgz" --bundle bundle.json --digest-alg sha512 \ --repo "$GITHUB_REPOSITORY" \ --source-digest "$GITHUB_SHA" \ --source-ref "refs/tags/$RELEASE_TAG" \ --signer-workflow "$GITHUB_REPOSITORY/.github/workflows/publish-to-npm.yml" \ --deny-self-hosted-runners; then echo "Verified npm provenance for $name@$version" continue 2 fi echo "Attempt $attempt for $name@$version failed, retrying in 15s" sleep 15 done echo "::error::Could not verify npm provenance for $name@$version" exit 1 done publish-sdk: if: github.repository == 'lmnr-ai/lmnr-ts' && !startsWith(github.event.release.tag_name, 'cli-') runs-on: ubuntu-latest permissions: contents: read id-token: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ github.repository }} ref: ${{ github.sha }} # full history + tags, to check the tag and main below fetch-depth: 0 persist-credentials: false - name: Verify release source env: # From the event payload, not GITHUB_REF: that is intermittently # empty on release events (actions/runner#2788). RELEASE_TAG: ${{ github.event.release.tag_name }} run: | set -euo pipefail fail() { echo "::error::$*"; exit 1; } origin="$(git remote get-url origin)" [ "${origin%.git}" = "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" ] \ || fail "origin remote is not $GITHUB_SERVER_URL/$GITHUB_REPOSITORY" [ "$(git rev-parse HEAD)" = "$GITHUB_SHA" ] \ || fail "HEAD $(git rev-parse HEAD) is not GITHUB_SHA $GITHUB_SHA" tag_sha="$(git rev-parse --verify "refs/tags/$RELEASE_TAG^{commit}")" [ "$tag_sha" = "$GITHUB_SHA" ] \ || fail "tag $RELEASE_TAG points to $tag_sha, not GITHUB_SHA $GITHUB_SHA" git merge-base --is-ancestor "$GITHUB_SHA" origin/main \ || fail "$GITHUB_SHA is not on main" # Tags are , optionally with a -post.N re-release suffix. # check-versions below keeps the other packages on the same version. version="$(jq -r .version packages/lmnr/package.json)" [ "${RELEASE_TAG%%[.-]post*}" = "$version" ] \ || fail "tag $RELEASE_TAG does not match @lmnr-ai/lmnr version $version" echo "Publishing $GITHUB_REPOSITORY@$GITHUB_SHA ($RELEASE_TAG, version $version)" - name: Install pnpm uses: pnpm/setup@v3.1.2 # immutable tag with: version: 12.14.0 runtime: node@24 # github runners have old npm, get a new-ish version - run: npm install -g npm@12.2.1 - run: pnpm install --frozen-lockfile - run: pnpm build - name: Check version consistency run: pnpm check-versions - name: Run tests run: pnpm --filter @lmnr-ai/* test # Recursive publish skips versions already on npm, so a re-run after a # partial failure only publishes what is missing. pnpm orders packages # by dependency (types, client, lmnr). - name: Publish SDK packages run: pnpm --filter "@lmnr-ai/*" publish --provenance --access public --no-git-checks - name: Verify npm provenance env: GH_TOKEN: ${{ github.token }} PACKAGES: packages/types packages/client packages/lmnr RELEASE_TAG: ${{ github.event.release.tag_name }} run: *verify-provenance