Publish to NPM #16
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' | |
| on: | |
| workflow_run: | |
| workflows: ['CI'] | |
| types: | |
| - completed | |
| branches: [main] | |
| workflow_call: | |
| inputs: | |
| ref: | |
| description: 'Git ref (branch, tag, or commit SHA) to checkout and publish' | |
| required: true | |
| type: string | |
| dist-tag: | |
| description: 'NPM dist-tag to use for publishing' | |
| required: false | |
| type: string | |
| default: 'next' | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: 'Git ref (branch, tag, or commit SHA) to checkout and publish' | |
| required: true | |
| type: string | |
| dist-tag: | |
| description: 'NPM dist-tag to use for publishing' | |
| required: false | |
| type: choice | |
| options: | |
| - next | |
| - latest | |
| default: 'next' | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| publish: | |
| name: Build & Publish | |
| runs-on: ubuntu-22.04 | |
| if: github.repository == 'eclipse-glsp/glsp-server-node' && (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || (github.event.workflow_run.conclusion == 'success')) | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| with: | |
| ref: ${{ inputs.ref || github.event.inputs.ref || github.event.workflow_run.head_commit.id || github.sha }} | |
| # Fetch all history to determine the canary version | |
| fetch-depth: 0 | |
| - name: Check for changes in "packages" or "examples" directory | |
| id: check_changes | |
| run: | | |
| DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}" | |
| # For 'next' dist-tag: check for changes when triggered by workflow_run or workflow_call | |
| # For 'latest' dist-tag or workflow_dispatch: always publish | |
| if [[ "$DIST_TAG" == "next" ]] && [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then | |
| if git diff --name-only HEAD^ HEAD | grep -qE '^(packages|examples)'; then | |
| echo "should_publish=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "should_publish=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "should_publish=true" >> $GITHUB_OUTPUT | |
| fi | |
| - uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8 | |
| if: steps.check_changes.outputs.should_publish == 'true' | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| if: steps.check_changes.outputs.should_publish == 'true' | |
| with: | |
| node-version: 22.x | |
| cache: pnpm | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Build | |
| if: steps.check_changes.outputs.should_publish == 'true' | |
| run: pnpm build | |
| - name: Publish to NPM | |
| if: steps.check_changes.outputs.should_publish == 'true' | |
| run: | | |
| DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}" | |
| if [[ "$DIST_TAG" == "next" ]]; then | |
| pnpm publish:next | |
| elif [[ "$DIST_TAG" == "latest" ]]; then | |
| pnpm publish:latest | |
| else | |
| echo "Unknown dist-tag: $DIST_TAG" | |
| exit 1 | |
| fi | |
| env: | |
| NPM_CONFIG_PROVENANCE: 'true' |