Skip to content

Commit 349473f

Browse files
scolladonclaude
andcommitted
refactor: consolidate npm publishing into single OIDC workflow
Create npm-publish.yml as the single entry-point workflow for npm trusted publishing. This workflow handles both PR dev publishes and release publishes, with provenance support. - Add npm-publish.yml with publish-dev and publish-release jobs - Add manual-deprecate-versions.yml for version deprecation - Add manual-manage-versions.yml for dist-tag management - Remove npm-publisher.yml (replaced by npm-publish.yml) - Update on-pull-request.yml to remove publish jobs (moved to npm-publish) - Update on-main-push.yml to remove release jobs (triggered by release event) - Update on-merged-pull-request.yml to use OIDC directly Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2036681 commit 349473f

File tree

7 files changed

+226
-235
lines changed

7 files changed

+226
-235
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Deprecate versions
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version-expression:
8+
description: version number (semver format) or range to deprecate
9+
required: true
10+
type: string
11+
rationale:
12+
description: explain why this version is deprecated. No message content will un-deprecate the version
13+
type: string
14+
15+
permissions:
16+
contents: read
17+
id-token: write
18+
19+
jobs:
20+
deprecate:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout sources
24+
uses: actions/checkout@v6
25+
26+
- name: Setup node
27+
uses: actions/setup-node@v6
28+
with:
29+
node-version: 20
30+
registry-url: "https://registry.npmjs.org"
31+
32+
- run: npm install -g npm@latest
33+
34+
- name: Deprecate version
35+
env:
36+
VERSION_EXPR: ${{ github.event.inputs.version-expression }}
37+
RATIONALE: ${{ github.event.inputs.rationale }}
38+
run: npm deprecate "sf-git-merge-driver@${VERSION_EXPR}" "$RATIONALE"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
name: Manage versions
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version-alias:
8+
description: version alias to map to a version number
9+
required: true
10+
type: choice
11+
options:
12+
- stable
13+
- latest
14+
- latest-rc
15+
version-number:
16+
description: version number (semver format)
17+
required: true
18+
default: vX.Y.Z
19+
type: string
20+
21+
permissions:
22+
contents: read
23+
id-token: write
24+
25+
jobs:
26+
add-tag:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout sources
30+
uses: actions/checkout@v6
31+
32+
- name: Setup node
33+
uses: actions/setup-node@v6
34+
with:
35+
node-version: 20
36+
registry-url: "https://registry.npmjs.org"
37+
38+
- run: npm install -g npm@latest
39+
40+
- name: Add dist-tag
41+
env:
42+
VERSION_NUMBER: ${{ github.event.inputs.version-number }}
43+
VERSION_ALIAS: ${{ github.event.inputs.version-alias }}
44+
run: npm dist-tag add "sf-git-merge-driver@${VERSION_NUMBER}" "$VERSION_ALIAS"

.github/workflows/npm-publish.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
name: NPM Publish
3+
4+
on:
5+
release:
6+
types: [published]
7+
pull_request:
8+
branches: [main]
9+
types: [opened, synchronize, reopened]
10+
paths-ignore:
11+
- "**.md"
12+
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
# Manage concurrency to stop running jobs and start new ones in case of new commit pushed
18+
concurrency:
19+
group: ${{ github.ref }}-${{ github.workflow }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
# Dev publish on PR
24+
publish-dev:
25+
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
26+
runs-on: ubuntu-latest
27+
outputs:
28+
channel: ${{ steps.publish.outputs.channel }}
29+
permissions:
30+
id-token: write
31+
contents: read
32+
pull-requests: write
33+
steps:
34+
- uses: actions/checkout@v6
35+
- uses: actions/setup-node@v6
36+
with:
37+
node-version: 20
38+
registry-url: "https://registry.npmjs.org"
39+
- run: npm install -g npm@latest
40+
- uses: ./.github/actions/install
41+
- name: Compute dev version
42+
id: version
43+
run: |
44+
CURRENT_VERSION=$(jq -r '.version' package.json)
45+
DEV_CHANNEL="dev-${{ github.event.pull_request.number }}"
46+
DEV_VERSION="${CURRENT_VERSION}-${DEV_CHANNEL}.${{ github.run_id }}-${{ github.run_attempt }}"
47+
echo "channel=$DEV_CHANNEL" >> "$GITHUB_OUTPUT"
48+
echo "version=$DEV_VERSION" >> "$GITHUB_OUTPUT"
49+
- name: Set version
50+
env:
51+
DEV_CHANNEL: ${{ steps.version.outputs.channel }}
52+
run: |
53+
git config --global user.email "${DEV_CHANNEL}@github.com"
54+
git config --global user.name "$DEV_CHANNEL"
55+
npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
56+
- name: Publish
57+
id: publish
58+
env:
59+
CHANNEL: ${{ steps.version.outputs.channel }}
60+
run: |
61+
npm publish --provenance --access public --tag "$CHANNEL"
62+
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
63+
- name: Comment PR
64+
uses: thollander/actions-comment-pull-request@v3
65+
env:
66+
DEV_CHANNEL: ${{ steps.version.outputs.channel }}
67+
with:
68+
message: |
69+
Published under `${{ env.DEV_CHANNEL }}` npm channel.
70+
```sh
71+
$ sf plugins install sf-git-merge-driver@${{ env.DEV_CHANNEL }}
72+
```
73+
comment-tag: dev-publish
74+
mode: recreate
75+
76+
# Release publish on release event
77+
publish-release:
78+
if: github.event_name == 'release'
79+
runs-on: ubuntu-latest
80+
outputs:
81+
channel: ${{ github.event.release.tag_name }}
82+
permissions:
83+
id-token: write
84+
contents: read
85+
steps:
86+
- uses: actions/checkout@v6
87+
- uses: actions/setup-node@v6
88+
with:
89+
node-version: 20
90+
registry-url: "https://registry.npmjs.org"
91+
- run: npm install -g npm@latest
92+
- uses: ./.github/actions/install
93+
- name: Publish
94+
run: npm publish --provenance --access public --tag latest-rc
95+
96+
# E2E tests after dev publish
97+
e2e-dev:
98+
needs: [publish-dev]
99+
if: github.event_name == 'pull_request'
100+
uses: ./.github/workflows/run-e2e-tests.yml
101+
with:
102+
channel: ${{ needs.publish-dev.outputs.channel }}
103+
104+
# E2E tests after release publish
105+
e2e-release:
106+
needs: [publish-release]
107+
if: github.event_name == 'release'
108+
uses: ./.github/workflows/run-e2e-tests.yml
109+
with:
110+
channel: ${{ needs.publish-release.outputs.channel }}

.github/workflows/npm-publisher.yml

Lines changed: 0 additions & 169 deletions
This file was deleted.

0 commit comments

Comments
 (0)