Visitar URL original
fix(release): publish platform packages before the cli package (#63124) · anomalyco/opencode@8f0bf22 · GitHub
Skip to content

Commit 8f0bf22

Browse files
authored
fix(release): publish platform packages before the cli package (#63124)
1 parent c1aa4e2 commit 8f0bf22

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

‎.github/release/publish-npm.sh‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,46 @@ for file in "${files[@]}"; do
4444
done
4545
for name in $expected; do cut -f1 "$list" | grep -qxF -- "$name" || die "Missing package $name"; done
4646

47-
# The CLI wrappers resolve their platform packages, so they publish last.
48-
order=$(mktemp)
49-
{ grep -vP '^@opencode/cli(-node)?\t' "$list" || true; grep -P '^@opencode/cli(-node)?\t' "$list"; } > "$order"
50-
cat "$order"
47+
# The CLI wrappers resolve their platform packages from postinstall, so they publish last.
48+
packages=$(mktemp)
49+
wrappers=$(mktemp)
50+
grep -vP '^@opencode/cli(-node)?\t' "$list" > "$packages" || true
51+
grep -P '^@opencode/cli(-node)?\t' "$list" > "$wrappers" || true
52+
cat "$packages" "$wrappers"
5153

5254
# A clean directory and config, so nothing from an artifact can redirect the registry.
5355
printf 'registry=https://registry.npmjs.org/\n' > "$RUNNER_TEMP/npmrc"
5456
export NPM_CONFIG_USERCONFIG="$RUNNER_TEMP/npmrc"
5557
cd "$(mktemp -d)"
5658
flags=(--tag "$OPENCODE_NPM_TAG" --access public --ignore-scripts)
5759
if dry_run; then flags+=(--dry-run); else flags+=(--provenance); fi
58-
while IFS=$'\t' read -r name file; do
59-
if ! dry_run && npm view "$name@$OPENCODE_VERSION" version > /dev/null 2>&1; then
60-
echo "already published $name@$OPENCODE_VERSION"
61-
continue
62-
fi
63-
npm publish "$file" "${flags[@]}"
64-
done < "$order"
60+
61+
publish() {
62+
while IFS=$'\t' read -r name file; do
63+
if ! dry_run && npm view "$name@$OPENCODE_VERSION" version > /dev/null 2>&1; then
64+
echo "already published $name@$OPENCODE_VERSION"
65+
continue
66+
fi
67+
npm publish "$file" "${flags[@]}"
68+
done < "$1"
69+
}
70+
71+
# npm publish returns while the registry is still processing the version: a large platform tarball can take ten
72+
# minutes to become available, and versions appear out of publish order. A wrapper published in that window makes
73+
# its postinstall fail with ETARGET, and rolling the dist-tag back does not repair an install that already failed,
74+
# so wait for every other package to resolve at this version before publishing the wrappers.
75+
wait_for_registry() {
76+
if dry_run; then return; fi
77+
while IFS= read -r name; do
78+
for attempt in $(seq 1 180); do
79+
if npm view --prefer-online "$name@$OPENCODE_VERSION" version > /dev/null 2>&1; then break; fi
80+
if [ "$attempt" = 180 ]; then die "$name@$OPENCODE_VERSION did not appear in the registry"; fi
81+
echo "waiting for $name@$OPENCODE_VERSION"
82+
sleep 10
83+
done
84+
done < <(cut -f1 "$1")
85+
}
86+
87+
publish "$packages"
88+
wait_for_registry "$packages"
89+
publish "$wrappers"

0 commit comments

Comments
 (0)