22name : NPM Publisher
33
44on :
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 :
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
3551permissions :
3652 contents : read
3753 id-token : write
38- statuses : write
3954
4055jobs :
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"
0 commit comments