Skip to content

Commit 44a1147

Browse files
committed
ci(npm): fallback publish token for scoped packages
1 parent 0abd64f commit 44a1147

1 file changed

Lines changed: 44 additions & 6 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,34 @@ jobs:
203203
- name: Publish core to NPM
204204
if: steps.should-publish.outputs.should_publish == 'true'
205205
run: |
206-
# Create npmrc for authentication
207-
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_AIOX_SQUADS }}" > .npmrc
206+
publish_status=1
207+
for token in "$NPM_TOKEN_AIOX_SQUADS" "$NPM_TOKEN"; do
208+
if [ -z "$token" ]; then
209+
continue
210+
fi
211+
echo "//registry.npmjs.org/:_authToken=${token}" > .npmrc
212+
if npm publish --tag ${{ steps.publish-tag.outputs.tag }} --access public; then
213+
publish_status=0
214+
break
215+
else
216+
publish_status=$?
217+
fi
218+
done
208219
209-
# Publish with appropriate tag
210-
npm publish --tag ${{ steps.publish-tag.outputs.tag }} --access public
220+
if [ "$publish_status" -ne 0 ]; then
221+
rm -f .npmrc
222+
echo "::error::Unable to publish scoped core package. Refresh NPM_TOKEN_AIOX_SQUADS or NPM_TOKEN with owner access to @aiox-squads/core."
223+
exit "$publish_status"
224+
fi
211225
212226
PKG_NAME=$(node -p "require('./package.json').name")
213227
npm access set status=public "${PKG_NAME}" --registry="${NPM_REGISTRY}"
228+
rm -f .npmrc
214229
echo "✅ Published ${PKG_NAME}@${{ needs.build.outputs.version }} with tag ${{ steps.publish-tag.outputs.tag }}"
215230
env:
216231
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_AIOX_SQUADS }}
232+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
233+
NPM_TOKEN_AIOX_SQUADS: ${{ secrets.NPM_TOKEN_AIOX_SQUADS }}
217234

218235
- name: Verify publication
219236
if: steps.should-publish.outputs.should_publish == 'true'
@@ -323,12 +340,33 @@ jobs:
323340
if: steps.should-publish.outputs.should_publish == 'true'
324341
working-directory: ${{ matrix.path }}
325342
run: |
326-
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_AIOX_SQUADS }}" > .npmrc
327-
npm publish --tag ${{ steps.publish-tag.outputs.tag }} --access public
343+
publish_status=1
344+
for token in "$NPM_TOKEN_AIOX_SQUADS" "$NPM_TOKEN"; do
345+
if [ -z "$token" ]; then
346+
continue
347+
fi
348+
echo "//registry.npmjs.org/:_authToken=${token}" > .npmrc
349+
if npm publish --tag ${{ steps.publish-tag.outputs.tag }} --access public; then
350+
publish_status=0
351+
break
352+
else
353+
publish_status=$?
354+
fi
355+
done
356+
357+
if [ "$publish_status" -ne 0 ]; then
358+
rm -f .npmrc
359+
echo "::error::Unable to publish ${{ steps.pkg.outputs.name }}. Refresh NPM_TOKEN_AIOX_SQUADS or NPM_TOKEN with owner access to the @aiox-squads scope."
360+
exit "$publish_status"
361+
fi
362+
328363
npm access set status=public "${{ steps.pkg.outputs.name }}" --registry="${NPM_REGISTRY}"
364+
rm -f .npmrc
329365
echo "✅ Published ${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}"
330366
env:
331367
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_AIOX_SQUADS }}
368+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
369+
NPM_TOKEN_AIOX_SQUADS: ${{ secrets.NPM_TOKEN_AIOX_SQUADS }}
332370

333371
- name: Smoke test - verify npx works
334372
if: steps.should-publish.outputs.should_publish == 'true'

0 commit comments

Comments
 (0)