Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 68e4d3d

Browse files
kwentclaude
andcommitted
Add version management helpers and Makefile improvements
- Add scripts/bump-version.sh for automated semantic versioning - Automatically updates version in pkg/commands/root.go - Creates git commits and tags - Includes safety checks and user confirmation - Enhance Makefile with new targets: - Add help target with self-documenting commands - Add version-show, version-patch/minor/major targets - Add release-patch/minor/major for complete release workflow - Add .PHONY declarations for all targets - Add descriptive comments for all commands - Update CLAUDE.md with version management documentation Inspired by rootly-edge-connector Makefile structure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 77e9736 commit 68e4d3d

3 files changed

Lines changed: 333 additions & 10 deletions

File tree

CLAUDE.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,37 @@ make docker-build
4343
make docker-push
4444
```
4545

46-
### Release
46+
### Release & Version Management
47+
48+
The project uses semantic versioning with automated version bumping:
49+
4750
```bash
48-
# Create and push a new version tag
51+
# Show current and next versions
52+
make version-show
53+
54+
# Bump versions (updates root.go, commits, creates tag, and pushes)
55+
make release-patch # 1.2.10 → 1.2.11 (for bug fixes)
56+
make release-minor # 1.2.10 → 1.3.0 (for new features)
57+
make release-major # 1.2.10 → 2.0.0 (for breaking changes)
58+
59+
# Or use individual steps
60+
make version-patch # Just bump and tag patch version
61+
make version-minor # Just bump and tag minor version
62+
make version-major # Just bump and tag major version
63+
64+
# Preview next version without making changes
65+
make version-next
66+
67+
# Legacy manual release (requires VERSION variable)
4968
make release VERSION="v1.0.0"
5069
```
5170

71+
**Note**: Version bumping requires a clean git working directory. The script will:
72+
1. Update version in `pkg/commands/root.go`
73+
2. Commit the change
74+
3. Create and push a git tag
75+
4. Trigger GitHub Actions to build and publish the release
76+
5277
## Architecture
5378

5479
### Package Structure
@@ -109,7 +134,25 @@ Critical fix context: Recent fix addressed panic in key-value parsing for refs a
109134

110135
## Version Management
111136

112-
Current version is hardcoded in `pkg/commands/root.go:34`. Update this file when releasing new versions.
137+
Current version is maintained in `pkg/commands/root.go:34` and managed through git tags.
138+
139+
### Version Bumping Process
140+
141+
The `scripts/bump-version.sh` script automates version management:
142+
1. Reads current version from latest git tag
143+
2. Calculates next version based on semver (patch/minor/major)
144+
3. Updates `pkg/commands/root.go` with new version
145+
4. Commits the change with message "Update version to vX.Y.Z"
146+
5. Creates annotated git tag (vX.Y.Z)
147+
6. Pushes commit and tag to origin
148+
149+
### Usage
150+
151+
Use Makefile targets for version management:
152+
- `make version-show` - Display current and next versions
153+
- `make release-patch` - Bump patch (bug fixes)
154+
- `make release-minor` - Bump minor (new features)
155+
- `make release-major` - Bump major (breaking changes)
113156

114157
The CLI checks for updates on `--version` flag using the `gleich/release` package.
115158

Makefile

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,71 @@
1-
build:
1+
.PHONY: build docker-build docker-push clean test lint release help
2+
.PHONY: version-show version-patch version-minor version-major version-next version-help
3+
.PHONY: release-patch release-minor release-major
4+
5+
help: ## Show this help message
6+
@echo 'Usage: make [target]'
7+
@echo ''
8+
@echo 'Available targets:'
9+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
10+
11+
build: ## Build the binary
212
CGO_ENABLED=0 go build -tags netgo -a -v -ldflags '-extldflags "-static"' -o ./bin/rootly ./cmd/rootly/
313

4-
docker-build:
14+
docker-build: ## Build Docker image
515
docker build -t rootlyhub/cli .
616

7-
docker-push:
17+
docker-push: ## Push Docker image
818
docker push rootlyhub/cli
919

10-
clean:
20+
clean: ## Remove build artifacts
1121
rm -r ./bin
1222

13-
test:
23+
test: ## Run tests
1424
go test -count=1 -v ./...
1525

16-
lint:
26+
lint: ## Run linters
1727
golangci-lint run
1828
hadolint Dockerfile
1929
goreleaser check
2030

21-
release:
31+
release: ## Create a release with VERSION variable (legacy)
2232
git tag -a $(VERSION) -m $(VERSION)
2333
git push origin $(VERSION)
34+
35+
# Version management targets
36+
# These targets manage semantic versioning using git tags
37+
38+
version-show: ## Show current and next versions
39+
@echo "Current version: $$(git describe --tags --abbrev=0 2>/dev/null || echo 'No tags found')"
40+
@echo "Next patch: $$(scripts/bump-version.sh show patch)"
41+
@echo "Next minor: $$(scripts/bump-version.sh show minor)"
42+
@echo "Next major: $$(scripts/bump-version.sh show major)"
43+
44+
version-patch: ## Bump patch version (1.2.3 → 1.2.4)
45+
@scripts/bump-version.sh patch
46+
47+
version-minor: ## Bump minor version (1.2.3 → 1.3.0)
48+
@scripts/bump-version.sh minor
49+
50+
version-major: ## Bump major version (1.2.3 → 2.0.0)
51+
@scripts/bump-version.sh major
52+
53+
version-next: ## Show next patch version
54+
@scripts/bump-version.sh show patch
55+
56+
version-help: ## Show detailed version help
57+
@scripts/bump-version.sh help
58+
59+
# Release targets - these create git tags which trigger CI releases
60+
61+
release-patch: version-patch ## Bump patch version and push tag (triggers CI release)
62+
@echo "✅ Patch version bumped and tagged"
63+
@echo "🚀 GitHub Actions will automatically build and publish the release"
64+
65+
release-minor: version-minor ## Bump minor version and push tag (triggers CI release)
66+
@echo "✅ Minor version bumped and tagged"
67+
@echo "🚀 GitHub Actions will automatically build and publish the release"
68+
69+
release-major: version-major ## Bump major version and push tag (triggers CI release)
70+
@echo "✅ Major version bumped and tagged"
71+
@echo "🚀 GitHub Actions will automatically build and publish the release"

scripts/bump-version.sh

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#!/bin/bash
2+
3+
# Version bumping script for Rootly CLI
4+
# Uses git tags to manage versions with semver compatibility
5+
# Updates version in pkg/commands/root.go
6+
7+
set -e
8+
9+
# Colors for output
10+
RED='\033[0;31m'
11+
GREEN='\033[0;32m'
12+
YELLOW='\033[0;33m'
13+
BLUE='\033[0;34m'
14+
NC='\033[0m' # No Color
15+
16+
# File containing the version
17+
VERSION_FILE="pkg/commands/root.go"
18+
19+
# Function to print colored output
20+
print_info() {
21+
echo -e "${BLUE}INFO:${NC} $1"
22+
}
23+
24+
print_success() {
25+
echo -e "${GREEN}SUCCESS:${NC} $1"
26+
}
27+
28+
print_warning() {
29+
echo -e "${YELLOW}WARNING:${NC} $1"
30+
}
31+
32+
print_error() {
33+
echo -e "${RED}ERROR:${NC} $1"
34+
}
35+
36+
# Function to get the current version from git tags
37+
get_current_version() {
38+
local current_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
39+
if [[ -z "$current_tag" ]]; then
40+
echo "0.0.0"
41+
else
42+
echo "$current_tag" | sed 's/^v//'
43+
fi
44+
}
45+
46+
# Function to parse semantic version
47+
parse_version() {
48+
local version=$1
49+
local major=$(echo "$version" | cut -d. -f1)
50+
local minor=$(echo "$version" | cut -d. -f2)
51+
local patch=$(echo "$version" | cut -d. -f3)
52+
echo "$major $minor $patch"
53+
}
54+
55+
# Function to calculate next version
56+
calculate_next_version() {
57+
local type=$1
58+
local current=$2
59+
60+
read -r major minor patch <<< $(parse_version "$current")
61+
62+
case $type in
63+
"major")
64+
echo "$((major + 1)).0.0"
65+
;;
66+
"minor")
67+
echo "$major.$((minor + 1)).0"
68+
;;
69+
"patch")
70+
echo "$major.$minor.$((patch + 1))"
71+
;;
72+
*)
73+
echo "Invalid version type: $type" >&2
74+
exit 1
75+
;;
76+
esac
77+
}
78+
79+
# Function to check if working directory is clean
80+
check_git_status() {
81+
if [[ -n $(git status --porcelain) ]]; then
82+
print_error "Working directory is not clean. Please commit or stash your changes."
83+
git status --short
84+
exit 1
85+
fi
86+
}
87+
88+
# Function to update version in root.go
89+
update_version_file() {
90+
local version=$1
91+
local temp_file="${VERSION_FILE}.tmp"
92+
93+
print_info "Updating version in $VERSION_FILE"
94+
95+
if [[ ! -f "$VERSION_FILE" ]]; then
96+
print_error "Version file not found: $VERSION_FILE"
97+
exit 1
98+
fi
99+
100+
# Update the version line using sed
101+
sed "s/version := \"v[0-9]*\.[0-9]*\.[0-9]*\"/version := \"v$version\"/" "$VERSION_FILE" > "$temp_file"
102+
mv "$temp_file" "$VERSION_FILE"
103+
104+
print_success "Version updated to v$version in $VERSION_FILE"
105+
}
106+
107+
# Function to create and push tag
108+
create_tag() {
109+
local version=$1
110+
local tag="v$version"
111+
112+
print_info "Creating tag: $tag"
113+
git tag -a "$tag" -m "Release $tag"
114+
115+
print_info "Pushing tag to origin..."
116+
git push origin "$tag"
117+
118+
print_success "Tag $tag created and pushed successfully!"
119+
print_info "GitHub Actions will build and publish the release automatically"
120+
}
121+
122+
# Function to show version information
123+
show_version() {
124+
local type=${1:-"patch"}
125+
local current=$(get_current_version)
126+
local next=$(calculate_next_version "$type" "$current")
127+
echo "$next"
128+
}
129+
130+
# Function to bump version
131+
bump_version() {
132+
local type=${1:-"patch"}
133+
134+
# Check git status
135+
check_git_status
136+
137+
# Get current version
138+
local current=$(get_current_version)
139+
print_info "Current version: $current"
140+
141+
# Calculate next version
142+
local next=$(calculate_next_version "$type" "$current")
143+
print_info "Next version: $next"
144+
145+
# Confirm with user
146+
echo -n "Are you sure you want to bump from $current to $next? [y/N]: "
147+
read -r confirm
148+
149+
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
150+
print_warning "Version bump cancelled."
151+
exit 0
152+
fi
153+
154+
# Update version in code
155+
update_version_file "$next"
156+
157+
# Commit the version file change
158+
git add "$VERSION_FILE"
159+
git commit -m "Update version to v$next"
160+
git push origin main
161+
162+
# Create and push tag
163+
create_tag "$next"
164+
165+
print_success "Version bumped from $current to $next"
166+
print_info "Monitor the release at: https://github.com/rootlyhq/cli/releases"
167+
}
168+
169+
# Function to show help
170+
show_help() {
171+
cat << EOF
172+
Usage: $0 [COMMAND] [TYPE]
173+
174+
COMMANDS:
175+
patch Bump patch version (default)
176+
minor Bump minor version
177+
major Bump major version
178+
show Show next version without creating tag
179+
help Show this help message
180+
181+
EXAMPLES:
182+
$0 patch # Bump patch version (1.2.3 → 1.2.4)
183+
$0 minor # Bump minor version (1.2.3 → 1.3.0)
184+
$0 major # Bump major version (1.2.3 → 2.0.0)
185+
$0 show patch # Show next patch version
186+
$0 show minor # Show next minor version
187+
$0 show major # Show next major version
188+
189+
This script manages semantic versioning using git tags.
190+
It updates the version in $VERSION_FILE and creates git tags.
191+
Version tags trigger GitHub Actions to build and publish releases.
192+
193+
EOF
194+
}
195+
196+
# Main script logic
197+
main() {
198+
local command=${1:-"patch"}
199+
local type=${2:-"patch"}
200+
201+
case $command in
202+
"patch"|"minor"|"major")
203+
bump_version "$command"
204+
;;
205+
"show")
206+
show_version "$type"
207+
;;
208+
"help"|"-h"|"--help")
209+
show_help
210+
;;
211+
*)
212+
print_error "Unknown command: $command"
213+
show_help
214+
exit 1
215+
;;
216+
esac
217+
}
218+
219+
# Check if git is available
220+
if ! command -v git &> /dev/null; then
221+
print_error "git is required but not installed."
222+
exit 1
223+
fi
224+
225+
# Check if we're in a git repository
226+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
227+
print_error "Not in a git repository."
228+
exit 1
229+
fi
230+
231+
# Run main function
232+
main "$@"

0 commit comments

Comments
 (0)