docs(readme): document release-based stable publishing #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 npm | |
| on: | |
| push: | |
| branches: | |
| - main | |
| release: | |
| types: | |
| - published | |
| permissions: | |
| contents: read | |
| id-token: write | |
| concurrency: | |
| group: npm-publish-${{ github.event_name }}-${{ github.ref || github.event.release.tag_name || github.run_id }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish-dev: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| cache-dependency-path: package-lock.json | |
| registry-url: https://registry.npmjs.org | |
| - name: Resolve development version | |
| id: dev_version | |
| run: | | |
| version="$(npm run --silent publish:resolve-dev-version)" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Stamp development package version | |
| env: | |
| DEV_VERSION: ${{ steps.dev_version.outputs.version }} | |
| run: npm version --no-git-tag-version "$DEV_VERSION" | |
| - name: Build package | |
| run: npm run build | |
| - name: Typecheck package | |
| run: npm run typecheck | |
| - name: Run tests | |
| run: npm test | |
| - name: Verify packed files | |
| run: npm run pack:check | |
| - name: Publish to npm dev dist-tag | |
| run: npm publish --tag dev --provenance --access public | |
| - name: Summarize publish result | |
| if: always() | |
| env: | |
| RESOLVED_VERSION: ${{ steps.dev_version.outputs.version || 'n/a' }} | |
| JOB_STATUS: ${{ job.status }} | |
| run: | | |
| { | |
| echo "## npm dev publish" | |
| echo | |
| echo "- Version: $RESOLVED_VERSION" | |
| echo "- Dist-tag: dev" | |
| echo "- Registry: npmjs.org" | |
| if [ "$JOB_STATUS" = "success" ]; then | |
| echo "- Result: published with provenance enabled." | |
| else | |
| echo "- Result: failed before publish completed. Check the failed gate above." | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| publish-release: | |
| if: github.event_name == 'release' && github.event.action == 'published' && !github.event.release.prerelease && !github.event.release.draft | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout release tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.release.tag_name }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| cache-dependency-path: package-lock.json | |
| registry-url: https://registry.npmjs.org | |
| - name: Verify release tag and resolve stable version | |
| id: version | |
| run: | | |
| version="$(npm run --silent publish:verify-release -- "${{ github.event.release.tag_name }}")" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Stamp stable package version | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.version }} | |
| run: npm version --no-git-tag-version "$RELEASE_VERSION" | |
| - name: Build package | |
| run: npm run build | |
| - name: Typecheck package | |
| run: npm run typecheck | |
| - name: Run tests | |
| run: npm test | |
| - name: Verify packed files | |
| run: npm run pack:check | |
| - name: Publish to npm latest dist-tag | |
| run: npm publish --tag latest --provenance --access public | |
| - name: Summarize publish result | |
| if: always() | |
| env: | |
| RESOLVED_VERSION: ${{ steps.version.outputs.version || 'n/a' }} | |
| JOB_STATUS: ${{ job.status }} | |
| RELEASE_URL: ${{ github.event.release.html_url }} | |
| TAG_NAME: ${{ github.event.release.tag_name }} | |
| run: | | |
| { | |
| echo "## npm stable publish" | |
| echo | |
| echo "- Version: $RESOLVED_VERSION" | |
| echo "- Dist-tag: latest" | |
| echo "- Release: $RELEASE_URL" | |
| echo "- Tag: $TAG_NAME" | |
| echo "- Registry: npmjs.org" | |
| if [ "$JOB_STATUS" = "success" ]; then | |
| echo "- Result: published with provenance enabled." | |
| else | |
| echo "- Result: failed before publish completed. Check the failed gate above." | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" |