name: Publish Packages (NPM & Github) on: release: types: [published] permissions: id-token: write # Required for OIDC packages: write contents: read jobs: # Guard against publishing from a tag that was not produced by # `npm run release:version`: `lerna publish from-package` publishes the # package.json versions at the tagged commit that are not yet on the # registry, so a tag placed on an unbumped commit publishes nothing and # the run "succeeds" (this happened with v1.10.0 on a 1.9.2 commit). check-version: runs-on: ubuntu-latest steps: - name: "Checkout" uses: actions/checkout@v4 with: fetch-depth: 0 - name: "Release tag must match lerna.json version" env: TAG: ${{ github.event.release.tag_name }} run: | set -euo pipefail version=$(node -p "require('./lerna.json').version") if [ "$TAG" != "v$version" ]; then echo "::error::Release tag '$TAG' does not match lerna.json version 'v$version'." echo "::error::Run 'npm run release:version' first (it bumps the packages, commits and creates the annotated tag), then create the release from that tag." exit 1 fi # Fixed mode only bumps the packages that changed since the last # release, so not every package carries the new version; require # that at least one public package does (those are what from-package # will publish, being absent from the registry). bumped=0 for pkg in packages/*/package.json; do if [ "$(node -p "require('./$pkg').private === true")" = "true" ]; then continue; fi if [ "$(node -p "require('./$pkg').version")" = "$version" ]; then bumped=$((bumped + 1)); fi done if [ "$bumped" -eq 0 ]; then echo "::error::No public package is at $version; the tagged commit was not produced by 'npm run release:version' and from-package would publish nothing." exit 1 fi echo "Release $TAG matches lerna.json; $bumped package(s) at $version." publish-npm: needs: check-version runs-on: ubuntu-latest steps: - name: "Checkout" uses: actions/checkout@v4 with: fetch-depth: 0 - name: "Setup node" uses: actions/setup-node@v4 with: node-version: 20.x registry-url: 'https://registry.npmjs.org' - name: "Install deps" run: npm ci - name: "Build" run: npm run build - name: "Publish package" run: npm run release:publish env: NPM_CONFIG_PROVENANCE: true publish-github: needs: check-version runs-on: ubuntu-latest steps: - name: "Checkout" uses: actions/checkout@v4 with: fetch-depth: 0 - name: "Setup node" uses: actions/setup-node@v4 with: node-version: 20.x registry-url: 'https://npm.pkg.github.com' scope: '@aleph-sdk' - name: "Prepare npmrc" run: envsubst < .npmrc_ci > .npmrc env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN}} - name: "Install deps" run: npm ci - name: "Build" run: npm run build - name: "Publish package" run: npm run release:publish