fix: stable release時にnext dist-tagを自動同期

This commit is contained in:
nrslib 2026-02-10 10:08:35 +09:00
parent 8384027f21
commit b9f8addaea

View File

@ -52,12 +52,47 @@ jobs:
run: |
VERSION="${{ needs.tag.outputs.tag }}"
VERSION="${VERSION#v}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if echo "$VERSION" | grep -qE '(alpha|beta|rc|next)'; then
echo "tag=next" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
- run: npm publish --tag ${{ steps.npm-tag.outputs.tag }}
- name: Publish package
run: npm publish --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Sync next tag on stable release
if: steps.npm-tag.outputs.tag == 'latest'
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
VERSION="${{ steps.npm-tag.outputs.version }}"
for attempt in 1 2 3; do
if npm dist-tag add "${PACKAGE_NAME}@${VERSION}" next; then
exit 0
fi
if [ "$attempt" -eq 3 ]; then
echo "Failed to sync next tag after 3 attempts."
exit 1
fi
sleep $((attempt * 5))
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Verify dist-tags
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
LATEST=$(npm view "${PACKAGE_NAME}" dist-tags.latest)
NEXT=$(npm view "${PACKAGE_NAME}" dist-tags.next || true)
echo "latest=${LATEST}"
echo "next=${NEXT}"
if [ "${{ steps.npm-tag.outputs.tag }}" = "latest" ] && [ "${LATEST}" != "${NEXT}" ]; then
echo "Expected next to match latest on stable release, but they differ."
exit 1
fi