Skip to content

Commit fdd8a31

Browse files
scolladonclaude
andcommitted
refactor: simplify npm-publisher as synchronous reusable workflow
Convert npm-publisher from workflow_run trigger to workflow_call reusable workflow for better visibility in PR checks and synchronous execution. - Replace workflow_run with workflow_call for synchronous execution - Add inputs: action, version-tag, version-expression, deprecation-message, ref - Update on-pull-request to call npm-publisher directly with e2e tests - Update on-main-push to call npm-publisher directly with e2e tests - Update on-merged-pull-request to call npm-publisher for cleanup - Remove commit status polling from run-e2e-tests (no longer needed) - Bump actions/cache and actions/upload-artifact versions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bbdef9c commit fdd8a31

File tree

7 files changed

+120
-253
lines changed

7 files changed

+120
-253
lines changed

.github/actions/install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ runs:
1010
run: echo "dir=$(npm config get cache)" >> "$GITHUB_OUTPUT"
1111
shell: bash
1212

13-
- uses: actions/cache@v4
13+
- uses: actions/cache@v5
1414
with:
1515
path: ${{ steps.cache-dir.outputs.dir }}
1616
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

.github/workflows/npm-publisher.yml

Lines changed: 71 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22
name: NPM Publisher
33

44
on:
5-
repository_dispatch:
6-
types:
7-
- npm-publish-release
8-
- npm-publish-dev
9-
- npm-dist-tag-add
10-
- npm-dist-tag-rm
11-
- npm-deprecate
5+
workflow_call:
6+
inputs:
7+
action:
8+
type: string
9+
required: true
10+
description: "Operation to perform: publish, deprecate, dist-tag-add, dist-tag-rm"
11+
version-tag:
12+
type: string
13+
required: false
14+
description: "npm tag (e.g., latest-rc, dev-166)"
15+
version-expression:
16+
type: string
17+
required: false
18+
description: "Version or semver range for deprecate/dist-tag operations"
19+
deprecation-message:
20+
type: string
21+
required: false
22+
description: "Deprecation message"
23+
ref:
24+
type: string
25+
required: false
26+
default: ''
27+
description: "Git ref to checkout for publish"
1228
workflow_dispatch:
1329
inputs:
1430
action:
@@ -19,43 +35,32 @@ on:
1935
- dist-tag-add
2036
- dist-tag-rm
2137
- deprecate
22-
tag:
38+
version-tag:
2339
description: "npm tag (for dist-tag operations)"
2440
required: false
2541
type: string
26-
version:
42+
version-expression:
2743
description: "Version or semver range"
2844
required: false
2945
type: string
30-
message:
46+
deprecation-message:
3147
description: "Deprecation message (empty to un-deprecate)"
3248
required: false
3349
type: string
3450

3551
permissions:
3652
contents: read
3753
id-token: write
38-
statuses: write
3954

4055
jobs:
41-
publish-release:
42-
if: github.event_name == 'repository_dispatch' && github.event.action == 'npm-publish-release'
56+
publish:
57+
if: ${{ inputs.action == 'publish' }}
4358
runs-on: ubuntu-latest
4459
steps:
45-
- name: Set pending commit status
46-
if: ${{ github.event.client_payload.ref != '' }}
47-
env:
48-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
SHA: ${{ github.event.client_payload.ref }}
50-
run: |
51-
gh api repos/${{ github.repository }}/statuses/$SHA \
52-
-f state=pending \
53-
-f context=npm-publish-release \
54-
-f description="Publishing release to npm..." \
55-
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
56-
5760
- name: Checkout sources
5861
uses: actions/checkout@v6
62+
with:
63+
ref: ${{ inputs.ref || github.sha }}
5964

6065
- name: Setup node
6166
uses: actions/setup-node@v6
@@ -69,54 +74,34 @@ jobs:
6974
- name: Setup dependencies, cache and install
7075
uses: ./.github/actions/install
7176

