2023-06-06 17:10:32 +08:00
|
|
|
|
#!/usr/bin/env bash
|
2025-09-02 22:49:05 +08:00
|
|
|
|
|
2026-01-26 20:37:48 +08:00
|
|
|
|
# Function to run sed in-place with OS-specific options
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace() {
|
2025-09-02 22:49:05 +08:00
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
2026-01-26 20:37:48 +08:00
|
|
|
|
# macOS - requires empty string after -i
|
|
|
|
|
|
sed -i '' "$@"
|
2025-09-02 22:49:05 +08:00
|
|
|
|
else
|
|
|
|
|
|
# Linux/Windows Git Bash
|
2026-01-26 20:37:48 +08:00
|
|
|
|
sed -i "$@"
|
2025-09-02 22:49:05 +08:00
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-06 17:10:32 +08:00
|
|
|
|
if [ $# -ne 2 ]; then
|
|
|
|
|
|
echo "Parameter exception, please execute in the format of $0 [directory] [version number]"
|
|
|
|
|
|
echo "PS:$0 ./ v2.4.0"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! -d "$1" ]; then
|
|
|
|
|
|
echo "Error: Directory does not exist"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$2" != v* ]]; then
|
|
|
|
|
|
echo "Error: Version number must start with v"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2023-10-18 20:01:16 +08:00
|
|
|
|
workdir=.
|
2023-06-06 17:10:32 +08:00
|
|
|
|
newVersion=$2
|
2025-03-09 22:31:20 +08:00
|
|
|
|
echo "Prepare to replace the GoFrame library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}"
|
2023-06-06 17:10:32 +08:00
|
|
|
|
|
2023-11-22 20:49:07 +08:00
|
|
|
|
# check find command support or not
|
|
|
|
|
|
output=$(find "${workdir}" -name go.mod 2>&1)
|
|
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
|
|
echo "Error: please use bash or zsh to run!"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2023-06-06 17:10:32 +08:00
|
|
|
|
if [[ true ]]; then
|
2024-12-05 20:21:19 +08:00
|
|
|
|
# Use sed to replace the version number in version.go
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace 's/VERSION = ".*"/VERSION = "'${newVersion}'"/' version.go
|
2024-12-05 20:21:19 +08:00
|
|
|
|
|
|
|
|
|
|
# Use sed to replace the version number in README.MD
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace 's/version=[^"]*/version='${newVersion}'/' README.MD
|
|
|
|
|
|
sed_replace 's/version=[^"]*/version='${newVersion}'/' README.zh_CN.MD
|
2023-06-06 17:10:32 +08:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -f "go.work" ]; then
|
|
|
|
|
|
mv go.work go.work.version.bak
|
|
|
|
|
|
echo "Back up the go.work file to avoid affecting the upgrade"
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
for file in `find ${workdir} -name go.mod`; do
|
|
|
|
|
|
goModPath=$(dirname $file)
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
echo "processing dir: $goModPath"
|
2024-12-17 09:24:13 +08:00
|
|
|
|
|
|
|
|
|
|
if [[ $goModPath =~ "/testdata/" ]]; then
|
|
|
|
|
|
echo "ignore testdata path $goModPath"
|
|
|
|
|
|
continue 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2025-03-09 22:31:20 +08:00
|
|
|
|
if [[ $goModPath =~ "/examples/" ]]; then
|
|
|
|
|
|
echo "ignore examples path $goModPath"
|
|
|
|
|
|
continue 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2023-06-06 17:10:32 +08:00
|
|
|
|
cd $goModPath
|
2026-01-26 20:37:48 +08:00
|
|
|
|
|
|
|
|
|
|
# Add replace directive for local development.
|
2023-10-18 20:01:16 +08:00
|
|
|
|
if [ $goModPath = "./cmd/gf" ]; then
|
|
|
|
|
|
mv go.work go.work.version.bak
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/v2=../../
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/clickhouse/v2=../../contrib/drivers/clickhouse
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/mssql/v2=../../contrib/drivers/mssql
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/mysql/v2=../../contrib/drivers/mysql
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/oracle/v2=../../contrib/drivers/oracle
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/pgsql/v2=../../contrib/drivers/pgsql
|
|
|
|
|
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/sqlite/v2=../../contrib/drivers/sqlite
|
|
|
|
|
|
fi
|
2025-11-10 17:38:50 +08:00
|
|
|
|
# Remove indirect dependencies
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace '/\/\/ indirect/d' go.mod
|
2023-06-06 17:10:32 +08:00
|
|
|
|
go mod tidy
|
2025-03-09 22:31:20 +08:00
|
|
|
|
# Remove toolchain line if exists
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace '/^toolchain/d' go.mod
|
2025-03-09 22:31:20 +08:00
|
|
|
|
|
2026-01-26 20:37:48 +08:00
|
|
|
|
# Upgrading only GoFrame related libraries, sometimes even if a version number is specified,
|
2025-03-09 22:31:20 +08:00
|
|
|
|
# it may not be possible to successfully upgrade. Please confirm before submitting the code
|
2023-06-06 17:10:32 +08:00
|
|
|
|
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf"
|
2026-01-26 20:37:48 +08:00
|
|
|
|
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" | xargs -L1 go get -v
|
2025-11-10 17:38:50 +08:00
|
|
|
|
# Remove indirect dependencies
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace '/\/\/ indirect/d' go.mod
|
2023-06-06 17:10:32 +08:00
|
|
|
|
go mod tidy
|
2025-03-09 22:31:20 +08:00
|
|
|
|
# Remove toolchain line if exists
|
2026-02-11 14:37:49 +08:00
|
|
|
|
sed_replace '/^toolchain/d' go.mod
|
2023-10-18 20:01:16 +08:00
|
|
|
|
if [ $goModPath = "./cmd/gf" ]; then
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/v2
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/clickhouse/v2
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/mssql/v2
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/mysql/v2
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/oracle/v2
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/pgsql/v2
|
|
|
|
|
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/sqlite/v2
|
|
|
|
|
|
mv go.work.version.bak go.work
|
|
|
|
|
|
fi
|
2023-06-06 17:10:32 +08:00
|
|
|
|
cd -
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
if [ -f "go.work.version.bak" ]; then
|
|
|
|
|
|
mv go.work.version.bak go.work
|
|
|
|
|
|
echo "Restore the go.work file"
|
|
|
|
|
|
fi
|