Skip to content

chore: add release scripts #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions scripts/.utils/check_go_mod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# Copyright 2025 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Go Module Dependency Checker
#
# This script validates that all CloudWeGo dependencies in go.mod use proper
# semantic version tags (vA.B.C format) instead of commit hashes or branch names.
#
# Purpose:
# - Ensures CloudWeGo dependencies follow proper versioning practices
# - Validates go.mod contains only formal release versions
# - Prevents release with non-standard dependency versions
#
# Usage:
# ./scripts/.utils/check_go_mod.sh
#
# The script:
# 1. Searches go.mod for github.com/cloudwego/* dependencies
# 2. Checks that each dependency uses semantic versioning (vX.Y.Z)
# 3. Reports any dependencies using non-standard versions
# 4. Exits with error if invalid dependencies are found
#
# Called by:
# - release.sh (before creating release tags)
# - release-hotfix.sh (before creating hotfix tags)
#

GO_MOD_FILE="go.mod"

cd $(git rev-parse --show-toplevel)

# Check go.mod for cloudwego dependencies using proper tag versions
echo "🔍 Checking go.mod for cloudwego dependencies..."
if [ -f "$GO_MOD_FILE" ]; then
# Find cloudwego dependencies that don't use formal tag versions (vA.B.C format)
invalid_deps=$(grep "github.com/cloudwego/" "$GO_MOD_FILE" | \
grep -v "// indirect" | grep -v "module " | \
grep -v -E "v[0-9]+\.[0-9]+\.[0-9]+$" | awk '{print $1 " " $2}')

if [ -n "$invalid_deps" ]; then
echo "❌ Error: Found cloudwego dependencies not using formal tag versions:"
echo
echo " $invalid_deps"
echo
echo " All github.com/cloudwego/* dependencies must use formal tag versions like v0.1.2 format"
echo " Please update go.mod to use proper tagged versions for these dependencies"
exit 1
else
echo "✅ All cloudwego dependencies use formal tag versions"
fi
else
echo "⚠️ WARNING: go.mod not found"
fi
70 changes: 70 additions & 0 deletions scripts/.utils/check_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
# Copyright 2025 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Version Consistency Checker
#
# This script validates that the version in version.go matches the intended
# release version to ensure consistency across the codebase.
#
# Purpose:
# - Prevents releasing with mismatched version numbers
# - Ensures version.go is updated before creating release tags
# - Provides interactive confirmation for version mismatches
#
# Usage:
# ./scripts/.utils/check_version.sh <target_version>
#
# Parameters:
# target_version - The version being released (e.g., v1.2.3)
#
# The script:
# 1. Reads the Version constant from version.go
# 2. Compares it with the target release version
# 3. Warns if versions don't match and prompts for confirmation
# 4. Exits with error if user chooses not to continue
#
# Called by:
# - release.sh (before creating release tags)
# - release-hotfix.sh (before creating hotfix tags)
#

VERSION_FILE="version.go"
new_version=$1

if [ -z "$new_version" ]; then
echo "❌ Error: Version parameter is required"
echo "Usage: $0 <version>"
exit 1
fi

cd $(git rev-parse --show-toplevel)

if [ -f "$VERSION_FILE" ]; then
version_go_version=$(grep -o 'Version = "v[^"]*"' $VERSION_FILE | sed 's/Version = "\([^"]*\)"/\1/')
if [ "$version_go_version" != "$new_version" ]; then
echo "⚠️ WARNING: $VERSION_FILE contains $version_go_version but you're releasing $new_version"
echo " Please update $VERSION_FILE to match the release version."
read -p " Continue anyway? (y/N): " continue_anyway
if [ "$continue_anyway" != "y" ] && [ "$continue_anyway" != "Y" ]; then
echo "❌ Release cancelled"
exit 1
fi
else
echo "✅ $VERSION_FILE matches release version: $new_version"
fi
else
echo "⚠️ WARNING: $VERSION_FILE not found"
fi
163 changes: 163 additions & 0 deletions scripts/.utils/funcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/bin/bash
# Copyright 2025 CloudWeGo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Shared utility functions for release scripts
#

