浏览代码

Merge pull request #7966 from infosiftr/better-diff

Replace "_bashbrew-arches" and "_bashbrew-shared-tags" with a ~sorted "bashbrew cat" clone in diff-pr.sh
yosifkit 5 年之前
父节点
当前提交
3305d2c93d
共有 2 个文件被更改,包括 58 次插入37 次删除
  1. 43 0
      _bashbrew-cat-sorted.sh
  2. 15 37
      diff-pr.sh

+ 43 - 0
_bashbrew-cat-sorted.sh

@@ -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

+ 15 - 37
diff-pr.sh

@@ -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)"
@@ -149,7 +121,7 @@ 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
@@ -157,6 +129,7 @@ copy-tar() {
 
 	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" )
@@ -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" \
@@ -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
@@ -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