From 119ef1417b2e02735077f509181dae640f3fe248 Mon Sep 17 00:00:00 2001 From: Meliox Date: Sun, 9 Aug 2026 12:48:01 +0200 Subject: [PATCH] more changes --- .github/workflows/create-release-tag.yml | 36 +++++ .github/workflows/pr-create.yml | 111 ------------- .github/workflows/prepare-release-pr.yml | 196 +++++++++++++++++++++++ .github/workflows/version-bump.yml | 110 ------------- 4 files changed, 232 insertions(+), 221 deletions(-) create mode 100644 .github/workflows/create-release-tag.yml delete mode 100644 .github/workflows/pr-create.yml create mode 100644 .github/workflows/prepare-release-pr.yml delete mode 100644 .github/workflows/version-bump.yml diff --git a/.github/workflows/create-release-tag.yml b/.github/workflows/create-release-tag.yml new file mode 100644 index 0000000..26b25b4 --- /dev/null +++ b/.github/workflows/create-release-tag.yml @@ -0,0 +1,36 @@ +name: Tag Release + +# Triggered when the chore/version-bump PR is merged to main. +# debian/changelog is already on main from the merged PR — just create the tag. +# release.yml triggers on the tag push and builds the release. + +on: + pull_request: + types: + - closed + branches: + - main + +permissions: + contents: write + +jobs: + tag: + runs-on: ubuntu-latest + if: | + github.event.pull_request.merged == true && + github.event.pull_request.head.ref == 'chore/version-bump' + + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Create and push tag + run: | + VERSION=$(grep -m1 '(' debian/changelog | sed 's/.*(\(.*\)).*/\1/') + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag "v${VERSION}" + git push origin "v${VERSION}" \ No newline at end of file diff --git a/.github/workflows/pr-create.yml b/.github/workflows/pr-create.yml deleted file mode 100644 index c840cac..0000000 --- a/.github/workflows/pr-create.yml +++ /dev/null @@ -1,111 +0,0 @@ -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 \ No newline at end of file diff --git a/.github/workflows/prepare-release-pr.yml b/.github/workflows/prepare-release-pr.yml new file mode 100644 index 0000000..173e798 --- /dev/null +++ b/.github/workflows/prepare-release-pr.yml @@ -0,0 +1,196 @@ +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 \ No newline at end of file diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml deleted file mode 100644 index 68a6fff..0000000 --- a/.github/workflows/version-bump.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: Version Bump - -# Triggered when the chore/version-bump PR is merged to main. -# Reads the bump:patch / bump:minor / bump:major label from the merged PR. -# Updates debian/changelog, commits it, and pushes a vX.Y.Z tag. -# release.yml triggers on that tag push and builds the release. - -on: - pull_request: - types: - - closed - branches: - - main - -permissions: - contents: write - -jobs: - bump: - runs-on: ubuntu-latest - if: | - github.event.pull_request.merged == true && - github.event.pull_request.head.ref == 'chore/version-bump' - - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Determine bump type from PR label - id: bump_type - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '[.labels[].name] | join(",")') - echo "Labels found: $LABELS" - - if echo "$LABELS" | grep -q 'bump:major'; then - echo "type=major" >> "$GITHUB_OUTPUT" - elif echo "$LABELS" | grep -q 'bump:minor'; then - echo "type=minor" >> "$GITHUB_OUTPUT" - else - echo "type=patch" >> "$GITHUB_OUTPUT" - fi - - - name: Extract and bump version - id: version - env: - BUMP_TYPE: ${{ steps.bump_type.outputs.type }} - run: | - # Prefer latest tag; fall back to debian/changelog on first run - CURRENT=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' \ - || grep -m1 '(' debian/changelog | 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 "current=$CURRENT" >> "$GITHUB_OUTPUT" - echo "new=$NEW" >> "$GITHUB_OUTPUT" - - - name: Collect accumulated changes - id: commits - run: | - # Read from the CHANGES.md that was merged in - LOG=$(cat .github/version-bump/CHANGES.md 2>/dev/null || true) - EOF=$(openssl rand -hex 16) - echo "log<<$EOF" >> "$GITHUB_OUTPUT" - echo "$LOG" >> "$GITHUB_OUTPUT" - echo "$EOF" >> "$GITHUB_OUTPUT" - - - name: Prepend new changelog entry - env: - NEW_VERSION: ${{ steps.version.outputs.new }} - COMMITS: ${{ steps.commits.outputs.log }} - run: | - DATE=$(date -R) - { - echo "pve-mod ($NEW_VERSION) stable; urgency=low" - echo "" - while IFS= read -r line; do - [[ -n "$line" ]] && echo " * $line" - done <<< "$COMMITS" - [[ -z "$COMMITS" ]] && echo " * Automated version bump." - echo "" - echo " -- github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> $DATE" - echo "" - cat debian/changelog - } > debian/changelog.new - mv debian/changelog.new debian/changelog - - - name: Commit and tag - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add debian/changelog - git rm --ignore-unmatch .github/version-bump/CHANGES.md - git commit -m "Release v${{ steps.version.outputs.new }}" - git tag v${{ steps.version.outputs.new }} - git push origin v${{ steps.version.outputs.new }} \ No newline at end of file