mirror of
https://codeberg.org/JasterV/docker.git
synced 2026-04-26 18:10:02 +00:00
[rust-magic-release] Publish first version
This commit is contained in:
parent
dac2c42c27
commit
43a7669d26
3 changed files with 100 additions and 0 deletions
21
.woodpecker/publish-rust-magic-release-image.yml
Normal file
21
.woodpecker/publish-rust-magic-release-image.yml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
when:
|
||||||
|
event: [push, manual]
|
||||||
|
branch: main
|
||||||
|
path:
|
||||||
|
[
|
||||||
|
"rust/magic-release.Dockerfile",
|
||||||
|
"rust/magic-release.sh",
|
||||||
|
".woodpecker/publish-rust-magic-release-image.yml",
|
||||||
|
]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
publish:
|
||||||
|
image: plugins/kaniko
|
||||||
|
settings:
|
||||||
|
repo: jasterv/rust-magic-release
|
||||||
|
tags: 1.93,latest
|
||||||
|
username:
|
||||||
|
from_secret: DOCKERHUB_USERNAME
|
||||||
|
password:
|
||||||
|
from_secret: DOCKERHUB_PASSWORD
|
||||||
|
dockerfile: rust/magic-release.Dockerfile
|
||||||
8
rust/magic-release.Dockerfile
Normal file
8
rust/magic-release.Dockerfile
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
FROM jasterv/rust-ci:latest
|
||||||
|
|
||||||
|
COPY rust/magic-release.sh /usr/local/bin/magic-release
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/magic-release
|
||||||
|
|
||||||
|
# Entrypoint is required for Woodpecker plugins
|
||||||
|
ENTRYPOINT ["/usr/local/bin/magic-release"]
|
||||||
71
rust/magic-release.sh
Executable file
71
rust/magic-release.sh
Executable file
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# --- 1. 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)"')
|
||||||
|
|
||||||
|
echo "Starting independent release process..."
|
||||||
|
|
||||||
|
# --- 3. 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) ---"
|
||||||
|
|
||||||
|
# A. 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..."
|
||||||
|
|
||||||
|
# B. 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
|
||||||
|
|
||||||
|
# C. 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
|
||||||
|
|
||||||
|
# D. 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 ---"
|
||||||
Loading…
Reference in a new issue