|
| 1 | +--- |
| 2 | +name: NPM Service |
| 3 | + |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: [published] |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + types: [opened, synchronize, reopened, closed] |
| 10 | + paths-ignore: |
| 11 | + - "**.md" |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + version-alias: |
| 15 | + description: version alias to map to a version number |
| 16 | + required: true |
| 17 | + type: choice |
| 18 | + options: |
| 19 | + - stable |
| 20 | + - latest |
| 21 | + - latest-rc |
| 22 | + version-number: |
| 23 | + description: version number (semver format) |
| 24 | + required: true |
| 25 | + default: vX.Y.Z |
| 26 | + type: string |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + id-token: write |
| 31 | + |
| 32 | +# Manage concurrency to stop running jobs and start new ones in case of new commit pushed |
| 33 | +concurrency: |
| 34 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 35 | + cancel-in-progress: true |
| 36 | + |
| 37 | +jobs: |
| 38 | + publish: |
| 39 | + if: github.event_name == 'release' || (github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' && github.event.pull_request.merged == false) |
| 40 | + runs-on: ubuntu-latest |
| 41 | + outputs: |
| 42 | + channel: ${{ steps.publish.outputs.channel }} |
| 43 | + permissions: |
| 44 | + id-token: write |
| 45 | + contents: read |
| 46 | + pull-requests: write |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v6 |
| 49 | + - uses: actions/setup-node@v6 |
| 50 | + with: |
| 51 | + node-version: 20 |
| 52 | + registry-url: "https://registry.npmjs.org" |
| 53 | + - run: npm install -g npm@latest |
| 54 | + - uses: ./.github/actions/install |
| 55 | + |
| 56 | + # Dev version setup (PR only) |
| 57 | + - name: Compute dev version |
| 58 | + if: github.event_name == 'pull_request' |
| 59 | + id: version |
| 60 | + run: | |
| 61 | + CURRENT_VERSION=$(jq -r '.version' package.json) |
| 62 | + DEV_CHANNEL="dev-${{ github.event.pull_request.number }}" |
| 63 | + DEV_VERSION="${CURRENT_VERSION}-${DEV_CHANNEL}.${{ github.run_id }}-${{ github.run_attempt }}" |
| 64 | + echo "channel=$DEV_CHANNEL" >> "$GITHUB_OUTPUT" |
| 65 | + echo "version=$DEV_VERSION" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Set dev version |
| 68 | + if: github.event_name == 'pull_request' |
| 69 | + env: |
| 70 | + DEV_CHANNEL: ${{ steps.version.outputs.channel }} |
| 71 | + run: | |
| 72 | + git config --global user.email "${DEV_CHANNEL}@github.com" |
| 73 | + git config --global user.name "$DEV_CHANNEL" |
| 74 | + npm version "${{ steps.version.outputs.version }}" --no-git-tag-version |
| 75 | +
|
| 76 | + # Publish (unified with conditional channel) |
| 77 | + - name: Publish |
| 78 | + id: publish |
| 79 | + env: |
| 80 | + DEV_CHANNEL: ${{ steps.version.outputs.channel }} |
| 81 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 82 | + EVENT_NAME: ${{ github.event_name }} |
| 83 | + run: | |
| 84 | + if [ "$EVENT_NAME" = "pull_request" ]; then |
| 85 | + CHANNEL="$DEV_CHANNEL" |
| 86 | + else |
| 87 | + CHANNEL="latest-rc" |
| 88 | + fi |
| 89 | + npm publish --provenance --access public --tag "$CHANNEL" |
| 90 | + # For e2e: PR uses dev channel, release uses tag name (e.g., v1.5.0) |
| 91 | + if [ "$EVENT_NAME" = "pull_request" ]; then |
| 92 | + echo "channel=$DEV_CHANNEL" >> "$GITHUB_OUTPUT" |
| 93 | + else |
| 94 | + echo "channel=$RELEASE_TAG" >> "$GITHUB_OUTPUT" |
| 95 | + fi |
| 96 | +
|
| 97 | + # Comment PR (PR only) |
| 98 | + - name: Comment PR |
| 99 | + if: github.event_name == 'pull_request' |
| 100 | + uses: thollander/actions-comment-pull-request@v3 |
| 101 | + env: |
| 102 | + DEV_CHANNEL: ${{ steps.version.outputs.channel }} |
| 103 | + with: |
| 104 | + message: | |
| 105 | + Published under `${{ env.DEV_CHANNEL }}` npm channel. |
| 106 | + ```sh |
| 107 | + $ sf plugins install sf-git-merge-driver@${{ env.DEV_CHANNEL }} |
| 108 | + ``` |
| 109 | + comment-tag: dev-publish |
| 110 | + mode: recreate |
| 111 | + |
| 112 | + e2e-tests: |
| 113 | + needs: [publish] |
| 114 | + uses: ./.github/workflows/run-e2e-tests.yml |
| 115 | + with: |
| 116 | + channel: ${{ needs.publish.outputs.channel }} |
| 117 | + |
| 118 | + manage-version: |
| 119 | + if: github.event_name == 'workflow_dispatch' |
| 120 | + runs-on: ubuntu-latest |
| 121 | + permissions: |
| 122 | + id-token: write |
| 123 | + contents: read |
| 124 | + steps: |
| 125 | + - name: Checkout sources |
| 126 | + uses: actions/checkout@v6 |
| 127 | + |
| 128 | + - name: Setup node |
| 129 | + uses: actions/setup-node@v6 |
| 130 | + with: |
| 131 | + node-version: 20 |
| 132 | + registry-url: "https://registry.npmjs.org" |
| 133 | + |
| 134 | + - run: npm install -g npm@latest |
| 135 | + |
| 136 | + - name: Add dist-tag |
| 137 | + env: |
| 138 | + VERSION_NUMBER: ${{ github.event.inputs.version-number }} |
| 139 | + VERSION_ALIAS: ${{ github.event.inputs.version-alias }} |
| 140 | + run: npm dist-tag add "sf-git-merge-driver@${VERSION_NUMBER}" "$VERSION_ALIAS" |
| 141 | + |
| 142 | + cleanup: |
| 143 | + if: ${{ github.event.pull_request.merged }} |
| 144 | + runs-on: ubuntu-latest |
| 145 | + permissions: |
| 146 | + id-token: write |
| 147 | + contents: read |
| 148 | + pull-requests: write |
| 149 | + steps: |
| 150 | + - uses: actions/checkout@v6 |
| 151 | + |
| 152 | + - uses: jwalton/gh-find-current-pr@master |
| 153 | + id: pr-number |
| 154 | + with: |
| 155 | + state: closed |
| 156 | + |
| 157 | + - name: Set dev channel value |
| 158 | + id: set-dev-channel |
| 159 | + run: | |
| 160 | + DEV_CHANNEL="dev-${{ steps.pr-number.outputs.pr }}" |
| 161 | +
|
| 162 | + - uses: actions/setup-node@v6 |
| 163 | + with: |
| 164 | + node-version: 20 |
| 165 | + registry-url: "https://registry.npmjs.org" |
| 166 | + |
| 167 | + - run: npm install -g npm@latest |
| 168 | + |
| 169 | + - name: Remove dist-tag |
| 170 | + run: npm dist-tag rm sf-git-merge-driver "${DEV_CHANNEL}" || true |
| 171 | + |
| 172 | + - name: Deprecate related dev versions |
| 173 | + run: | |
| 174 | + npm view sf-git-merge-driver versions --json | jq -r '.[]' | grep "\-dev-${DEV_CHANNEL}\." | xargs -I {} npm deprecate "sf-git-merge-driver@{}" "Deprecated dev version" || true |
| 175 | +
|
| 176 | + - name: Delete package dev channel PR comment |
| 177 | + uses: thollander/actions-comment-pull-request@v3 |
| 178 | + with: |
| 179 | + message: | |
| 180 | + Published under `${DEV_CHANNEL}` npm channel. |
| 181 | + ```sh |
| 182 | + $ sf plugins install sf-git-merge-driver@${DEV_CHANNEL} |
| 183 | + ``` |
| 184 | + comment-tag: dev-publish |
| 185 | + mode: delete |
0 commit comments