# Function to show changes between two commits/tags
# Usage: show_changes <from_ref> <to_ref> [title]
show_changes() {
local from_ref=$1
local to_ref=$2
local title=${3:-"Changes"}

echo
echo "📋 $title:"
echo "$(printf '%*s' ${#title} | tr ' ' '=')"

# Check if there are any commits between the references
local commit_count=$(git rev-list --count "$from_ref..$to_ref")
if [ "$commit_count" -eq 0 ]; then
echo "✅ No new commits. Nothing to release."
return 1
fi

# Show changes grouped by author email
git log --pretty=format:"%ae|%h %s" "$from_ref..$to_ref" | sort | awk -F'|' '{
if ($1 != prev_email) {
if (prev_email != "") print ""
print "👤 " $1 ":"
prev_email = $1
}
print " " $2
}'

return 0
}

# Function to show changes for first release (no previous version)
# Usage: show_first_release_changes <commit> [limit]
show_first_release_changes() {
local commit=$1
local limit=${2:-10}

echo
echo "📋 This is the first release - showing recent commits:"
echo "===================================================="

git log --pretty=format:"%ae|%h %s" -"$limit" "$commit" | sort | awk -F'|' '{
if ($1 != prev_email) {
if (prev_email != "") print ""
print "👤 " $1 ":"
prev_email = $1
}
print " " $2
}'
}

# Function to ask user for confirmation of changes
# Usage: confirm_changes
confirm_changes() {
echo
echo "📝 Please review the changes above."
read -p "Do you want to proceed with these changes? (y/N): " confirm_changes
if [ "$confirm_changes" != "y" ] && [ "$confirm_changes" != "Y" ]; then
echo "❌ Release cancelled by user"
return 1
fi
return 0
}

# Function to check if commit exists on origin
# Usage: check_commit_exists <commit> <branch>
check_commit_exists() {
local commit=$1
local branch=$2
if ! git cat-file -e "$commit" 2>/dev/null; then
echo "❌ Error: Commit $commit does not exist locally"
exit 1
fi

if ! git branch -r --contains "$commit" | grep -q "origin/$branch$"; then
echo "❌ Error: Commit $commit does not exist on origin/$branch"
exit 1
fi
}

# Function to get latest version tag
# Usage: get_latest_version
get_latest_version() {
local latest_tag=$(git tag -l "v*.*.*" | sort -V | tail -n1)
if [ -z "$latest_tag" ]; then
echo "v0.0.0"
else
echo "$latest_tag"
fi
}

# Function to get latest patch version for a given minor version
# Usage: get_latest_patch_version <minor_version>
get_latest_patch_version() {
local minor_version=$1
# Remove 'v' prefix and '.x' suffix if present
minor_version=${minor_version#v}
minor_version=${minor_version%.x}

local latest_patch=$(git tag -l "v${minor_version}.*" | sort -V | tail -n1)
if [ -z "$latest_patch" ]; then
echo "No tags found for minor version v${minor_version}.x"
return 1
else
echo "$latest_patch"
fi
}

# Function to increment version
# Usage: increment_version <version> <type>
# where type is one of: major, minor, patch
increment_version() {
local version=$1
local type=$2

# Remove 'v' prefix
version=${version#v}

IFS='.' read -r major minor patch <<< "$version"

case $type in
"major")
major=$((major + 1))
minor=0
patch=0
;;
"minor")
minor=$((minor + 1))
patch=0
;;
"patch")
patch=$((patch + 1))
;;
esac

echo "v$major.$minor.$patch"
}

# Function to increment patch version (convenience wrapper)
# Usage: increment_patch_version <version>
increment_patch_version() {
local version=$1
increment_version "$version" "patch"
}
Loading