Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 19 additions & 42 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,57 +95,34 @@ jobs:
VERSION="${{ steps.release.outputs.version }}"
PUBLISHED_ANY=false

crate_version_exists() {
local crate="$1"
local version="$2"

local response
response="$(curl -sf "https://crates.io/api/v1/crates/${crate}" || true)"

if [ -z "$response" ]; then
return 1
fi

# Strip optional 'v' prefix for crates.io API (num is always bare like "0.1.1")
local bare_version="${version#v}"
echo "$response" |
jq -e --arg version "$bare_version" 'any(.versions[].num; . == $version)' >/dev/null
}

wait_for_crate() {
publish_crate() {
local crate="$1"
local version="$2"

echo "Waiting for $crate $version to become visible on crates.io..."
local output

for i in $(seq 1 60); do
echo "Attempt $i/60..."
echo "Publishing $crate $VERSION..."

if crate_version_exists "$crate" "$version"; then
echo "$crate $version is visible on crates.io"
# Let cargo publish decide — it uses the same local index as validation.
# If the version already exists in the index, cargo exits non-zero and
# prints "already exists" to stderr.
set +e
output="$(cargo publish -p "$crate" --token "$CARGO_REGISTRY_TOKEN" 2>&1)"
local exit_code=$?
set -e

if [ $exit_code -ne 0 ]; then
if echo "$output" | grep -q "already exists"; then
echo "$crate $VERSION already published — skipping"
return 0
fi

sleep 10
done

echo "Timed out waiting for $crate $version"
exit 1
}

publish_crate() {
local crate="$1"

if crate_version_exists "$crate" "$VERSION"; then
echo "$crate $VERSION already published — skipping"
return 0
echo "$output"
echo "cargo publish failed for $crate"
exit $exit_code
fi

echo "Publishing $crate $VERSION..."
cargo publish -p "$crate" --token "$CARGO_REGISTRY_TOKEN"

echo "$output"
echo "$crate $VERSION published successfully"
PUBLISHED_ANY=true
wait_for_crate "$crate" "$VERSION"
}

publish_crate xtax-encryption
Expand Down