@@ -44,21 +44,46 @@ for file in "${files[@]}"; do |
44 | 44 | done |
45 | 45 | for name in $expected; do cut -f1 "$list" | grep -qxF -- "$name" || die "Missing package $name"; done |
46 | 46 |
|
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" |
51 | 53 |
|
52 | 54 | # A clean directory and config, so nothing from an artifact can redirect the registry. |
53 | 55 | printf 'registry=https://registry.npmjs.org/\n' > "$RUNNER_TEMP/npmrc" |
54 | 56 | export NPM_CONFIG_USERCONFIG="$RUNNER_TEMP/npmrc" |
55 | 57 | cd "$(mktemp -d)" |
56 | 58 | flags=(--tag "$OPENCODE_NPM_TAG" --access public --ignore-scripts) |
57 | 59 | 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" |