Skip to content

Commit 8ee0006

Browse files
[CNSL-1935] Add version bump workflow
Added GitHub Actions workflow that automatically creates and merges version bump PRs when pending-deploy-* branches are merged to main. The workflow updates CHANGELOG.md, internal/spec/config.yaml, and README.md with the new version. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent a33646a commit 8ee0006

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Finalize Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
update-version:
15+
# Only run if PR was merged and source branch starts with pending-deploy-
16+
if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'pending-deploy-')
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
with:
22+
ref: main
23+
24+
- name: Extract release version
25+
id: extract-version
26+
uses: cockroachdb/actions/release-version-extract@v0
27+
28+
- name: Configure git
29+
if: steps.extract-version.outputs.has_unreleased == 'true'
30+
run: |
31+
git config user.name "github-actions[bot]"
32+
git config user.email "github-actions[bot]@users.noreply.github.com"
33+
34+
- name: Create branch and update version
35+
if: steps.extract-version.outputs.has_unreleased == 'true'
36+
run: |
37+
git checkout -b "update-version-${{ steps.extract-version.outputs.next_version }}"
38+
bash internal/update-version.sh "${{ steps.extract-version.outputs.next_version }}"
39+
40+
- name: Commit and push changes
41+
if: steps.extract-version.outputs.has_unreleased == 'true'
42+
run: |
43+
if [[ -z "$(git status --porcelain)" ]]; then
44+
echo "No changes to commit"
45+
exit 1
46+
fi
47+
48+
# Extract changelog entries for this version
49+
changelog_body=$(awk '
50+
/^## \[${{ steps.extract-version.outputs.next_version }}\]/ {flag=1; next}
51+
/^## \[/ {flag=0}
52+
flag
53+
' CHANGELOG.md | sed '/^$/d')
54+
55+
git add .
56+
git commit -m "Release v${{ steps.extract-version.outputs.next_version }}" \
57+
-m "$changelog_body" \
58+
-m "Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>"
59+
git push origin "update-version-${{ steps.extract-version.outputs.next_version }}"
60+
61+
- name: Create Pull Request and enable auto-merge
62+
if: steps.extract-version.outputs.has_unreleased == 'true'
63+
env:
64+
GH_TOKEN: ${{ github.token }}
65+
run: |
66+
pr_body="## Summary
67+
- Updates version to ${{ steps.extract-version.outputs.next_version }}
68+
- Updates CHANGELOG.md, internal/spec/config.yaml, and README.md"
69+
70+
gh pr create \
71+
--title "Release v${{ steps.extract-version.outputs.next_version }}" \
72+
--body "$pr_body" \
73+
--base main \
74+
--head "update-version-${{ steps.extract-version.outputs.next_version }}"
75+
76+
gh pr merge "update-version-${{ steps.extract-version.outputs.next_version }}" --squash --delete-branch

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Added automated release workflow that creates and merges version bump PRs when `pending-deploy-*`
13+
branches are merged to main.
14+
815
## [6.10.0] - 2025-11-19
916

1017
### Added

internal/update-version.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Check if version argument is provided
6+
if [ -z "$1" ]; then
7+
echo "Usage: $0 <version>"
8+
echo "Example: $0 6.11.0"
9+
exit 1
10+
fi
11+
12+
VERSION="$1"
13+
DATE=$(date +%Y-%m-%d)
14+
15+
# Validate semver format
16+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
17+
echo "Error: Version must be in semver format (e.g., 6.11.0)"
18+
exit 1
19+
fi
20+
21+
# Helper function to set output
22+
set_output() {
23+
echo "has_unreleased=$1"
24+
[ -n "$GITHUB_OUTPUT" ] && echo "has_unreleased=$1" >> "$GITHUB_OUTPUT"
25+
}
26+
27+
# Check if [Unreleased] section exists
28+
echo "Checking CHANGELOG.md for Unreleased section..."
29+
if ! grep -q "^## \[Unreleased\]" CHANGELOG.md; then
30+
echo "No Unreleased section found. No files updated."
31+
set_output false
32+
exit 0
33+
fi
34+
35+
# Check if [Unreleased] section has content
36+
echo "Checking if Unreleased section has content..."
37+
unreleased_content=$(awk '
38+
/^## \[Unreleased\]/ { flag=1; next }
39+
/^## \[/ { flag=0 }
40+
flag && /^[^[:space:]]/ { print }
41+
' CHANGELOG.md | grep -v "^$")
42+
43+
if [ -z "$unreleased_content" ]; then
44+
echo "Unreleased section is empty. No files updated."
45+
set_output false
46+
exit 0
47+
fi
48+
49+
echo "Found Unreleased section. Updating version to $VERSION (date: $DATE)"
50+
51+
# Update CHANGELOG.md - keep [Unreleased] and add new version below
52+
echo "Updating CHANGELOG.md..."
53+
awk -v version="$VERSION" -v date="$DATE" '
54+
/^## \[Unreleased\]/ { print; print ""; print "## [" version "] - " date; next }
55+
{ print }
56+
' CHANGELOG.md > CHANGELOG.md.tmp && mv CHANGELOG.md.tmp CHANGELOG.md
57+
58+
# Update internal/spec/config.yaml
59+
echo "Updating internal/spec/config.yaml..."
60+
sed "s/^packageVersion:.*/packageVersion: $VERSION/" internal/spec/config.yaml > internal/spec/config.yaml.tmp && mv internal/spec/config.yaml.tmp internal/spec/config.yaml
61+
62+
# Update README.md
63+
echo "Updating README.md..."
64+
sed "s/^- Package version:.*/- Package version: $VERSION/" README.md > README.md.tmp && mv README.md.tmp README.md
65+
66+
echo ""
67+
echo "✓ Version updated to $VERSION in:"
68+
echo " - CHANGELOG.md"
69+
echo " - internal/spec/config.yaml"
70+
echo " - README.md"
71+
echo ""
72+
73+
set_output true

0 commit comments

Comments
 (0)