Skip to content

Commit edefefe

Browse files
[CNSL-1935] Add automated release PR workflow (#95)
Added GitHub Actions workflow that automatically creates release PRs when automation/pending-deploy-* branches are merged to main. The workflow updates go.mod and main.go for major version changes, updates config.yaml with the new version, and regenerates the OpenAPI client to automatically update all generated files (README.md, docs/README.md, pkg/client/configuration.go, and other generated code). Co-authored-by: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent 38d5ac8 commit edefefe

4 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Create Release PR
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write # Push to fork and create branch
12+
pull-requests: write # Create release PR
13+
14+
jobs:
15+
create-release-pr:
16+
# Run on merged PRs with automation/pending-deploy- prefix, or manual workflow_dispatch
17+
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'automation/pending-deploy-'))
18+
uses: cockroachdb/actions/.github/workflows/create-release-pr.yml@v0
19+
with:
20+
fork_owner: crl-gh-actions-pr-bot
21+
fork_repo: cockroach-cloud-sdk-go
22+
build_script: scripts/update_version.sh
23+
files_to_commit: |
24+
go.mod
25+
main.go
26+
internal/spec/config.yaml
27+
README.md
28+
docs/README.md
29+
pkg/client/configuration.go
30+
allow_fork_force_sync: true
31+
secrets:
32+
fork_push_token: ${{ secrets.FORK_PUSH_TOKEN }}
33+
pr_create_token: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Automated release workflow that creates release PRs when `automation/pending-deploy-*`
13+
branches are merged to main, updating the version number in all relevant files
1214
- Added pending deploy branch management to release workflow to ensure automated
1315
PRs that remain open after an SDK release are retargeted to the latest pending
1416
deploy branch

scripts/lib/validation.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# Validation helper functions
3+
4+
# Check if required commands are available in PATH
5+
# Usage: check_required_commands "cmd1" "cmd2" "cmd3"
6+
check_required_commands() {
7+
local missing_commands=()
8+
9+
for cmd in "$@"; do
10+
if ! command -v "$cmd" >/dev/null 2>&1; then
11+
missing_commands+=("$cmd")
12+
fi
13+
done
14+
15+
if [[ ${#missing_commands[@]} -gt 0 ]]; then
16+
log_error "Required command(s) not found in PATH: ${missing_commands[*]}"
17+
return 1
18+
fi
19+
20+
return 0
21+
}

scripts/update_version.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# This script is called by the reusable workflow after CHANGELOG.md has been updated.
6+
# The VERSION environment variable is set by the reusable workflow.
7+
# This script should only update version numbers in files other than CHANGELOG.md.
8+
9+
# Get the script directory
10+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
12+
# Source helper functions
13+
source "$SCRIPT_DIR/lib/actions-helpers.sh"
14+
source "$SCRIPT_DIR/lib/validation.sh"
15+
16+
# Check required commands are available
17+
check_required_commands cut sed make
18+
19+
# Check if VERSION environment variable is set
20+
if [ -z "$VERSION" ]; then
21+
log_error "VERSION environment variable is required"
22+
log_error "This script is intended to be called by the create-release-pr workflow"
23+
exit 1
24+
fi
25+
26+
log_info "Updating version to $VERSION in config and documentation files..."
27+
28+
# Extract major version from VERSION (e.g., 7.0.0 -> 7)
29+
MAJOR_VERSION=$(echo "$VERSION" | cut --delimiter=. --fields=1)
30+
31+
# Update go.mod module path to match major version
32+
log_info "Updating go.mod..."
33+
sed --regexp-extended "s|(github.com/cockroachdb/cockroach-cloud-sdk-go)/v[0-9]+|\1/v${MAJOR_VERSION}|" go.mod > go.mod.tmp && mv go.mod.tmp go.mod
34+
35+
# Update main.go import path to match major version
36+
log_info "Updating main.go..."
37+
sed --regexp-extended "s|(github.com/cockroachdb/cockroach-cloud-sdk-go)/v[0-9]+|\1/v${MAJOR_VERSION}|" main.go > main.go.tmp && mv main.go.tmp main.go
38+
39+
# Update internal/spec/config.yaml
40+
log_info "Updating internal/spec/config.yaml..."
41+
sed "s/^packageVersion:.*/packageVersion: $VERSION/" internal/spec/config.yaml > internal/spec/config.yaml.tmp && mv internal/spec/config.yaml.tmp internal/spec/config.yaml
42+
43+
# Generate OpenAPI client to update README files
44+
log_info "Generating OpenAPI client..."
45+
# Note: sudo is required because docker containers run as root by default,
46+
# creating files owned by root. We then chown them back to the current user.
47+
sudo make generate-openapi-client
48+
sudo chown --recursive "$(id --user):$(id --group)" internal/openapi-generator/ pkg/client/ docs/ README.md
49+
50+
log_info "Version updated to $VERSION"
51+
52+
# Validate the updated code
53+
log_info "Running validation..."
54+
make validate

0 commit comments

Comments
 (0)