Skip to content

Commit

Permalink
Slightly improved "diff-pr" output, especially around build-order
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
tianon committed Dec 13, 2022
1 parent 990cef4 commit 9f6ee11
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
4 changes: 1 addition & 3 deletions _bashbrew-cat-sorted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) -}}
Expand Down
48 changes: 32 additions & 16 deletions diff-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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' || :

Expand All @@ -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 \
Expand Down

0 comments on commit 9f6ee11

Please sign in to comment.