72-
- name: Publish to npm
77+
- name: Setup git user for dev version
78+
if: ${{ startsWith(inputs.version-tag, 'dev-') }}
7379
env:
74-
NPM_TAG: ${{ github.event.client_payload.tag || 'latest-rc' }}
75-
run: npm publish --provenance --access public --tag "$NPM_TAG"
80+
VERSION_TAG: ${{ inputs.version-tag }}
81+
run: |
82+
git config --global user.email "${VERSION_TAG}@github.com"
83+
git config --global user.name "$VERSION_TAG"
7684
77-
- name: Set success commit status
78-
if: ${{ success() && github.event.client_payload.ref != '' }}
85+
- name: Compute and set dev version
86+
if: ${{ startsWith(inputs.version-tag, 'dev-') }}
7987
env:
80-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81-
SHA: ${{ github.event.client_payload.ref }}
88+
VERSION_TAG: ${{ inputs.version-tag }}
8289
run: |
83-
gh api repos/${{ github.repository }}/statuses/$SHA \
84-
-f state=success \
85-
-f context=npm-publish-release \
86-
-f description="Release published to npm" \
87-
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
88-
89-
- name: Set failure commit status
90-
if: ${{ failure() && github.event.client_payload.ref != '' }}
90+
CURRENT_VERSION=$(jq -r '.version' package.json)
91+
DEV_VERSION="${CURRENT_VERSION}-${VERSION_TAG}.${{ github.run_id }}-${{ github.run_attempt }}"
92+
npm version "$DEV_VERSION" --no-git-tag-version
93+
94+
- name: Publish to npm
9195
env:
92-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93-
SHA: ${{ github.event.client_payload.ref }}
94-
run: |
95-
gh api repos/${{ github.repository }}/statuses/$SHA \
96-
-f state=failure \
97-
-f context=npm-publish-release \
98-
-f description="Failed to publish release" \
99-
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
100-
101-
publish-dev:
102-
if: github.event_name == 'repository_dispatch' && github.event.action == 'npm-publish-dev'
96+
VERSION_TAG: ${{ inputs.version-tag }}
97+
run: npm publish --provenance --access public --tag "$VERSION_TAG"
98+
99+
deprecate:
100+
if: ${{ inputs.action == 'deprecate' }}
103101
runs-on: ubuntu-latest
104102
steps:
105-
- name: Set pending commit status
106-
env:
107-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108-
SHA: ${{ github.event.client_payload.ref }}
109-
run: |
110-
gh api repos/${{ github.repository }}/statuses/$SHA \
111-
-f state=pending \
112-
-f context=npm-publish-dev \
113-
-f description="Publishing dev version to npm..." \
114-
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
115-
116103
- name: Checkout sources
117104
uses: actions/checkout@v6
118-
with:
119-
ref: ${{ github.event.client_payload.ref }}
120105

121106
- name: Setup node
122107
uses: actions/setup-node@v6
@@ -127,57 +112,21 @@ jobs:
127112
- name: Upgrade npm for trusted publishing support
128113
run: npm install -g npm@latest
129114

130-
- name: Setup dependencies, cache and install
131-
uses: ./.github/actions/install
132-
133-
- name: Setup git user
134-
env:
135-
DEV_CHANNEL: ${{ github.event.client_payload.dev_channel }}
136-
run: |
137-
git config --global user.email "${DEV_CHANNEL}@github.com"
138-
git config --global user.name "$DEV_CHANNEL"
139-
140-
- name: Compute and set dev version
141-
env:
142-
DEV_CHANNEL: ${{ github.event.client_payload.dev_channel }}
143-
run: |
144-
CURRENT_VERSION=$(jq -r '.version' package.json)
145-
DEV_TAG="${DEV_CHANNEL}.${{ github.run_id }}-${{ github.run_attempt }}"
146-
npm version "${CURRENT_VERSION}-${DEV_TAG}" --no-git-tag-version
147-
148-
- name: Publish dev version to npm
115+
- name: Remove dist-tag
116+
if: ${{ inputs.version-tag != '' }}
149117
env:
150-
DEV_CHANNEL: ${{ github.event.client_payload.dev_channel }}
151-
run: npm publish --provenance --access public --tag "$DEV_CHANNEL"
118+
VERSION_TAG: ${{ inputs.version-tag }}
119+
run: npm dist-tag rm sf-git-merge-driver "$VERSION_TAG" || true
152120

153-
- name: Set success commit status
154-
if: success()
155-
env:
156-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157-
SHA: ${{ github.event.client_payload.ref }}
158-
run: |
159-
gh api repos/${{ github.repository }}/statuses/$SHA \
160-
-f state=success \
161-
-f context=npm-publish-dev \
162-
-f description="Dev version published to npm" \
163-
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
164-
165-
- name: Set failure commit status
166-
if: failure()
121+
- name: Deprecate version(s)
122+
if: ${{ inputs.version-expression != '' }}
167123
env:
168-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169-
SHA: ${{ github.event.client_payload.ref }}
170-
run: |
171-
gh api repos/${{ github.repository }}/statuses/$SHA \
172-
-f state=failure \
173-
-f context=npm-publish-dev \
174-
-f description="Failed to publish dev version" \
175-
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
124+
VERSION_EXPR: ${{ inputs.version-expression }}
125+
MESSAGE: ${{ inputs.deprecation-message }}
126+
run: npm deprecate "sf-git-merge-driver@${VERSION_EXPR}" "$MESSAGE"
176127

