Skip to content

Commit b1ed2da

Browse files
committed
chore: add release scripts
1 parent 6c112da commit b1ed2da

File tree

5 files changed

+611
-0
lines changed

5 files changed

+611
-0
lines changed

scripts/.utils/check_go_mod.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Copyright 2025 CloudWeGo Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# Go Module Dependency Checker
18+
#
19+
# This script validates that all CloudWeGo dependencies in go.mod use proper
20+
# semantic version tags (vA.B.C format) instead of commit hashes or branch names.
21+
#
22+
# Purpose:
23+
# - Ensures CloudWeGo dependencies follow proper versioning practices
24+
# - Validates go.mod contains only formal release versions
25+
# - Prevents release with non-standard dependency versions
26+
#
27+
# Usage:
28+
# ./scripts/.check_go_mod.sh
29+
#
30+
# The script:
31+
# 1. Searches go.mod for github.com/cloudwego/* dependencies
32+
# 2. Checks that each dependency uses semantic versioning (vX.Y.Z)
33+
# 3. Reports any dependencies using non-standard versions
34+
# 4. Exits with error if invalid dependencies are found
35+
#
36+
# Called by:
37+
# - release.sh (before creating release tags)
38+
# - release-hotfix.sh (before creating hotfix tags)
39+
#
40+
41+
GO_MOD_FILE="go.mod"
42+
43+
cd $(git rev-parse --show-toplevel)
44+
45+
# Check go.mod for cloudwego dependencies using proper tag versions
46+
echo "🔍 Checking go.mod for cloudwego dependencies..."
47+
if [ -f "$GO_MOD_FILE" ]; then
48+
# Find cloudwego dependencies that don't use formal tag versions (vA.B.C format)
49+
invalid_deps=$(grep "github.com/cloudwego/" "$GO_MOD_FILE" | \
50+
grep -v "// indirect" | grep -v "module " | \
51+
grep -v -E "v[0-9]+\.[0-9]+\.[0-9]+$" | awk '{print $1 " " $2}')
52+
53+
if [ -n "$invalid_deps" ]; then
54+
echo "❌ Error: Found cloudwego dependencies not using formal tag versions:"
55+
echo
56+
echo " $invalid_deps"
57+
echo
58+
echo " All github.com/cloudwego/* dependencies must use formal tag versions like v0.1.2 format"
59+
echo " Please update go.mod to use proper tagged versions for these dependencies"
60+
exit 1
61+
else
62+
echo "✅ All cloudwego dependencies use formal tag versions"
63+
fi
64+
else
65+
echo "⚠️ WARNING: go.mod not found"
66+
fi

scripts/.utils/check_version.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
# Copyright 2025 CloudWeGo Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# Version Consistency Checker
18+
#
19+
# This script validates that the version in version.go matches the intended
20+
# release version to ensure consistency across the codebase.
21+
#
22+
# Purpose:
23+
# - Prevents releasing with mismatched version numbers
24+
# - Ensures version.go is updated before creating release tags
25+
# - Provides interactive confirmation for version mismatches
26+
#
27+
# Usage:
28+
# ./scripts/.check_version.sh <target_version>
29+
#
30+
# Parameters:
31+
# target_version - The version being released (e.g., v1.2.3)
32+
#
33+
# The script:
34+
# 1. Reads the Version constant from version.go
35+
# 2. Compares it with the target release version
36+
# 3. Warns if versions don't match and prompts for confirmation
37+
# 4. Exits with error if user chooses not to continue
38+
#
39+
# Called by:
40+
# - release.sh (before creating release tags)
41+
# - release-hotfix.sh (before creating hotfix tags)
42+
#
43+
44+
VERSION_FILE="version.go"
45+
new_version=$1
46+
47+
if [ -z "$new_version" ]; then
48+
echo "❌ Error: Version parameter is required"
49+
echo "Usage: $0 <version>"
50+
exit 1
51+
fi
52+
53+
cd $(git rev-parse --show-toplevel)
54+
55+
if [ -f "$VERSION_FILE" ]; then
56+
version_go_version=$(grep -o 'Version = "v[^"]*"' $VERSION_FILE | sed 's/Version = "\([^"]*\)"/\1/')
57+
if [ "$version_go_version" != "$new_version" ]; then
58+
echo "⚠️ WARNING: $VERSION_FILE contains $version_go_version but you're releasing $new_version"
59+
echo " Please update $VERSION_FILE to match the release version."
60+
read -p " Continue anyway? (y/N): " continue_anyway
61+
if [ "$continue_anyway" != "y" ] && [ "$continue_anyway" != "Y" ]; then
62+
echo "❌ Release cancelled"
63+
exit 1
64+
fi
65+
else
66+
echo "$VERSION_FILE matches release version: $new_version"
67+
fi
68+
else
69+
echo "⚠️ WARNING: $VERSION_FILE not found"
70+
fi

