111 lines
3.7 KiB
YAML
111 lines
3.7 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@v7
|
|
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"
|
|
|
|
# Always rebase the bump branch on the latest main so the PR is testable
|
|
git fetch origin main
|
|
if git fetch origin chore/version-bump 2>/dev/null; then
|
|
git checkout chore/version-bump
|
|
git rebase origin/main
|
|
else
|
|
git checkout -b chore/version-bump origin/main
|
|
fi
|
|
|
|
# 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 "${COMMITS:-No src/ changes detected.}"
|
|
echo "$PREV"
|
|
} > .github/version-bump/CHANGES.md
|
|
|
|
git add .github/version-bump/CHANGES.md
|
|
MAIN_SHA=$(git rev-parse --short origin/main)
|
|
git commit -m "chore: accumulate changes from ${MAIN_SHA}"
|
|
|
|
# Rebase rewrites history, so the push must be a force (lease-guarded).
|
|
git push --force-with-lease 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"
|
|
TITLE="chore: release next 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 |