Skip to content

Commit 5d4178e

Browse files
committed
fix(ci): surface crates.io publish auth failures and require token before verify
1 parent 45a51e5 commit 5d4178e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

.github/workflows/publish-to-crates-io.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ jobs:
9393
fi
9494
echo "Tag/version match: $ws_ver"
9595
96+
- name: Check crates.io token is present
97+
# Fail fast - before the ~4.5 min verified dry-run - when the repo secret
98+
# `CRATES_IO_TOKEN` is missing/empty. Otherwise cargo publish fails only
99+
# after verification with an opaque auth error.
100+
run: |
101+
if [ -z "${CARGO_REGISTRY_TOKEN:-}" ]; then
102+
echo "CRATES_IO_TOKEN repo secret is not set (or is empty) - add a crates.io API token at GitHub repo Settings -> Secrets and variables -> Actions." >&2
103+
exit 1
104+
fi
105+
echo "crates.io token present"
106+
96107
- name: Pre-publish verification (full verify, all members)
97108
# Release policy: never publish without verify. `cargo publish
98109
# --workspace --dry-run` packages every publishable member and
@@ -145,7 +156,10 @@ jobs:
145156
if cargo publish --workspace --allow-dirty "${excludes[@]}" >>"$log" 2>&1; then
146157
echo "=== publish complete at $ver ==="; exit 0
147158
fi
148-
ra=$(grep -o 'try again after [A-Za-z]*, [0-9]* [A-Za-z]* [0-9]* [0-9:]* GMT' "$log" | tail -n 1 | sed 's/try again after //')
159+
# `|| true` matters: the loop runs under `bash -e`, and a missing 429
160+
# in the log makes this assignment exit 1 — silently skipping the
161+
# diagnostic + log tail below. Keep the no-match case non-fatal.
162+
ra=$(grep -o 'try again after [A-Za-z]*, [0-9]* [A-Za-z]* [0-9]* [0-9:]* GMT' "$log" | tail -n 1 | sed 's/try again after //' || true)
149163
if [ -n "$ra" ]; then
150164
ra_epoch=$(date -d "$ra" +%s) || { echo "::error::unparseable retry-after: $ra"; exit 1; }
151165
sleep_s=$(( ra_epoch - $(date +%s) + 120 ))

0 commit comments

Comments
 (0)