-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" |