From 9f6ee11257b0781aa6017cb004abfa8cf95ffc8a Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 13 Dec 2022 15:35:56 -0800 Subject: [PATCH] Slightly improved "diff-pr" output, especially around build-order This should help avoid "empty cat" output we saw recently when something failed to fetch but was otherwise valid. The current implementation is trying to do two things with one output: 1. normalized `bashbrew cat` diff 2. visualize `--build-order` changes This change splits those into two separate things because combining them ends up making the diff harder to read than it should be ("changed tags + changed commit" leading to a full reordering of the diff because build-order also changed). --- _bashbrew-cat-sorted.sh | 4 +--- diff-pr.sh | 48 +++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/_bashbrew-cat-sorted.sh b/_bashbrew-cat-sorted.sh index 2730b5ef24f40..5361a1df89e12 100755 --- a/_bashbrew-cat-sorted.sh +++ b/_bashbrew-cat-sorted.sh @@ -5,8 +5,7 @@ set -Eeuo pipefail images="$( bashbrew list --repos --uniq "$@" \ - | sort -uV \ - | xargs -r bashbrew list --repos --uniq --build-order + | sort -uV )" set -- $images @@ -34,7 +33,6 @@ for img; do bashbrew list --uniq "$img" \ | sort -V \ - | xargs -r bashbrew list --uniq --build-order \ | xargs -r bashbrew cat --format ' {{- range $e := .TagEntries -}} {{- printf "\n%s\n" ($e.ClearDefaults $.Manifest.Global) -}} diff --git a/diff-pr.sh b/diff-pr.sh index 09d09764cb7fe..dc78b0e7c19b9 100755 --- a/diff-pr.sh +++ b/diff-pr.sh @@ -249,6 +249,35 @@ copy-tar() { done } +# a "bashbrew cat" template that gives us the last / "least specific" tags for the arguments +# (in other words, this is "bashbrew list --uniq" but last instead of first) +templateLastTags=' + {{- range .TagEntries -}} + {{- $.RepoName -}} + {{- ":" -}} + {{- .Tags | last -}} + {{- "\n" -}} + {{- end -}} +' + +_metadata-files() { + bashbrew list "$@" 2>>temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || : + + "$diffDir/_bashbrew-cat-sorted.sh" "$@" 2>>temp/_bashbrew.err > temp/_bashbrew-cat || : + + bashbrew list --uniq "$@" \ + | sort -V \ + | xargs -r bashbrew list --uniq --build-order 2>>temp/_bashbrew.err \ + | xargs -r bashbrew cat --format "$templateLastTags" 2>>temp/_bashbrew.err \ + > temp/_bashbrew-list-build-order || : + + script="$(bashbrew cat --format "$template" "$@")" + mkdir tar + ( eval "$script" | tar -xiC tar ) + copy-tar tar temp + rm -rf tar +} + mkdir temp git -C temp init --quiet git -C temp config user.name 'Bogus' @@ -257,15 +286,7 @@ git -C temp config user.email 'bogus@bogus' # handle "new-image" PRs gracefully for img; do touch "$BASHBREW_LIBRARY/$img"; [ -s "$BASHBREW_LIBRARY/$img" ] || echo 'Maintainers: New Image! :D (@docker-library-bot)' > "$BASHBREW_LIBRARY/$img"; done -bashbrew list "$@" 2>>temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || : -"$diffDir/_bashbrew-cat-sorted.sh" "$@" 2>>temp/_bashbrew.err > temp/_bashbrew-cat || : -for image; do - script="$(bashbrew cat --format "$template" "$image")" - mkdir tar - ( eval "$script" | tar -xiC tar ) - copy-tar tar temp - rm -rf tar -done +_metadata-files "$@" git -C temp add . || : git -C temp commit --quiet --allow-empty -m 'initial' || : @@ -276,13 +297,8 @@ git -C oi checkout --quiet pull for img; do touch "$BASHBREW_LIBRARY/$img"; [ -s "$BASHBREW_LIBRARY/$img" ] || echo 'Maintainers: Deleted Image D: (@docker-library-bot)' > "$BASHBREW_LIBRARY/$img"; done git -C temp rm --quiet -rf . || : -bashbrew list "$@" 2>>temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || : -"$diffDir/_bashbrew-cat-sorted.sh" "$@" 2>>temp/_bashbrew.err > temp/_bashbrew-cat || : -script="$(bashbrew cat --format "$template" "$@")" -mkdir tar -( eval "$script" | tar -xiC tar ) -copy-tar tar temp -rm -rf tar + +_metadata-files "$@" git -C temp add . git -C temp diff \