fix: partially support v2+ go modules
This patch supports branch-based v2 modules, but not directory-based (i.e., not vN modules with `vN/` directories).
This commit is contained in:
parent
34aa267100
commit
26d14a6262
@ -40,7 +40,8 @@ msg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
statlog() {
|
statlog() {
|
||||||
local rpath="$GOPATH/src/$1"
|
local module="$1"
|
||||||
|
local rpath="$GOPATH/src/$(strip_version "$module")"
|
||||||
local start="${2:-}"
|
local start="${2:-}"
|
||||||
local end="${3:-HEAD}"
|
local end="${3:-HEAD}"
|
||||||
local mailmap_file="$rpath/.mailmap"
|
local mailmap_file="$rpath/.mailmap"
|
||||||
@ -106,9 +107,10 @@ pr_link() {
|
|||||||
release_log() {
|
release_log() {
|
||||||
setopt local_options BASH_REMATCH
|
setopt local_options BASH_REMATCH
|
||||||
|
|
||||||
local repo="$1"
|
local module="$1"
|
||||||
local start="$2"
|
local start="$2"
|
||||||
local end="${3:-HEAD}"
|
local end="${3:-HEAD}"
|
||||||
|
local repo="$(strip_version "$1")"
|
||||||
local dir="$GOPATH/src/$repo"
|
local dir="$GOPATH/src/$repo"
|
||||||
|
|
||||||
local commit pr
|
local commit pr
|
||||||
@ -139,12 +141,11 @@ indent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod_deps() {
|
mod_deps() {
|
||||||
go mod download
|
go list -mod=mod -json -m all | jq 'select(.Version != null)'
|
||||||
go list -json -m all | jq 'select(.Version != null)'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure() {
|
ensure() {
|
||||||
local repo="$1"
|
local repo="$(strip_version "$1")"
|
||||||
local commit="$2"
|
local commit="$2"
|
||||||
local rpath="$GOPATH/src/$repo"
|
local rpath="$GOPATH/src/$repo"
|
||||||
if [[ ! -d "$rpath" ]]; then
|
if [[ ! -d "$rpath" ]]; then
|
||||||
@ -165,21 +166,30 @@ statsummary() {
|
|||||||
jq '. + {Lines: (.Deletions + .Insertions)}'
|
jq '. + {Lines: (.Deletions + .Insertions)}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strip_version() {
|
||||||
|
local repo="$1"
|
||||||
|
if [[ "$repo" =~ '.*/v[0-9]+$' ]]; then
|
||||||
|
repo="$(dirname "$repo")"
|
||||||
|
fi
|
||||||
|
echo "$repo"
|
||||||
|
}
|
||||||
|
|
||||||
recursive_release_log() {
|
recursive_release_log() {
|
||||||
local start="${1:-$(git tag -l | sort -V | grep -v -- '-rc' | grep 'v'| tail -n1)}"
|
local start="${1:-$(git tag -l | sort -V | grep -v -- '-rc' | grep 'v'| tail -n1)}"
|
||||||
local end="${2:-$(git rev-parse HEAD)}"
|
local end="${2:-$(git rev-parse HEAD)}"
|
||||||
local repo_root="$(git rev-parse --show-toplevel)"
|
local repo_root="$(git rev-parse --show-toplevel)"
|
||||||
local package="$(cd "$repo_root" && go list)"
|
local module="$(go list -m)"
|
||||||
|
local dir="$(go list -m -f '{{.Dir}}')"
|
||||||
|
|
||||||
if ! [[ "${GOPATH}/${package}" != "${repo_root}" ]]; then
|
if [[ "${GOPATH}/${module}" -ef "${dir}" ]]; then
|
||||||
echo "This script requires the target package and all dependencies to live in a GOPATH."
|
echo "This script requires the target module and all dependencies to live in a GOPATH."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(
|
(
|
||||||
local result=0
|
local result=0
|
||||||
local workspace="$(mktemp -d)"
|
local workspace="$(mktemp -d)"
|
||||||
#trap "$(printf 'rm -rf "%q"' "$workspace")" INT TERM EXIT
|
trap "$(printf 'rm -rf "%q"' "$workspace")" INT TERM EXIT
|
||||||
cd "$workspace"
|
cd "$workspace"
|
||||||
|
|
||||||
mkdir extern
|
mkdir extern
|
||||||
@ -196,28 +206,28 @@ recursive_release_log() {
|
|||||||
|
|
||||||
rm -f go.mod go.sum
|
rm -f go.mod go.sum
|
||||||
|
|
||||||
printf -- "Generating Changelog for %s %s..%s\n" "$package" "$start" "$end" >&2
|
printf -- "Generating Changelog for %s %s..%s\n" "$module" "$start" "$end" >&2
|
||||||
|
|
||||||
printf -- "- %s:\n" "$package"
|
printf -- "- %s:\n" "$module"
|
||||||
release_log "$package" "$start" "$end" | indent
|
release_log "$module" "$start" "$end" | indent
|
||||||
|
|
||||||
|
|
||||||
statlog "$package" "$start" "$end" > statlog.json
|
statlog "$module" "$start" "$end" > statlog.json
|
||||||
|
|
||||||
dep_changes old_deps.json new_deps.json |
|
dep_changes old_deps.json new_deps.json |
|
||||||
jq --arg filter "$REPO_FILTER" 'select(.Path | match($filter))' |
|
jq --arg filter "$REPO_FILTER" 'select(.Path | match($filter))' |
|
||||||
# Compute changelogs
|
# Compute changelogs
|
||||||
jq -r '"\(.Path) \(.New.Version) \(.New.Ref) \(.Old.Version) \(.Old.Ref // "")"' |
|
jq -r '"\(.Path) \(.New.Version) \(.New.Ref) \(.Old.Version) \(.Old.Ref // "")"' |
|
||||||
while read repo new new_ref old old_ref; do
|
while read module new new_ref old old_ref; do
|
||||||
if ! ensure "$repo" "$new_ref"; then
|
if ! ensure "$module" "$new_ref"; then
|
||||||
result=1
|
result=1
|
||||||
local changelog="failed to fetch repo"
|
local changelog="failed to fetch repo"
|
||||||
else
|
else
|
||||||
statlog "$repo" "$old_ref" "$new_ref" >> statlog.json
|
statlog "$module" "$old_ref" "$new_ref" >> statlog.json
|
||||||
local changelog="$(release_log "$repo" "$old_ref" "$new_ref")"
|
local changelog="$(release_log "$module" "$old_ref" "$new_ref")"
|
||||||
fi
|
fi
|
||||||
if [[ -n "$changelog" ]]; then
|
if [[ -n "$changelog" ]]; then
|
||||||
printf -- "- %s (%s -> %s):\n" "$repo" "$old" "$new"
|
printf -- "- %s (%s -> %s):\n" "$module" "$old" "$new"
|
||||||
echo "$changelog" | indent
|
echo "$changelog" | indent
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user