From b437c5c87e707f68e6feea1d1ee36fff5617556c Mon Sep 17 00:00:00 2001 From: JasterV <49537445+JasterV@users.noreply.github.com> Date: Sat, 7 Mar 2026 00:58:12 +0100 Subject: [PATCH] fix: do not release crates that have `publish = false` --- rust/magic-release.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/rust/magic-release.sh b/rust/magic-release.sh index 25919f9..c7f07eb 100755 --- a/rust/magic-release.sh +++ b/rust/magic-release.sh @@ -1,17 +1,21 @@ #!/bin/sh set -e -# --- 1. Configuration --- +# --- Configuration --- TOKEN="${PLUGIN_TOKEN}" CRATES_TOKEN="${PLUGIN_CRATES_IO_TOKEN}" REPO_FULL_NAME="${CI_REPO}" API_URL="https://codeberg.org/api/v1/repos/${REPO_FULL_NAME}" -# --- 2. Get Workspace Packages in Topological Order --- -# Requires 'jq' to be installed in the environment -PACKAGES=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | .[] | "\(.name) \(.version) \(.manifest_path)"') +# --- Get Workspace Packages in Topological Order --- +PACKAGES=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | .[] | select(.publish != []) | "\(.name) \(.version) \(.manifest_path)"') -echo "Starting independent release process..." +if [ -z "$PACKAGES" ]; then + echo "No publishable packages found in workspace." + exit 0 +fi + +echo "Starting release process..." # --- 3. Process each package --- echo "$PACKAGES" | while read -r PKG_NAME PKG_VERSION MANIFEST_PATH; do @@ -19,7 +23,7 @@ echo "$PACKAGES" | while read -r PKG_NAME PKG_VERSION MANIFEST_PATH; do TAG_NAME="${PKG_NAME}-v${PKG_VERSION}" echo "--- Checking $PKG_NAME ($PKG_VERSION) ---" - # A. Check if this version is already on crates.io + # Check if this version is already on crates.io status_code=$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/${PKG_NAME}/${PKG_VERSION}") if [ "$status_code" = "200" ]; then @@ -29,7 +33,7 @@ echo "$PACKAGES" | while read -r PKG_NAME PKG_VERSION MANIFEST_PATH; do echo " - New version detected. Proceeding with release..." - # B. Create Git Tag if it doesn't exist + # Create Git Tag if it doesn't exist if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then echo " - Tag $TAG_NAME already exists locally/remotely." else @@ -39,7 +43,7 @@ echo "$PACKAGES" | while read -r PKG_NAME PKG_VERSION MANIFEST_PATH; do git push "https://$TOKEN@codeberg.org/${REPO_FULL_NAME}.git" "$TAG_NAME" fi - # C. Create Codeberg Release + # Create Codeberg Release # We check if the release exists via API first to avoid 409 errors RELEASE_CHECK=$(curl -s -H "Authorization: token $TOKEN" "$API_URL/releases/tags/$TAG_NAME") if echo "$RELEASE_CHECK" | grep -q "\"id\":"; then @@ -62,10 +66,10 @@ EOF -d "$RELEASE_PAYLOAD" > /dev/null fi - # D. Publish to Crates.io + # Publish to Crates.io echo " - Publishing $PKG_NAME to crates.io..." # --allow-dirty handles cases where the CI environment modified files (like lockfiles) cargo publish --token "$CRATES_TOKEN" -p "$PKG_NAME" --allow-dirty done -echo "--- All independent releases processed ---" +echo "--- All crates processed ---"