Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions _bashbrew-cat-sorted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -Eeuo pipefail

# a mimic of "bashbrew cat" which should sort slightly more deterministically (so even full-order-changing PRs should have reasonable diffs)

images="$(
bashbrew list --repos --uniq "$@" \
| sort -uV \
| xargs -r bashbrew list --repos --uniq --build-order
)"
set -- $images

declare -A seenGlobal=()

first=1
for img; do
if [ -n "$first" ]; then
first=
else
echo; echo
fi

if [ "$#" -gt 1 ]; then
echo "# $img"
fi

repo="${img%:*}"
if [ -z "${seenGlobal["$repo"]:-}" ]; then
bashbrew cat --format '{{ printf "%s\n" (.Manifest.Global.ClearDefaults defaults) }}' "$img"
seenGlobal["$repo"]="$img"
else
echo "# (see also ${seenGlobal["$repo"]} above)"
fi

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) -}}
{{- end -}}
'
done
52 changes: 15 additions & 37 deletions diff-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,6 @@ export BASHBREW_LIBRARY="$PWD/oi/library"
: "${BASHBREW_ARCH:=amd64}" # TODO something smarter with arches
export BASHBREW_ARCH

# "bashbrew cat" template for duplicating something like "bashbrew list --uniq" but with architectures too
archesListTemplate='
{{- range $e := $.Entries -}}
{{- range .Architectures -}}
{{- $.RepoName -}}:{{- $e.Tags | last -}}
{{- " @ " -}}
{{- . -}}
{{- "\n" -}}
{{- end -}}
{{- end -}}
'
# ... and SharedTags
sharedTagsListTemplate='
{{- range $group := .Manifest.GetSharedTagGroups -}}
{{- range $tag := $group.SharedTags -}}
{{- join ":" $.RepoName $tag -}}
{{- " -- " -}}
{{- range $i, $e := $group.Entries -}}
{{- if gt $i 0 -}}
{{- ", " -}}
{{- end -}}
{{- join ":" $.RepoName ($e.Tags | last) -}}
{{- end -}}
{{- "\n" -}}
{{- end -}}
{{- end -}}
'

# TODO something less hacky than "git archive" hackery, like a "bashbrew archive" or "bashbrew context" or something
template='
tempDir="$(mktemp -d)"
Expand Down Expand Up @@ -149,14 +121,15 @@ copy-tar() {
local src="$1"; shift
local dst="$1"; shift

if [ "$allFiles" ]; then
if [ -n "$allFiles" ]; then
mkdir -p "$dst"
cp -al "$src"/*/ "$dst/"
return
fi

local d dockerfiles=()
for d in "$src"/*/.bashbrew-dockerfile-name; do
[ -f "$d" ] || continue
local bf; bf="$(< "$d")"
local dDir; dDir="$(dirname "$d")"
dockerfiles+=( "$dDir/$bf" )
Expand Down Expand Up @@ -233,9 +206,9 @@ copy-tar() {
mkdir -p "$gDir"
cp -alT "$dDir/$g" "$dst/$dDirName/$g"

if [ "$listTarballContents" ]; then
if [ -n "$listTarballContents" ]; then
case "$g" in
*.tar.*|*.tgz)
*.tar.* | *.tgz)
if [ -s "$dst/$dDirName/$g" ]; then
tar -tf "$dst/$dDirName/$g" \
| grep -vE "$uninterestingTarballGrep" \
Expand All @@ -256,11 +229,13 @@ git -C temp init --quiet
git -C temp config user.name 'Bogus'
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 || :
bashbrew cat --format "$archesListTemplate" "$@" 2>>temp/_bashbrew.err | sort -V > temp/_bashbrew-arches || :
bashbrew cat --format "$sharedTagsListTemplate" "$@" 2>>temp/_bashbrew.err | grep -vE '^$' | sort -V > temp/_bashbrew-shared-tags || :
"$diffDir/_bashbrew-cat-sorted.sh" "$@" 2>>temp/_bashbrew.err > temp/_bashbrew-cat || :
for image; do
if script="$(bashbrew cat -f "$template" "$image")"; then
if script="$(bashbrew cat --format "$template" "$image")"; then
mkdir tar
( eval "$script" | tar -xiC tar )
copy-tar tar temp
Expand All @@ -270,13 +245,16 @@ done
git -C temp add . || :
git -C temp commit --quiet --allow-empty -m 'initial' || :

git -C oi clean --quiet --force
git -C oi checkout --quiet pull

# handle "deleted-image" PRs gracefully :(
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 || :
bashbrew cat --format "$archesListTemplate" "$@" 2>>temp/_bashbrew.err | sort -V > temp/_bashbrew-arches || :
bashbrew cat --format "$sharedTagsListTemplate" "$@" 2>>temp/_bashbrew.err | grep -vE '^$' | sort -V > temp/_bashbrew-shared-tags || :
script="$(bashbrew cat -f "$template" "$@")"
"$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
Expand Down