This commit is contained in:
昔念
2026-01-27 00:07:06 +08:00
parent f86f1856f0
commit a194d912b5

View File

@@ -1,76 +0,0 @@
when:
event:
- pull_request_close
clone:
image: woodpeckerci/plugin-git
settings:
use-ssh: true
ssh-key-private:
from_secret: WOODPECKER_SSH_KEY
commands:
- |
# 设置SSH
mkdir -p /app/.ssh
chmod 700 /app/.ssh
echo "$${WOODPECKER_SSH_KEY}" > /app/.ssh/id_rsa
chmod 600 /app/.ssh/id_rsa
ssh-keyscan -H codeberg.org >> /app/.ssh/known_hosts
# 配置git
git config --global user.name "Woodpecker CI"
git config --global user.email "ci@example.com"
steps:
- name: 📦 Auto-Archive Merged Branches
image: alpine/git:latest
environment:
WOODPECKER_SSH_KEY:
from_secret: WOODPECKER_SSH_KEY
commands:
- |
# PR_TITLE=${CI_COMMIT_PULL_REQUEST_TITLE}
BRANCH_NAME=${CI_COMMIT_SOURCE_BRANCH}
DEFAULT_BRANCH=${CI_REPO_DEFAULT_BRANCH}
# Set up SSH
mkdir -p ~/.ssh
echo "$${WOODPECKER_SSH_KEY}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H codeberg.org >> ~/.ssh/known_hosts
# Configure git
git config --global user.name "Woodpecker CI"
git config --global user.email "ci@example.com"
if [ "$BRANCH_NAME" = "$DEFAULT_BRANCH" ] || [[ "$BRANCH_NAME" == archived/* ]]; then
echo "⏭️ Skipping: Branch is default branch or already archived"
exit 0
fi
# if [[ "$PR_TITLE" == *NO_ARCHIVE* ]]; then
# echo "⏭️ Skipping: PR title contains NO_ARCHIVE"
# exit 0
# fi
TAG_NAME="archived/$BRANCH_NAME"
echo "🏷️ Archiving branch: $BRANCH_NAME -> tag $TAG_NAME"
git fetch origin --tags "$BRANCH_NAME"
TAG_BASE="$TAG_NAME"
if git ls-remote --exit-code --tags origin "refs/tags/$TAG_BASE" >/dev/null 2>&1; then
echo " Tag $TAG_BASE already exists; searching for next suffix"
suffix=1
while git ls-remote --exit-code --tags origin "refs/tags/${TAG_BASE}-${suffix}" >/dev/null 2>&1; do
suffix=$((suffix+1))
done
TAG_NAME="${TAG_BASE}-${suffix}"
fi
git tag "$TAG_NAME" "origin/$BRANCH_NAME"
git push origin "$TAG_NAME"
git push origin --delete "$BRANCH_NAME"
echo "✅ Successfully archived branch as tag $TAG_NAME"