PVE-mods/.github/workflows/pr-create.yml
Meliox 26b858db80
revise build workflow (#262)
* change build to tags

* more changes

* d

---------

Co-authored-by: Meliox <na>
2026-08-09 12:50:47 +02:00

196 lines
6.9 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).
# Accumulates changes in CHANGES.md, writes debian/changelog with the correct
# bumped version, and keeps the PR body up to date.
# On label change the changelog entry is rewritten with the new version.
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: Collect new commits (push only)
id: new_commits
if: github.event_name == 'push'
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: Set up chore/version-bump branch
env:
NEW_COMMITS: ${{ steps.new_commits.outputs.log }}
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 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
if [[ "${{ github.event_name }}" == "push" ]]; then
mkdir -p .github/version-bump
PREV=$(cat .github/version-bump/CHANGES.md 2>/dev/null || true)
{
echo "${NEW_COMMITS:-No src/ changes detected.}"
[[ -n "$PREV" ]] && 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}"
git push --force-with-lease origin 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