name: Version Bump # Triggered when the chore/version-bump PR is merged to main. # Reads the bump:patch / bump:minor / bump:major label to determine # the version increment, updates debian/changelog, and commits it. # release.yml then picks up the changelog change 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@v4 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: | CURRENT=$(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 src/ commits since last tag id: commits run: | LAST_TAG=$(git tag -l 'v*' | sort -V | tail -n1) if [[ -n "$LAST_TAG" ]]; then LOG=$(git log "${LAST_TAG}..HEAD" --oneline -- src/ | head -50) else LOG=$(git log --oneline -- src/ | head -50) fi 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 push changelog env: NEW_VERSION: ${{ steps.version.outputs.new }} 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 commit -m "Release v${NEW_VERSION}" git push