Skip to content

Commit 9458201

Browse files
committed
fix(publish): 🩹 use cargo index checks for crates visibility
1 parent d8dd8e5 commit 9458201

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,29 @@ jobs:
9494
echo "$version"
9595
}
9696
97-
crate_status_code() {
97+
crate_registry_state() {
9898
local pkg="$1"
9999
local version="$2"
100-
curl -sS -o /dev/null -w '%{http_code}' "https://crates.io/api/v1/crates/${pkg}/${version}"
100+
local output
101+
local cmd_status
102+
103+
set +e
104+
output="$(cargo info "${pkg}@${version}" --registry crates-io 2>&1)"
105+
cmd_status=$?
106+
set -e
107+
108+
if [[ "$cmd_status" -eq 0 ]]; then
109+
echo "present"
110+
return 0
111+
fi
112+
113+
if grep -qi "could not find" <<< "$output"; then
114+
echo "missing"
115+
return 0
116+
fi
117+
118+
echo "::error::Failed to query crates.io index for ${pkg} ${version}: ${output}" >&2
119+
return 1
101120
}
102121
103122
ensure_crate_visible() {
@@ -107,22 +126,18 @@ jobs:
107126
local sleep_seconds=10
108127
109128
for ((attempt = 1; attempt <= max_attempts; attempt++)); do
110-
http_code="$(crate_status_code "$pkg" "$version")"
111-
case "$http_code" in
112-
200)
129+
state="$(crate_registry_state "$pkg" "$version")"
130+
case "$state" in
131+
present)
113132
echo "${pkg} ${version} is visible on crates.io."
114133
return 0
115134
;;
116-
404)
135+
missing)
117136
echo "Waiting for ${pkg} ${version} to become visible on crates.io (${attempt}/${max_attempts})..."
118137
sleep "$sleep_seconds"
119138
;;
120-
5??)
121-
echo "::error::crates.io returned ${http_code} while checking ${pkg} ${version}."
122-
return 1
123-
;;
124139
*)
125-
echo "::error::Unexpected crates.io status ${http_code} while checking ${pkg} ${version}."
140+
echo "::error::Unexpected crates.io registry state '${state}' while checking ${pkg} ${version}."
126141
return 1
127142
;;
128143
esac
@@ -156,24 +171,20 @@ jobs:
156171
continue
157172
fi
158173
159-
http_code="$(crate_status_code "$pkg" "$version")"
160-
case "$http_code" in
161-
200)
174+
state="$(crate_registry_state "$pkg" "$version")"
175+
case "$state" in
176+
present)
162177
if [[ "$SKIP_PUBLISHED" == "true" ]]; then
163178
echo "Skipping ${pkg} ${version}; version already exists on crates.io."
164179
continue
165180
fi
166181
echo "::error::${pkg} ${version} already exists on crates.io."
167182
exit 1
168183
;;
169-
404)
170-
;;
171-
5??)
172-
echo "::error::crates.io returned ${http_code} while checking ${pkg} ${version}."
173-
exit 1
184+
missing)
174185
;;
175186
*)
176-
echo "::error::Unexpected crates.io status ${http_code} while checking ${pkg} ${version}."
187+
echo "::error::Unexpected crates.io registry state '${state}' while checking ${pkg} ${version}."
177188
exit 1
178189
;;
179190
esac

0 commit comments

Comments
 (0)