Skip to content

Commit 6488ba3

Browse files
committed
ci(npm): gate main publish on all platform packages existing
npm publishes aren't transactional, so guarantee the consumer-facing invariant instead: publish @zerops/zcli only after verifying all five platform packages exist at the target version, so its optionalDependencies can never resolve to a missing package. Platform publishes now skip versions already on the registry, making a re-run after a partial failure complete without bumping the version.
1 parent 4401ab5 commit 6488ba3

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,44 @@ jobs:
8787
--version "$NPM_VERSION" \
8888
--out "$GITHUB_WORKSPACE/dist-npm"
8989
90-
# Platform packages must be published before the main package, otherwise its
91-
# optionalDependencies can't be resolved on install.
90+
# npm publishes aren't transactional, so we enforce the consumer-facing invariant
91+
# instead: publish the main package only after all platform packages exist at this
92+
# version, so its optionalDependencies can never resolve to a missing package.
93+
# Platform publishes are idempotent (skip versions already on the registry) so a
94+
# re-run after a partial failure completes cleanly without bumping the version.
9295
- name: Publish platform packages
9396
env:
9497
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
9598
run: |
9699
for dir in "$GITHUB_WORKSPACE"/dist-npm/*/; do
100+
name="$(node -p "require('$dir/package.json').name")"
101+
if npm view "$name@$NPM_VERSION" version >/dev/null 2>&1; then
102+
echo "$name@$NPM_VERSION already published, skipping"
103+
continue
104+
fi
97105
npm publish "$dir" --access=public --tag "$NPM_TAG"
98106
done
99107
108+
- name: Verify all platform packages are published
109+
run: |
110+
for dir in "$GITHUB_WORKSPACE"/dist-npm/*/; do
111+
name="$(node -p "require('$dir/package.json').name")"
112+
ok=0
113+
for i in $(seq 1 12); do
114+
if npm view "$name@$NPM_VERSION" version >/dev/null 2>&1; then
115+
ok=1
116+
break
117+
fi
118+
echo "waiting for $name@$NPM_VERSION to be resolvable..."
119+
sleep 5
120+
done
121+
if [ "$ok" -ne 1 ]; then
122+
echo "::error::$name@$NPM_VERSION is not on the registry; refusing to publish the main package"
123+
exit 1
124+
fi
125+
done
126+
echo "all platform packages present at $NPM_VERSION"
127+
100128
- name: Publish main package
101129
env:
102130
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)