From 9bc9fc45457e1d4c76828d36ed45aeec55263cb0 Mon Sep 17 00:00:00 2001 From: HaiLaz <739476267@qq.com> Date: Tue, 6 Jun 2023 17:10:32 +0800 Subject: [PATCH] improve command `make version` (#2676) --- .set_version.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 28 ++------------------------ 2 files changed, 55 insertions(+), 26 deletions(-) create mode 100755 .set_version.sh diff --git a/.set_version.sh b/.set_version.sh new file mode 100755 index 000000000..33fc5dba8 --- /dev/null +++ b/.set_version.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +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 + +workdir=$1 +newVersion=$2 +echo "Prepare to replace the GF library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}" + +if [[ true ]]; then + echo "package gf" > version.go + echo "" >> version.go + echo "const (" >> version.go + echo -e "\t// VERSION is the current GoFrame version." >> version.go + echo -e "\tVERSION = \"${newVersion}\"" >> version.go + echo ")" >> version.go +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" + cd $goModPath + go mod tidy + # Upgrading only GF related libraries, sometimes even if a version number is specified, it may not be possible to successfully upgrade. Please confirm before submitting the code + go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" + go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" | xargs -L1 go get -v + go mod tidy + cd - +done + +if [ -f "go.work.version.bak" ]; then + mv go.work.version.bak go.work + echo "Restore the go.work file" +fi \ No newline at end of file diff --git a/Makefile b/Makefile index b8c6f6f6f..2210ebcd9 100644 --- a/Makefile +++ b/Makefile @@ -18,33 +18,9 @@ lint: # make version to=v2.4.0 .PHONY: version version: - $(eval files=$(shell find . -name go.mod)) @set -e; \ newVersion=$(to); \ - echo "The version will be set to $$newVersion"; \ - if [[ $$newVersion =~ "v" ]]; then \ - latestVersion=$$newVersion; \ - echo "package gf" > version.go; \ - echo "" >> version.go; \ - echo "const (" >> version.go; \ - echo -e "\t// VERSION is the current GoFrame version." >> version.go; \ - echo -e "\tVERSION = \"$$latestVersion\"" >> version.go; \ - echo ")" >> version.go; \ - else \ - latestVersion=latest; \ - fi; \ - for file in ${files}; do \ - goModPath=$$(dirname $$file); \ - if [[ $$goModPath =~ "./contrib" || $$goModPath =~ "./cmd/gf" || $$goModPath =~ "./example" ]]; then \ - echo "" ; \ - echo "processing dir: $$goModPath"; \ - cd $$goModPath; \ - go mod tidy; \ - go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@$$latestVersion{{end}}" -m all | grep "^github.com/gogf/gf/contrib" | xargs -L1 go get -v; \ - go get -v github.com/gogf/gf/v2@$$latestVersion; \ - go mod tidy; \ - cd -; \ - fi \ - done + ./.set_version.sh ./ $$newVersion; \ + echo "make version to=$(to) done"