输出version到文件
version=`git log --date=iso --pretty=format:"%cd @%H" -1`
if [ $? -ne 0 ]; then
version="unknown version"
fi
compile=`date +"%F %T %z"`" by "`go version`
if [ $? -ne 0 ]; then
compile="unknown datetime"
fi
describe=`git describe --tags 2>/dev/null`
if [ $? -eq 0 ]; then
version="${version} @${describe}"
fi
cat << EOF | gofmt > pkg/utils/version.go
package utils
const (
Version = "$version"
Compile = "$compile"
)
EOF
cat << EOF > bin/version
version = $version
compile = $compile
EOF
或
update-version:
@echo "package goqlc" > $(shell pwd)/version.go
@echo "">> $(shell pwd)/version.go
@echo "const GITREV = \""$(GITREV)"\"" >> $(shell pwd)/version.go
@echo "const VERSION = \""$(VERSION)"\"" >> $(shell pwd)/version.go
@echo "const BUILDTIME = \""$(BUILDTIME)"\"" >> $(shell pwd)/version.go
@echo "const MAINNET = true" >> $(shell pwd)/version.go
升级pkg
#!/bin/bash
echo "> run: go mod tidy"
go mod tidy
pkg_arg=$1
pkg_name_in_gomod=($(cat go.mod | grep "${pkg_arg}"))
if [ -z ${pkg_name_in_gomod} ]
then
echo "> find ${pkg_arg}: not found"
exit
else
echo "> grep ${pkg_arg}: ${pkg_name_in_gomod[@]}"
fi
pkg=${pkg_name_in_gomod[0]}
version=${pkg_name_in_gomod[1]}
read -p "update(y/n)?" is_update
case ${is_update} in
n*)
exit
;;
esac
update_msg=($(go get -u ${pkg} 2>&1 | grep upgraded))
if [ ${#update_msg[@]} -eq 0 ]
then
echo "> nothing to update"
exit
else
version_updated=${update_msg[${#update_msg[@]}-1]}
echo "> updated: ${version} ==> ${version_updated}"
fi