Skip to content

Commit 577af0a

Browse files
fix: tolerate npm eventual consistency after publish
1 parent 8d2808c commit 577af0a

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

.github/workflows/publish.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
5353
- name: Verify published version
5454
run: |
55+
set -euo pipefail
56+
5557
TAG="${{ steps.inputs.outputs.tag }}"
5658
if [ -z "$TAG" ]; then
5759
TAG="latest"
@@ -61,15 +63,35 @@ jobs:
6163
VERSION="$(node -p 'require("./package.json").version')"
6264
echo "Checking npm dist-tag '$TAG' for ${NAME}@${VERSION}..."
6365
64-
if ! npm view "${NAME}@${VERSION}" version >/dev/null 2>&1; then
65-
echo "[ERROR] npm does not report ${NAME}@${VERSION} after publish"
66-
exit 1
67-
fi
66+
# npm registry can be eventually consistent right after publish.
67+
# Give it a short window to make the new version visible.
68+
for i in $(seq 1 20); do
69+
if npm view "${NAME}@${VERSION}" version >/dev/null 2>&1; then
70+
break
71+
fi
6872
69-
DIST_VERSION="$(npm view "${NAME}" dist-tags."${TAG}" 2>/dev/null || true)"
70-
if [ -n "$DIST_VERSION" ] && [ "$DIST_VERSION" != "$VERSION" ]; then
71-
echo "[ERROR] dist-tag '$TAG' points to $DIST_VERSION (expected $VERSION)"
72-
exit 1
73-
fi
73+
if [ "$i" -eq 20 ]; then
74+
echo "[ERROR] npm does not report ${NAME}@${VERSION} after publish"
75+
exit 1
76+
fi
77+
78+
echo "Waiting for npm to show ${NAME}@${VERSION} (${i}/20)..."
79+
sleep 3
80+
done
81+
82+
for i in $(seq 1 20); do
83+
DIST_VERSION="$(npm view "${NAME}" dist-tags."${TAG}" 2>/dev/null || true)"
84+
if [ -n "$DIST_VERSION" ] && [ "$DIST_VERSION" = "$VERSION" ]; then
85+
break
86+
fi
87+
88+
if [ "$i" -eq 20 ]; then
89+
echo "[ERROR] dist-tag '$TAG' points to ${DIST_VERSION:-<empty>} (expected $VERSION)"
90+
exit 1
91+
fi
92+
93+
echo "Waiting for dist-tag '$TAG' to update (${i}/20)..."
94+
sleep 3
95+
done
7496
7597
echo "✓ npm publish verification passed"

0 commit comments

Comments
 (0)