mirror of
https://codeberg.org/JasterV/docker.git
synced 2026-04-26 18:10:02 +00:00
87 lines
3 KiB
Bash
Executable file
87 lines
3 KiB
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
# --- 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}"
|
|
|
|
# Get workspace members in topological order (dependencies first)
|
|
# We use 'tac' because 'cargo tree' puts the "roots" at the top.
|
|
# Reversing it ensures "leaves" (dependencies) are published first.
|
|
ORDERED_CRATES=$(cargo tree --workspace --depth 0 --prefix none --format "{p}" | awk '{print $1}' | tac)
|
|
|
|
# Get all package metadata in one go
|
|
# Use jq to re-sort the metadata to match the ORDERED_NAMES
|
|
PACKAGES=$(cargo metadata --format-version 1 --no-deps | jq -r --arg names "$ORDERED_CRATES" '
|
|
($names | split("\n")) as $order
|
|
| [.packages[] | select(.publish != [])] as $pkgs
|
|
| $order[] as $name
|
|
| $pkgs[] | select(.name == $name)
|
|
| "\(.name) \(.version) \(.manifest_path)"
|
|
')
|
|
|
|
if [ -z "$PACKAGES" ]; then
|
|
echo "No publishable packages found."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Starting release process..."
|
|
|
|
# --- Process each package ---
|
|
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) ---"
|
|
|
|
# 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
|
|
echo " - $PKG_NAME v$PKG_VERSION is already published. Skipping."
|
|
continue
|
|
fi
|
|
|
|
echo " - New version detected. Proceeding with release..."
|
|
|
|
# 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
|
|
echo " - Tagging $TAG_NAME..."
|
|
git tag "$TAG_NAME"
|
|
# Use the token for authenticated push
|
|
git push "https://$TOKEN@codeberg.org/${REPO_FULL_NAME}.git" "$TAG_NAME"
|
|
fi
|
|
|
|
# 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
|
|
echo " - Codeberg release for $TAG_NAME already exists."
|
|
else
|
|
echo " - Creating Codeberg release for $TAG_NAME..."
|
|
RELEASE_PAYLOAD=$(cat <<EOF
|
|
{
|
|
"tag_name": "$TAG_NAME",
|
|
"name": "$PKG_NAME v$PKG_VERSION",
|
|
"body": "Automated release for crate **$PKG_NAME** at version \`$PKG_VERSION\`. \n\nSee CHANGELOG.md for details.",
|
|
"draft": false,
|
|
"prerelease": false
|
|
}
|
|
EOF
|
|
)
|
|
curl -s -X 'POST' "$API_URL/releases" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$RELEASE_PAYLOAD" > /dev/null
|
|
fi
|
|
|
|
# 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 crates processed ---"
|