Skip to content

Commit 1ac8e8d

Browse files
[CNSL-1935] Add automated release PR workflow
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 7777b8d commit 1ac8e8d

5 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
secrets:
31+
fork_push_token: ${{ secrets.FORK_PUSH_TOKEN }}
32+
pr_create_token: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
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
14+
1015
## [7.1.0] - 2026-04-14
1116

1217
### Added

scripts/lib/actions-helpers.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# Logging functions for GitHub Actions workflows
3+
4+
# Output an informational message to stdout
5+
log_info() {
6+
local message="$1"
7+
echo "$message"
8+
}
9+
10+
# Output an error message using GitHub Actions workflow command format
11+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
12+
log_error() {
13+
local message="$1"
14+
echo "::error::$message" >&2
15+
}
16+
17+
# Output a warning message using GitHub Actions workflow command format
18+
log_warning() {
19+
local message="$1"
20+
echo "::warning::$message" >&2
21+
}
22+
23+
# Output a notice message using GitHub Actions workflow command format
24+
log_notice() {
25+
local message="$1"
26+
echo "::notice::$message"
27+
}
28+
29+
# Write a single-line output: set_output key value
30+
set_output() {
31+
echo "$1=$2" >> "${GITHUB_OUTPUT:-/dev/null}"
32+
}

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)