From 386c2ab8011583d5acbc5ffef6fceffc78c00930 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Fri, 28 Aug 2026 08:50:58 -0700 Subject: [PATCH] Fix crates.io publish detection (#1781) * Fix crate publish existence check Signed-off-by: James Sturtevant * Extract crate publish check script Signed-off-by: James Sturtevant * Enforce LF endings for shell scripts Signed-off-by: James Sturtevant * Simplify crate publish script Signed-off-by: James Sturtevant * Move crate publish script to dev Signed-off-by: James Sturtevant * Keep crate publish script executable Signed-off-by: James Sturtevant --------- Signed-off-by: James Sturtevant --- .gitattributes | 1 + .github/workflows/CargoPublish.yml | 38 ++++++-------------- dev/crates-to-publish.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 28 deletions(-) create mode 100644 .gitattributes create mode 100755 dev/crates-to-publish.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..dfdb8b771c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.github/workflows/CargoPublish.yml b/.github/workflows/CargoPublish.yml index 5d97a89d8c..4b91fffad3 100644 --- a/.github/workflows/CargoPublish.yml +++ b/.github/workflows/CargoPublish.yml @@ -51,34 +51,16 @@ jobs: - name: Determine which crates need publishing run: | - needs_publish() { - local crate=$1 - local crate_env_var=$(echo "$crate" | tr '[:lower:]' '[:upper:]' | tr '-' '_') - - if [ -z "$VERSION" ]; then - echo "No version set (dry run?), skipping crates.io existence checks." - echo "PUBLISH_${crate_env_var}=true" >> "$GITHUB_ENV" - return - fi - - if curl -s "https://crates.io/api/v1/crates/$crate/$VERSION" | jq -e .version > /dev/null; then - echo "PUBLISH_${crate_env_var}=false" >> "$GITHUB_ENV" - echo "✅ $crate@$VERSION already exists." - else - echo "PUBLISH_${crate_env_var}=true" >> "$GITHUB_ENV" - echo "🚀 $crate@$VERSION will be published." - fi - } - - needs_publish hyperlight-libc - needs_publish hyperlight-common - needs_publish hyperlight-guest - needs_publish hyperlight-guest-macro - needs_publish hyperlight-guest-bin - needs_publish hyperlight-component-util - needs_publish hyperlight-component-macro - needs_publish hyperlight-host - needs_publish hyperlight-guest-tracing + ./dev/crates-to-publish.sh "$VERSION" \ + hyperlight-libc \ + hyperlight-common \ + hyperlight-guest \ + hyperlight-guest-macro \ + hyperlight-guest-bin \ + hyperlight-component-util \ + hyperlight-component-macro \ + hyperlight-host \ + hyperlight-guest-tracing >> "$GITHUB_ENV" - name: Authenticate with crates.io uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5 diff --git a/dev/crates-to-publish.sh b/dev/crates-to-publish.sh new file mode 100755 index 0000000000..a82b769987 --- /dev/null +++ b/dev/crates-to-publish.sh @@ -0,0 +1,58 @@ +#!/bin/bash +set -euo pipefail + +if [ "$#" -lt 2 ]; then + echo "Usage: $0 VERSION CRATE..." >&2 + exit 1 +fi + +VERSION=$1 +shift + +response_file=$(mktemp) +trap 'rm -f "$response_file"' EXIT + +for crate in "$@"; do + crate_env_var=${crate^^} + crate_env_var=${crate_env_var//-/_} + + if [ -z "$VERSION" ]; then + echo "No version set (dry run?), skipping crates.io existence checks." >&2 + echo "PUBLISH_${crate_env_var}=true" + continue + fi + + if ! http_status=$( + curl --silent --show-error \ + --user-agent 'hyperlight-release-workflow (https://github.com/hyperlight-dev/hyperlight)' \ + --retry 3 \ + --retry-all-errors \ + --connect-timeout 10 \ + --max-time 30 \ + --output "$response_file" \ + --write-out '%{http_code}' \ + "https://crates.io/api/v1/crates/$crate/$VERSION" + ); then + echo "Failed to query crates.io for $crate@$VERSION." >&2 + exit 1 + fi + + case "$http_status" in + 200) + if ! jq -e --arg version "$VERSION" '.version.num == $version' "$response_file" > /dev/null; then + echo "crates.io returned malformed or mismatched version data for $crate@$VERSION." >&2 + exit 1 + fi + echo "PUBLISH_${crate_env_var}=false" + echo "$crate@$VERSION already exists." >&2 + ;; + 404) + echo "PUBLISH_${crate_env_var}=true" + echo "$crate@$VERSION will be published." >&2 + ;; + *) + echo "crates.io returned HTTP $http_status for $crate@$VERSION." >&2 + exit 1 + ;; + esac +done