Publish JS SDK to npm #3
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 JS SDK to npm | |
| on: | |
| workflow_dispatch: # run the test matrix on demand (publish still requires a tag) | |
| push: | |
| tags: | |
| - "js-sdk-v*" # Trigger on tags like js-sdk-v0.1.0, js-sdk-v1.0.0 | |
| permissions: | |
| contents: write # For creating GitHub Releases | |
| jobs: | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| defaults: | |
| run: | |
| working-directory: packages/js-sdk | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest] | |
| node-version: [18, 20, 22] | |
| include: | |
| # Windows coverage on the LTS line only (issue #113). | |
| - os: windows-latest | |
| node-version: 20 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: "npm" | |
| cache-dependency-path: packages/js-sdk/package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Type check | |
| run: npm run typecheck | |
| - name: Run tests | |
| run: npm test | |
| - name: Build | |
| run: npm run build | |
| publish: | |
| needs: test | |
| # Event-scoped: a workflow_dispatch (even one targeting a tag ref) runs | |
| # tests only; publishing requires an actual tag push. | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: packages/js-sdk | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org | |
| - name: Verify package version matches tag | |
| run: | | |
| TAG_VERSION="${GITHUB_REF_NAME#js-sdk-v}" | |
| PKG_VERSION=$(node -p "require('./package.json').version") | |
| if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then | |
| echo "::error::Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)" | |
| exit 1 | |
| fi | |
| echo "VERSION=$PKG_VERSION" >> "$GITHUB_ENV" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Publish to npm | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # Release body = Install section + Highlights from the annotated tag | |
| # message (git tag -a js-sdk-vX.Y.Z -m "- bullet"), if any, + | |
| # auto-generated notes. Lightweight tags simply get no Highlights section. | |
| - name: Compose release notes | |
| run: | | |
| NOTES="$RUNNER_TEMP/release-notes.md" | |
| { | |
| echo '## Install' | |
| echo '' | |
| echo '```bash' | |
| echo "npm install @qverisai/sdk@${VERSION}" | |
| echo '```' | |
| } > "$NOTES" | |
| # actions/checkout maps the tag ref to the bare commit, dropping the | |
| # annotation (actions/checkout#882) — re-fetch the real tag object. | |
| git fetch --force --depth=1 origin "refs/tags/${GITHUB_REF_NAME}:refs/tags/${GITHUB_REF_NAME}" \ | |
| || echo "::warning::Could not re-fetch tag ${GITHUB_REF_NAME}; Highlights may be omitted" | |
| if [ "$(git cat-file -t "refs/tags/${GITHUB_REF_NAME}" 2>/dev/null)" = "tag" ]; then | |
| HIGHLIGHTS="$(git tag -l --format='%(contents)' "$GITHUB_REF_NAME" \ | |
| | sed -e '/^-----BEGIN PGP SIGNATURE-----$/,$d' -e '/^-----BEGIN SSH SIGNATURE-----$/,$d')" | |
| if [ -n "$HIGHLIGHTS" ]; then | |
| printf '\n## Highlights\n\n%s\n' "$HIGHLIGHTS" >> "$NOTES" | |
| fi | |
| fi | |
| printf '\nSee [README](packages/js-sdk/README.md) for usage.\n' >> "$NOTES" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: "QVeris JS SDK v${{ env.VERSION }}" | |
| body_path: ${{ runner.temp }}/release-notes.md | |
| generate_release_notes: true |