|
| 1 | +name: 'Publish to NPM' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ['CI'] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: [master] |
| 9 | + workflow_call: |
| 10 | + inputs: |
| 11 | + ref: |
| 12 | + description: 'Git ref (branch, tag, or commit SHA) to checkout and publish' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + dist-tag: |
| 16 | + description: 'NPM dist-tag to use for publishing' |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: 'next' |
| 20 | + workflow_dispatch: |
| 21 | + inputs: |
| 22 | + ref: |
| 23 | + description: 'Git ref (branch, tag, or commit SHA) to checkout and publish' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + dist-tag: |
| 27 | + description: 'NPM dist-tag to use for publishing' |
| 28 | + required: false |
| 29 | + type: choice |
| 30 | + options: |
| 31 | + - next |
| 32 | + - latest |
| 33 | + default: 'next' |
| 34 | + |
| 35 | +permissions: |
| 36 | + contents: read |
| 37 | + id-token: write |
| 38 | + |
| 39 | +jobs: |
| 40 | + publish: |
| 41 | + name: Build & Publish |
| 42 | + runs-on: ubuntu-22.04 |
| 43 | + if: github.repository == 'eclipse-glsp/glsp-client' && (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || (github.event.workflow_run.conclusion == 'success')) |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 46 | + with: |
| 47 | + ref: ${{ inputs.ref || github.event.inputs.ref || github.event.workflow_run.head_commit.id || github.sha }} |
| 48 | + # Fetch all history for lerna to determine versions |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + - name: Check for changes in "packages" or "examples" directory |
| 52 | + id: check_changes |
| 53 | + run: | |
| 54 | + DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}" |
| 55 | + # For 'next' dist-tag: check for changes when triggered by workflow_run or workflow_call |
| 56 | + # For 'latest' dist-tag or workflow_dispatch: always publish |
| 57 | + if [[ "$DIST_TAG" == "next" ]] && [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then |
| 58 | + if git diff --name-only HEAD^ HEAD | grep -qE '^(packages|examples)'; then |
| 59 | + echo "should_publish=true" >> $GITHUB_OUTPUT |
| 60 | + else |
| 61 | + echo "should_publish=false" >> $GITHUB_OUTPUT |
| 62 | + fi |
| 63 | + else |
| 64 | + echo "should_publish=true" >> $GITHUB_OUTPUT |
| 65 | + fi |
| 66 | +
|
| 67 | + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 |
| 68 | + if: steps.check_changes.outputs.should_publish == 'true' |
| 69 | + with: |
| 70 | + node-version: 20.x |
| 71 | + registry-url: 'https://registry.npmjs.org' |
| 72 | + |
| 73 | + - name: Build |
| 74 | + if: steps.check_changes.outputs.should_publish == 'true' |
| 75 | + run: yarn |
| 76 | + |
| 77 | + - name: Publish to NPM |
| 78 | + if: steps.check_changes.outputs.should_publish == 'true' |
| 79 | + run: | |
| 80 | + DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}" |
| 81 | + if [[ "$DIST_TAG" == "next" ]]; then |
| 82 | + yarn publish:next |
| 83 | + elif [[ "$DIST_TAG" == "latest" ]]; then |
| 84 | + yarn publish:latest |
| 85 | + else |
| 86 | + echo "Unknown dist-tag: $DIST_TAG" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | + env: |
| 90 | + NPM_CONFIG_PROVENANCE: 'true' |
0 commit comments