naughty-sharedtags.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. if [ "$#" -eq 0 ]; then
  4. set -- '--all'
  5. fi
  6. bashbrew cat --format '
  7. {{- range $e := .Entries -}}
  8. {{- range $t := .SharedTags -}}
  9. {{- "{" -}}
  10. "sharedTag": {{ join ":" $.RepoName $t | json }},
  11. "tag": {{ join ":" $.RepoName ($e.Tags | first) | json }},
  12. "arches": {{ $e.Architectures | json }}
  13. {{- "}\n" -}}
  14. {{- end -}}
  15. {{- end -}}
  16. ' "$@" | jq -rn '
  17. # collect map of "shared tag -> all architectures" (combining shared tags back together, respecting/keeping duplicates, since that is what this is testing for)
  18. reduce inputs as $in ({}; .[$in.sharedTag] |= (. // {} | .arches += $in.arches | .tags += [$in.tag]))
  19. # convert that into a map of "shared tags -> same architecture list" (just to shrink the problem set and make it easier to look at/think about)
  20. | reduce to_entries[] as $in ([];
  21. (path(first(.[] | select(.value.arches == $in.value.arches))) // [length]) as $i
  22. | .[$i[0]] |= (
  23. .key |= if . then "\(.), \($in.key)" else $in.key end
  24. | .value //= $in.value
  25. )
  26. )
  27. | map(
  28. # filter down to just entries with duplicates (ignoring Windows duplicates, since duplicating them is the primary use case of SharedTags in the first place)
  29. .value.arches |= (
  30. # TODO we *should* try to further verify that there is only one copy of each underlying Windows version here (not 2x "ltsc2022" for example), but that is a much more difficult query to automate
  31. . - ["windows-amd64"]
  32. # trim the list down to just the duplicates (so the error is more obvious)
  33. | group_by(.)
  34. | map(select(length > 1))
  35. | flatten
  36. )
  37. | select(.value.arches | length > 0)
  38. | " - \(.key): (duplicate architectures in SharedTags; \(.value.tags | join(", ")))\([ "", .value.arches[] ] | join("\n - "))"
  39. )
  40. | join("\n\n")
  41. '