Publish to npm #18
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 | |
| # Triggered when a version tag is created — by git push or the GitHub API. | |
| # | |
| # push: tags: only fires for git push operations. Tags created via the REST | |
| # API (POST /git/refs) use the create: event instead. create: covers both | |
| # cases, so it replaces push: tags: here. | |
| # | |
| # The job condition filters to @polygonlabs/** tags; branch creates are skipped. | |
| # Note: GitHub skips create events when >3 refs are created at once, but each | |
| # tag is created in a separate API call so each fires its own event. | |
| # | |
| # lerna publish from-package is idempotent — it only publishes versions not | |
| # yet on the registry. Private packages (agent-connector-ui, agent-shared) | |
| # are skipped automatically by lerna. Access is declared via publishConfig | |
| # in each package's package.json rather than as a flag here. | |
| on: | |
| create: | |
| workflow_dispatch: | |
| inputs: | |
| dist_tag: | |
| description: 'npm dist-tag' | |
| required: true | |
| default: 'latest' | |
| type: choice | |
| options: [latest, beta, dev] | |
| permissions: | |
| contents: read | |
| id-token: write # required for npm provenance attestations | |
| jobs: | |
| publish: | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| (github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/@polygonlabs/')) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| - uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4 | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: 'pnpm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Determine dist-tag | |
| id: dist-tag | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "value=${{ github.event.inputs.dist_tag }}" >> "$GITHUB_OUTPUT" | |
| else | |
| # GITHUB_REF_NAME is the tag name, e.g. "@polygonlabs/agent-cli@0.7.0" | |
| # Extract the version portion (everything after the last @) | |
| VERSION="${GITHUB_REF_NAME##*@}" | |
| # Pull the prerelease identifier out of the version string, if present | |
| # e.g. "0.7.0-beta.1" → "beta", "0.7.0" → "latest" | |
| if [[ "$VERSION" =~ -([a-zA-Z]+)\. ]]; then | |
| echo "value=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "value=latest" >> "$GITHUB_OUTPUT" | |
| fi | |
| fi | |
| - name: Publish to npm | |
| run: | | |
| echo "Publishing with dist-tag: ${{ steps.dist-tag.outputs.value }}" | |
| pnpm exec lerna publish from-package \ | |
| --dist-tag "${{ steps.dist-tag.outputs.value }}" \ | |
| --yes |