mirror of
https://github.com/iyear/tdl
synced 2025-01-05 10:27:16 +08:00
chore(hack): add release_mod script
This commit is contained in:
parent
3459602a81
commit
dd186e37b5
44
hack/lib.sh
Normal file
44
hack/lib.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_MODULE=$(go list -m)
|
||||
|
||||
function set_root_dir {
|
||||
# shellcheck disable=SC2034
|
||||
ROOT_DIR=$(go list -f '{{.Dir}}' "${ROOT_MODULE}")
|
||||
}
|
||||
|
||||
set_root_dir
|
||||
|
||||
#### Convenient IO methods #####
|
||||
COLOR_RED='\033[0;31m'
|
||||
COLOR_ORANGE='\033[0;33m'
|
||||
COLOR_GREEN='\033[0;32m'
|
||||
COLOR_BLUE='\033[0;94m'
|
||||
COLOR_BOLD='\033[1m'
|
||||
COLOR_NONE='\033[0m' # No Color
|
||||
|
||||
function log_error {
|
||||
>&2 echo -n -e "${COLOR_BOLD}${COLOR_RED}"
|
||||
>&2 echo "$@"
|
||||
>&2 echo -n -e "${COLOR_NONE}"
|
||||
}
|
||||
|
||||
function log_warn {
|
||||
>&2 echo -n -e "${COLOR_ORANGE}"
|
||||
>&2 echo "$@"
|
||||
>&2 echo -n -e "${COLOR_NONE}"
|
||||
}
|
||||
|
||||
function log_succ {
|
||||
>&2 echo -n -e "${COLOR_GREEN}"
|
||||
>&2 echo "$@"
|
||||
>&2 echo -n -e "${COLOR_NONE}"
|
||||
}
|
||||
|
||||
function log_info {
|
||||
>&2 echo -n -e "${COLOR_BLUE}"
|
||||
>&2 echo "$@"
|
||||
>&2 echo -n -e "${COLOR_NONE}"
|
||||
}
|
83
hack/release_mod.sh
Normal file
83
hack/release_mod.sh
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Examples:
|
||||
|
||||
# Update all dependencies to version vX.Y.Z
|
||||
# ./hack/release_mod.sh deps vX.Y.Z
|
||||
|
||||
# Add tags to all modules with version vX.Y.Z
|
||||
# ./hack/release_mod.sh tags v0.1.0
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source ./hack/lib.sh
|
||||
|
||||
cmd="${1}"
|
||||
version="${2}"
|
||||
if [ -z "${version}" ]; then
|
||||
log_error "version argument is required"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
go mod tidy
|
||||
|
||||
dirs=$(find . -name "go.mod" -not -path "./docs/*" -exec dirname {} \;)
|
||||
|
||||
function deps() {
|
||||
log_info "Updating dependencies to version ${version}"
|
||||
log_info ""
|
||||
|
||||
for dir in ${dirs}; do
|
||||
(
|
||||
log_info "Processing ${dir}"
|
||||
|
||||
cd "${dir}"
|
||||
|
||||
go mod tidy
|
||||
|
||||
modules=$(go list -f '{{if not .Main}}{{if not .Indirect}}{{.Path}}{{end}}{{end}}' -m all)
|
||||
deps=$(echo "${modules}" | grep -E "${ROOT_MODULE}/.*" || true)
|
||||
|
||||
for dep in ${deps}; do
|
||||
go mod edit -require "${dep}@${version}"
|
||||
done
|
||||
|
||||
go mod tidy
|
||||
|
||||
cd "${ROOT_DIR}"
|
||||
|
||||
log_succ " Processed ${dir}"
|
||||
)
|
||||
done
|
||||
|
||||
log_succ ""
|
||||
log_succ "Dependencies updated, and commit them manually"
|
||||
}
|
||||
|
||||
function tags(){
|
||||
log_info "Adding tags to all modules with version ${version}"
|
||||
log_info ""
|
||||
|
||||
for dir in ${dirs}; do
|
||||
(
|
||||
log_info "Processing ${dir}"
|
||||
prefix="${dir#./}"
|
||||
prefix="${prefix#.}"
|
||||
# if prefix is not empty, append a slash
|
||||
if [ -n "${prefix}" ]; then
|
||||
prefix="${prefix}/"
|
||||
fi
|
||||
|
||||
tag="${prefix}${version}"
|
||||
git tag "${tag}"
|
||||
|
||||
log_succ " Tag ${tag}"
|
||||
)
|
||||
done
|
||||
|
||||
log_succ ""
|
||||
log_succ "Tags added, and push them manually"
|
||||
}
|
||||
|
||||
# run the function
|
||||
"${cmd}"
|
Loading…
Reference in New Issue
Block a user