PVE-mods/.github/workflows/pr-create.yml
2026-06-07 19:25:28 +02:00

107 lines
3.6 KiB
YAML

name: Open / Update Version Bump PR
# Triggered when any PR merges to main touching src/ or debian/.
# Accumulates changes on chore/version-bump branch by appending to CHANGES.md.
# Opens the bump PR if it doesn't exist, updates body if it does.
# Label is never changed on update — preserving manual bump:minor / bump:major.
# Bot guard prevents firing on the changelog commit from version-bump.yml.
on:
push:
branches:
- main
paths:
- 'src/**'
- 'debian/**'
permissions:
contents: write
pull-requests: write
jobs:
pr:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Collect src/ commits from this merge
id: commits
run: |
LOG=$(git log "HEAD~1..HEAD" --oneline -- src/ | head -50)
EOF=$(openssl rand -hex 16)
echo "log<<$EOF" >> "$GITHUB_OUTPUT"
echo "$LOG" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Update chore/version-bump branch
env:
COMMITS: ${{ steps.commits.outputs.log }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Checkout existing bump branch or create it from main
git fetch origin chore/version-bump 2>/dev/null && \
git checkout chore/version-bump || \
git checkout -b chore/version-bump
# Append this merge's changes to the top of CHANGES.md
mkdir -p .github/version-bump
PREV=$(cat .github/version-bump/CHANGES.md 2>/dev/null || true)
{
echo "### Merged at $(date -R)"
echo "${COMMITS:-No src/ changes detected.}"
echo ""
echo "$PREV"
} > .github/version-bump/CHANGES.md
git add .github/version-bump/CHANGES.md
git commit -m "chore: accumulate changes from $(git rev-parse --short HEAD~1)"
git push origin chore/version-bump
- name: Build PR body from accumulated changes
run: |
VERSION=$(grep -m1 '(' debian/changelog | sed 's/.*(\(.*\)).*/\1/')
{
echo "## Pending changes for next release (current: v${VERSION})"
echo ""
cat .github/version-bump/CHANGES.md
echo ""
echo "---"
echo "*Change label to \`bump:minor\` or \`bump:major\` before merging if needed.*"
echo "*Default is \`bump:patch\`.*"
echo "*Merge this PR when ready to release.*"
} > /tmp/pr-body.md
- name: Create or update version bump PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BUMP_BRANCH="chore/version-bump"
VERSION=$(grep -m1 '(' debian/changelog | sed 's/.*(\(.*\)).*/\1/')
TITLE="chore: release next version (current: v${VERSION})"
EXISTING=$(gh pr list \
--head "$BUMP_BRANCH" \
--base main \
--json number --jq '.[0].number' 2>/dev/null || true)
if [[ -n "$EXISTING" ]]; then
gh pr edit "$EXISTING" \
--title "$TITLE" \
--body-file /tmp/pr-body.md
echo "Updated PR #${EXISTING} (label unchanged)"
else
gh pr create \
--title "$TITLE" \
--body-file /tmp/pr-body.md \
--base main \
--head "$BUMP_BRANCH" \
--label "bump:patch"
echo "Opened new version bump PR with label bump:patch"
fi