177128
dist-tag-add:
178-
if: |
179-
(github.event_name == 'repository_dispatch' && github.event.action == 'npm-dist-tag-add') ||
180-
(github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'dist-tag-add')
129+
if: ${{ inputs.action == 'dist-tag-add' }}
181130
runs-on: ubuntu-latest
182131
steps:
183132
- name: Checkout sources
@@ -189,16 +138,17 @@ jobs:
189138
node-version: 20
190139
registry-url: "https://registry.npmjs.org"
191140

141+
- name: Upgrade npm for trusted publishing support
142+
run: npm install -g npm@latest
143+
192144
- name: Add dist-tag
193145
env:
194-
VERSION: ${{ github.event.client_payload.version || github.event.inputs.version }}
195-
TAG: ${{ github.event.client_payload.tag || github.event.inputs.tag }}
196-
run: npm dist-tag add "sf-git-merge-driver@${VERSION}" "$TAG"
146+
VERSION_EXPR: ${{ inputs.version-expression }}
147+
VERSION_TAG: ${{ inputs.version-tag }}
148+
run: npm dist-tag add "sf-git-merge-driver@${VERSION_EXPR}" "$VERSION_TAG"
197149

198150
dist-tag-rm:
199-
if: |
200-
(github.event_name == 'repository_dispatch' && github.event.action == 'npm-dist-tag-rm') ||
201-
(github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'dist-tag-rm')
151+
if: ${{ inputs.action == 'dist-tag-rm' }}
202152
runs-on: ubuntu-latest
203153
steps:
204154
- name: Checkout sources
@@ -210,28 +160,10 @@ jobs:
210160
node-version: 20
211161
registry-url: "https://registry.npmjs.org"
212162

213-
- name: Remove dist-tag
214-
env:
215-
TAG: ${{ github.event.client_payload.tag || github.event.inputs.tag }}
216-
run: npm dist-tag rm sf-git-merge-driver "$TAG"
217-
218-
deprecate:
219-
if: |
220-
(github.event_name == 'repository_dispatch' && github.event.action == 'npm-deprecate') ||
221-
(github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'deprecate')
222-
runs-on: ubuntu-latest
223-
steps:
224-
- name: Checkout sources
225-
uses: actions/checkout@v6
226-
227-
- name: Setup node
228-
uses: actions/setup-node@v6
229-
with:
230-
node-version: 20
231-
registry-url: "https://registry.npmjs.org"
163+
- name: Upgrade npm for trusted publishing support
164+
run: npm install -g npm@latest
232165

233-
- name: Deprecate version(s)
166+
- name: Remove dist-tag
234167
env:
235-
VERSION: ${{ github.event.client_payload.version || github.event.inputs.version }}
236-
MESSAGE: ${{ github.event.client_payload.message || github.event.inputs.message }}
237-
run: npm deprecate "sf-git-merge-driver@${VERSION}" "$MESSAGE"
168+
VERSION_TAG: ${{ inputs.version-tag }}
169+
run: npm dist-tag rm sf-git-merge-driver "$VERSION_TAG"

.github/workflows/on-main-push.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
release_created: ${{ steps.release.outputs.release_created }}
2525
prs_created: ${{ steps.release.outputs.prs_created }}
2626
version: ${{ steps.release.outputs.version }}
27+
permissions:
28+
contents: write
29+
pull-requests: write
2730
steps:
2831
- uses: googleapis/release-please-action@v4
2932
id: release
@@ -33,21 +36,16 @@ jobs:
3336

3437
release:
3538
needs: [prepare-release]
36-
runs-on: ubuntu-latest
3739
if: ${{ needs.prepare-release.outputs.release_created == 'true' }}
38-
steps:
39-
- name: Trigger npm publish
40-
uses: peter-evans/repository-dispatch@v3
41-
with:
42-
token: ${{ secrets.RELEASE_PAT }}
43-
event-type: npm-publish-release
44-
client-payload: '{"tag": "latest-rc", "ref": "${{ github.sha }}"}'
40+
uses: ./.github/workflows/npm-publisher.yml
41+
with:
42+
action: publish
43+
version-tag: latest-rc
44+
ref: ${{ github.sha }}
4545

4646
test-release:
47-
uses: ./.github/workflows/run-e2e-tests.yml
4847
needs: [prepare-release, release]
48+
if: ${{ needs.prepare-release.outputs.release_created == 'true' }}
49+
uses: ./.github/workflows/run-e2e-tests.yml
4950
with:
5051
channel: ${{ needs.prepare-release.outputs.version }}
51-
commit_sha: ${{ github.sha }}
52-
status_context: npm-publish-release
53-
secrets: inherit

0 commit comments

Comments
 (0)