@cryptotaxi247 / kubo / commits / c74498158

fix(mkreleaselog): partially handle v2 modules

We can now handle v2 modules that use tags, but not v2 modules that use v2 sub-directories.

Steven Allen committed Apr 13, 2021 at 12:45 UTC c744981585519d632d4deb02a7cc0bc56370d2fa
1 file changed +27 -16
bin/mkreleaselog
+27 -16
@@ -40,7 +40,8 @@ msg() {
40 }
41
42 statlog() {
43 - local rpath="$GOPATH/src/$1"
43 + local module="$1"
44 + local rpath="$GOPATH/src/$(strip_version "$module")"
45 local start="${2:-}"
46 local end="${3:-HEAD}"
47 local mailmap_file="$rpath/.mailmap"
@@ -106,9 +107,10 @@ pr_link() {
107 release_log() {
108 setopt local_options BASH_REMATCH
109
109 - local repo="$1"
110 + local module="$1"
111 local start="$2"
112 local end="${3:-HEAD}"
113 + local repo="$(strip_version "$1")"
114 local dir="$GOPATH/src/$repo"
115
116 local commit pr
@@ -139,11 +141,11 @@ indent() {
141 }
142
143 mod_deps() {
142 - go list -json -m all | jq 'select(.Version != null)'
144 + go list -mod=mod -json -m all | jq 'select(.Version != null)'
145 }
146
147 ensure() {
146 - local repo="$1"
148 + local repo="$(strip_version "$1")"
149 local commit="$2"
150 local rpath="$GOPATH/src/$repo"
151 if [[ ! -d "$rpath" ]]; then
@@ -164,14 +166,23 @@ statsummary() {
166 jq '. + {Lines: (.Deletions + .Insertions)}'
167 }
168
169 +strip_version() {
170 + local repo="$1"
171 + if [[ "$repo" =~ '.*/v[0-9]+$' ]]; then
172 + repo="$(dirname "$repo")"
173 + fi
174 + echo "$repo"
175 +}
176 +
177 recursive_release_log() {
178 local start="${1:-$(git tag -l | sort -V | grep -v -- '-rc' | grep 'v'| tail -n1)}"
179 local end="${2:-$(git rev-parse HEAD)}"
180 local repo_root="$(git rev-parse --show-toplevel)"
171 - local package="$(cd "$repo_root" && go list)"
181 + local module="$(go list -m)"
182 + local dir="$(go list -m -f '{{.Dir}}')"
183
173 - if ! [[ "${GOPATH}/${package}" != "${repo_root}" ]]; then
174 - echo "This script requires the target package and all dependencies to live in a GOPATH."
184 + if [[ "${GOPATH}/${module}" -ef "${dir}" ]]; then
185 + echo "This script requires the target module and all dependencies to live in a GOPATH."
186 return 1
187 fi
188
@@ -191,28 +202,28 @@ recursive_release_log() {
202
203 rm -f go.mod go.sum
204
194 - printf -- "Generating Changelog for %s %s..%s\n" "$package" "$start" "$end" >&2
205 + printf -- "Generating Changelog for %s %s..%s\n" "$module" "$start" "$end" >&2
206
196 - printf -- "- %s:\n" "$package"
197 - release_log "$package" "$start" "$end" | indent
207 + printf -- "- %s:\n" "$module"
208 + release_log "$module" "$start" "$end" | indent
209
210
200 - statlog "$package" "$start" "$end" > statlog.json
211 + statlog "$module" "$start" "$end" > statlog.json
212
213 dep_changes old_deps.json new_deps.json |
214 jq --arg filter "$REPO_FILTER" 'select(.Path | match($filter))' |
215 # Compute changelogs
216 jq -r '"\(.Path) \(.New.Version) \(.New.Ref) \(.Old.Version) \(.Old.Ref // "")"' |
206 - while read repo new new_ref old old_ref; do
207 - if ! ensure "$repo" "$new_ref"; then
217 + while read module new new_ref old old_ref; do
218 + if ! ensure "$module" "$new_ref"; then
219 result=1
220 local changelog="failed to fetch repo"
221 else
211 - statlog "$repo" "$old_ref" "$new_ref" >> statlog.json
212 - local changelog="$(release_log "$repo" "$old_ref" "$new_ref")"
222 + statlog "$module" "$old_ref" "$new_ref" >> statlog.json
223 + local changelog="$(release_log "$module" "$old_ref" "$new_ref")"
224 fi
225 if [[ -n "$changelog" ]]; then
215 - printf -- "- %s (%s -> %s):\n" "$repo" "$old" "$new"
226 + printf -- "- %s (%s -> %s):\n" "$module" "$old" "$new"
227 echo "$changelog" | indent
228 fi
229 done