187 lines
6.8 KiB
YAML
187 lines
6.8 KiB
YAML
name: Open / Update Version Bump PR
|
|
|
|
# Triggered when any PR merges to main touching src/ or debian/ (push),
|
|
# or when a bump:* label is added to the chore/version-bump PR (labeled).
|
|
# On push: recreates the branch from main and collects all commits since the
|
|
# last tag — no incremental accumulation, no rebase, no conflicts.
|
|
# On label change: checks out the existing branch and rewrites the changelog entry.
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'src/**'
|
|
- 'debian/**'
|
|
pull_request:
|
|
types:
|
|
- labeled
|
|
branches:
|
|
- main
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
pr:
|
|
runs-on: ubuntu-latest
|
|
if: |
|
|
(github.event_name == 'push' && github.actor != 'github-actions[bot]') ||
|
|
(github.event_name == 'pull_request' &&
|
|
github.event.pull_request.head.ref == 'chore/version-bump' &&
|
|
startsWith(github.event.label.name, 'bump:'))
|
|
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up chore/version-bump branch
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
|
|
git fetch origin main
|
|
|
|
if [[ "${{ github.event_name }}" == "push" ]]; then
|
|
# Always recreate from main — avoids rebase conflicts after PR merge
|
|
git checkout -b chore/version-bump origin/main
|
|
|
|
# Collect all commits touching src/ since the last release tag
|
|
LAST_TAG=$(git describe --tags --abbrev=0 origin/main 2>/dev/null || true)
|
|
if [[ -n "$LAST_TAG" ]]; then
|
|
LOG=$(git log "${LAST_TAG}..origin/main" --oneline -- src/ | head -50)
|
|
else
|
|
LOG=$(git log origin/main --oneline -- src/ | head -50)
|
|
fi
|
|
mkdir -p .github/version-bump
|
|
echo "${LOG:-No src/ changes since last release.}" > .github/version-bump/CHANGES.md
|
|
git add .github/version-bump/CHANGES.md
|
|
git commit -m "chore: collect changes since ${LAST_TAG:-initial}"
|
|
git push --force origin chore/version-bump
|
|
else
|
|
# Label change: check out the existing branch, no CHANGES.md update
|
|
git fetch origin chore/version-bump
|
|
git checkout chore/version-bump
|
|
fi
|
|
|
|
- name: Determine bump type
|
|
id: bump_type
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
|
LABEL="${{ github.event.label.name }}"
|
|
else
|
|
# Use existing PR label if present, otherwise default to patch
|
|
LABEL=$(gh pr list \
|
|
--head "chore/version-bump" \
|
|
--base main \
|
|
--json labels \
|
|
--jq '.[0].labels[].name' 2>/dev/null | grep '^bump:' | head -1 || echo "bump:patch")
|
|
fi
|
|
|
|
if [[ "$LABEL" == "bump:major" ]]; then
|
|
echo "type=major" >> "$GITHUB_OUTPUT"
|
|
elif [[ "$LABEL" == "bump:minor" ]]; then
|
|
echo "type=minor" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "type=patch" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Compute new version
|
|
id: version
|
|
env:
|
|
BUMP_TYPE: ${{ steps.bump_type.outputs.type }}
|
|
run: |
|
|
# Always base version on main's latest tag to avoid double-bumping on reruns
|
|
CURRENT=$(git describe --tags --abbrev=0 origin/main 2>/dev/null | sed 's/^v//' \
|
|
|| git show origin/main:debian/changelog | grep -m1 '(' | sed 's/.*(\(.*\)).*/\1/')
|
|
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
|
|
MINOR=$(echo "$CURRENT" | cut -d. -f2)
|
|
PATCH=$(echo "$CURRENT" | cut -d. -f3)
|
|
|
|
if [[ "$BUMP_TYPE" == "major" ]]; then
|
|
NEW="$((MAJOR + 1)).0.0"
|
|
elif [[ "$BUMP_TYPE" == "minor" ]]; then
|
|
NEW="${MAJOR}.$((MINOR + 1)).0"
|
|
else
|
|
NEW="${MAJOR}.${MINOR}.$((PATCH + 1))"
|
|
fi
|
|
|
|
echo "Bumping $CURRENT → $NEW ($BUMP_TYPE)"
|
|
echo "new=$NEW" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Write debian/changelog
|
|
env:
|
|
NEW_VERSION: ${{ steps.version.outputs.new }}
|
|
run: |
|
|
LOG=$(cat .github/version-bump/CHANGES.md 2>/dev/null || true)
|
|
DATE=$(date -R)
|
|
# Base on main's changelog so reruns always replace the previous bot entry cleanly
|
|
MAIN_CHANGELOG=$(git show origin/main:debian/changelog)
|
|
{
|
|
echo "pve-mod ($NEW_VERSION) stable; urgency=low"
|
|
echo ""
|
|
while IFS= read -r line; do
|
|
[[ -n "$line" ]] && echo " * $line"
|
|
done <<< "$LOG"
|
|
[[ -z "$LOG" ]] && echo " * Automated version bump."
|
|
echo ""
|
|
echo " -- github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> $DATE"
|
|
echo ""
|
|
echo "$MAIN_CHANGELOG"
|
|
} > debian/changelog
|
|
git add debian/changelog
|
|
git diff --cached --quiet || git commit -m "chore: update changelog to v${NEW_VERSION}"
|
|
git push --force-with-lease origin chore/version-bump
|
|
|
|
- name: Build PR body
|
|
env:
|
|
NEW_VERSION: ${{ steps.version.outputs.new }}
|
|
run: |
|
|
{
|
|
echo "## Release v${NEW_VERSION}"
|
|
echo ""
|
|
cat .github/version-bump/CHANGES.md 2>/dev/null || echo "No changes recorded."
|
|
echo ""
|
|
echo "---"
|
|
echo "*Change label to \`bump:minor\` or \`bump:major\` before merging if needed.*"
|
|
echo "*Merge this PR when ready to release.*"
|
|
} > /tmp/pr-body.md
|
|
|
|
- name: Create or update PR (push)
|
|
if: github.event_name == 'push'
|
|
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 PR with label bump:patch"
|
|
fi
|
|
|
|
- name: Update PR body (label change)
|
|
if: github.event_name == 'pull_request'
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
run: |
|
|
gh pr edit "$PR_NUMBER" --body-file /tmp/pr-body.md |