mirror of
https://codeberg.org/JasterV/docker.git
synced 2026-04-26 18:10:02 +00:00
refactor: restructure project
This commit is contained in:
parent
9550d7c65e
commit
a72e9c24fb
6 changed files with 120 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
8
release-plz/update-pr.Dockerfile
Normal file
8
release-plz/update-pr.Dockerfile
Normal file
|
|
@ -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"]
|
||||
91
release-plz/update-pr.sh
Normal file
91
release-plz/update-pr.sh
Normal file
|
|
@ -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 <<EOF
|
||||
{
|
||||
"base": "$BASE_BRANCH",
|
||||
"head": "$TEMP_BRANCH",
|
||||
"title": "$PR_TITLE",
|
||||
"body": "This is an automated PR generated by [release-plz](https://github.com/MarcoIeni/release-plz) via Woodpecker CI."
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
CREATE_RESPONSE=$(curl -s -X 'POST' "$API_URL/pulls" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$PR_PAYLOAD")
|
||||
|
||||
# Check if creation was successful
|
||||
if echo "$CREATE_RESPONSE" | grep -q "\"id\":"; then
|
||||
echo "Successfully created Pull Request!"
|
||||
else
|
||||
echo "Failed to create Pull Request. Response:"
|
||||
echo "$CREATE_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "An open Pull Request already exists. Codeberg has updated it via the push."
|
||||
fi
|
||||
|
||||
echo "--- Release-plz plugin task completed ---"
|
||||
Loading…
Reference in a new issue