scripts/.utils/funcs.sh

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/bin/bash
2+
# Copyright 2025 CloudWeGo Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# Shared utility functions for release scripts
18+
#
19+
20+
# Function to show changes between two commits/tags
21+
# Usage: show_changes <from_ref> <to_ref> [title]
22+
show_changes() {
23+
local from_ref=$1
24+
local to_ref=$2
25+
local title=${3:-"Changes"}
26+
27+
echo
28+
echo "📋 $title:"
29+
echo "$(printf '%*s' ${#title} | tr ' ' '=')"
30+
31+
# Check if there are any commits between the references
32+
local commit_count=$(git rev-list --count "$from_ref..$to_ref")
33+
if [ "$commit_count" -eq 0 ]; then
34+
echo "✅ No new commits. Nothing to release."
35+
return 1
36+
fi
37+
38+
# Show changes grouped by author email
39+
git log --pretty=format:"%ae|%h %s" "$from_ref..$to_ref" | sort | awk -F'|' '{
40+
if ($1 != prev_email) {
41+
if (prev_email != "") print ""
42+
print "👤 " $1 ":"
43+
prev_email = $1
44+
}
45+
print " " $2
46+
}'
47+
48+
return 0
49+
}
50+
51+
# Function to show changes for first release (no previous version)
52+
# Usage: show_first_release_changes <commit> [limit]
53+
show_first_release_changes() {
54+
local commit=$1
55+
local limit=${2:-10}
56+
57+
echo
58+
echo "📋 This is the first release - showing recent commits:"
59+
echo "===================================================="
60+
61+
git log --pretty=format:"%ae|%h %s" -"$limit" "$commit" | sort | awk -F'|' '{
62+
if ($1 != prev_email) {
63+
if (prev_email != "") print ""
64+
print "👤 " $1 ":"
65+
prev_email = $1
66+
}
67+
print " " $2
68+
}'
69+
}
70+
71+
# Function to ask user for confirmation of changes
72+
# Usage: confirm_changes
73+
confirm_changes() {
74+
echo
75+
echo "📝 Please review the changes above."
76+
read -p "Do you want to proceed with these changes? (y/N): " confirm_changes
77+
if [ "$confirm_changes" != "y" ] && [ "$confirm_changes" != "Y" ]; then
78+
echo "❌ Release cancelled by user"
79+
return 1
80+
fi
81+
return 0
82+
}
83+
84+
# Function to check if commit exists on origin
85+
# Usage: check_commit_exists <commit> <branch>
86+
check_commit_exists() {
87+
local commit=$1
88+
local branch=$2
89+
if ! git cat-file -e "$commit" 2>/dev/null; then
90+
echo "❌ Error: Commit $commit does not exist locally"
91+
exit 1
92+
fi
93+
94+
if ! git branch -r --contains "$commit" | grep -q "origin/$branch$"; then
95+
echo "❌ Error: Commit $commit does not exist on origin/$branch"
96+
exit 1
97+
fi
98+
}
99+
100+
# Function to get latest version tag
101+
# Usage: get_latest_version
102+
get_latest_version() {
103+
local latest_tag=$(git tag -l "v*.*.*" | sort -V | tail -n1)
104+
if [ -z "$latest_tag" ]; then
105+
echo "v0.0.0"
106+
else
107+
echo "$latest_tag"
108+
fi
109+
}
110+
111+
# Function to get latest patch version for a given minor version
112+
# Usage: get_latest_patch_version <minor_version>
113+
get_latest_patch_version() {
114+
local minor_version=$1
115+
# Remove 'v' prefix and '.x' suffix if present
116+
minor_version=${minor_version#v}
117+
minor_version=${minor_version%.x}
118+
119+
local latest_patch=$(git tag -l "v${minor_version}.*" | sort -V | tail -n1)
120+
if [ -z "$latest_patch" ]; then
121+
echo "No tags found for minor version v${minor_version}.x"
122+
return 1
123+
else
124+
echo "$latest_patch"
125+
fi
126+
}
127+
128+
# Function to increment version
129+
# Usage: increment_version <version> <type>
130+
# where type is one of: major, minor, patch
131+
increment_version() {
132+
local version=$1
133+
local type=$2
134+
135+
# Remove 'v' prefix
136+
version=${version#v}
137+
138+
IFS='.' read -r major minor patch <<< "$version"
139+
140+
case $type in
141+
"major")
142+
major=$((major + 1))
143+
minor=0
144+
patch=0
145+
;;
146+
"minor")
147+
minor=$((minor + 1))
148+
patch=0
149+
;;
150+
"patch")
151+
patch=$((patch + 1))
152+
;;
153+
esac
154+
155+
echo "v$major.$minor.$patch"
156+
}
157+
158+
# Function to increment patch version (convenience wrapper)
159+
# Usage: increment_patch_version <version>
160+
increment_patch_version() {
161+
local version=$1
162+
increment_version "$version" "patch"
163+
}

0 commit comments

Comments
 (0)