diff --git a/.woodpecker/publish-release-plz-image.yml b/.woodpecker/publish-release-plz-image.yml index 1b28c4b..9d1ccc2 100644 --- a/.woodpecker/publish-release-plz-image.yml +++ b/.woodpecker/publish-release-plz-image.yml @@ -1,7 +1,7 @@ when: event: [push, manual] branch: main - path: ["release-plz.Dockerfile"] + path: ["release-plz/base.Dockerfile"] steps: publish: @@ -13,4 +13,4 @@ steps: from_secret: DOCKERHUB_USERNAME password: from_secret: DOCKERHUB_PASSWORD - dockerfile: release-plz.Dockerfile + dockerfile: release-plz/base.Dockerfile diff --git a/.woodpecker/publish-rust-ci-image.yml b/.woodpecker/publish-rust-ci-image.yml index b196f1a..fe19694 100644 --- a/.woodpecker/publish-rust-ci-image.yml +++ b/.woodpecker/publish-rust-ci-image.yml @@ -1,7 +1,7 @@ when: event: [push, manual] branch: main - path: ["rust.Dockerfile"] + path: ["rust/Dockerfile"] steps: publish: @@ -13,4 +13,4 @@ steps: from_secret: DOCKERHUB_USERNAME password: from_secret: DOCKERHUB_PASSWORD - dockerfile: rust.Dockerfile + dockerfile: rust/Dockerfile diff --git a/release-plz.Dockerfile b/release-plz/base.Dockerfile similarity index 51% rename from release-plz.Dockerfile rename to release-plz/base.Dockerfile index 5055d4e..3aee662 100644 --- a/release-plz.Dockerfile +++ b/release-plz/base.Dockerfile @@ -1,7 +1,13 @@ FROM rust:alpine AS builder # Install build dependencies for Rust crates -RUN apk add --no-cache musl-dev gcc +RUN apk add --no-cache \ + musl-dev \ + gcc \ + perl \ + make \ + openssl-dev \ + pkgconfig # Install release-plz RUN cargo install release-plz --version 0.3.156 @@ -9,8 +15,16 @@ RUN cargo install release-plz --version 0.3.156 # Final lightweight image FROM alpine:latest -# Install runtime dependencies (git for repo access, curl for API calls) -RUN apk add --no-cache git curl libgcc +# Install runtime dependencies +# curl: for the API calls in your script +# git: for release-plz to commit/push +# ca-certificates: so curl/git can verify HTTPS connections +RUN apk add --no-cache \ + git \ + curl \ + ca-certificates \ + libgcc \ + openssl # Copy the binary from the builder stage COPY --from=builder /usr/local/cargo/bin/release-plz /usr/local/bin/release-plz diff --git a/release-plz/update-pr.Dockerfile b/release-plz/update-pr.Dockerfile new file mode 100644 index 0000000..37bc6ba --- /dev/null +++ b/release-plz/update-pr.Dockerfile @@ -0,0 +1,8 @@ +FROM jasterv/release-plz:0.3 + +COPY release-plz/update-pr.sh /usr/local/bin/release-plz-update-pr + +RUN chmod +x /usr/local/bin/release-plz-update-pr + +# Entrypoint is required for Woodpecker plugins +ENTRYPOINT ["/usr/local/bin/release-plz-update-pr"] diff --git a/release-plz/update-pr.sh b/release-plz/update-pr.sh new file mode 100644 index 0000000..5293ba0 --- /dev/null +++ b/release-plz/update-pr.sh @@ -0,0 +1,91 @@ +#!/bin/sh +set -e + +# --- 1. Configuration & Defaults --- +# Woodpecker settings are passed as PLUGIN_* environment variables +TOKEN="${PLUGIN_TOKEN}" +BASE_BRANCH="${PLUGIN_BASE_BRANCH:-"main"}" +TEMP_BRANCH="${PLUGIN_TEMP_BRANCH:-"release-plz-update"}" +BOT_NAME="${PLUGIN_BOT_NAME:-"release-plz-bot"}" +BOT_EMAIL="${PLUGIN_BOT_EMAIL:-"bot@codeberg.org"}" +COMMIT_MESSAGE="${PLUGIN_COMMIT_MESSAGE:-"chore: release-plz update"}" +PR_TITLE="${PLUGIN_PR_TITLE:-"chore: release-plz update"}" + +# Use Woodpecker CI built-in variables +REPO_FULL_NAME="${CI_REPO}" # e.g., "username/repo" +API_URL="https://codeberg.org/api/v1/repos/${REPO_FULL_NAME}" + +# --- 2. Validation --- +if [ -z "$TOKEN" ]; then + echo "Error: 'token' setting is missing. Please provide a Codeberg Access Token." + exit 1 +fi + +# --- 3. Run release-plz update --- +echo "--- Running release-plz update ---" +release-plz update + +# Check if any files were changed (Cargo.toml, CHANGELOG.md, etc.) +if [ -z "$(git status --porcelain)" ]; then + echo "No changes detected. Repository is up to date." + exit 0 +fi + +echo "Changes detected. Preparing to update Codeberg..." + +# --- 4. Git Setup & Push --- +# Configure identity for the commit +git config --global user.email "$BOT_EMAIL" +git config --global user.name "$BOT_NAME" + +# Create or switch to the feature branch +git checkout -b "$TEMP_BRANCH" +git add . +git commit -m "$COMMIT_MESSAGE" + +# Force push to update the branch (and the linked PR if it exists) +echo "Pushing changes to branch: $TEMP_BRANCH..." +git push -f "https://$TOKEN@codeberg.org/${REPO_FULL_NAME}.git" "$TEMP_BRANCH" + +# --- 5. Pull Request Management --- +echo "Checking for existing Pull Request..." + +# Search for an open PR from our specific head branch to the base branch +PR_SEARCH=$(curl -s -H "Authorization: token $TOKEN" \ + "$API_URL/pulls?state=open&head=$TEMP_BRANCH&base=$BASE_BRANCH") + +# Check if the search result contains our branch name +PR_EXISTS=$(echo "$PR_SEARCH" | grep -q "\"head\":{\"label\":\"$TEMP_BRANCH\"" && echo "yes" || echo "no") + +if [ "$PR_EXISTS" = "no" ]; then + echo "No open PR found. Creating a new one..." + + # Construct the JSON payload for the new PR + PR_PAYLOAD=$(cat <