diff --git a/hub/gsl.sh b/hub/gsl.sh index 4eda9af..19a2d9b 100755 --- a/hub/gsl.sh +++ b/hub/gsl.sh @@ -7,13 +7,6 @@ dir="$(dirname "$BASH_SOURCE")" cd "$dir" commit="$(git log -1 --format='format:%H' HEAD -- .)" -cat <<-EOH - Maintainers: Tianon Gravi (@tianon) - GitRepo: https://github.com/tianon/gosu.git - GitCommit: $commit - Directory: hub - Builder: buildkit -EOH version= i=0; jq=; froms=() @@ -31,24 +24,68 @@ for variant in "${preferredOrder[@]}"; do done arches="$(bashbrew remote arches --json "${froms[@]}" | jq -sc "{ $jq }")" # { alpine: [ "amd64", ... ], debian: [ "amd64", ... ] } -queue="$(jq <<<"$arches" -r 'to_entries | map(@sh "variant=\(.key)\narch=\(.value[])") | map(@sh) | join("\n")')" -eval "queue=( $queue )" - -declare -A seenArches=() -for item in "${queue[@]}"; do - eval "$item" # variant=yyy arch=xxx - [ -n "$variant" ] - [ -n "$arch" ] - tags="$variant-$arch" - sharedTags="$variant, $version-$variant" - if [ -z "${seenArches["$arch"]:-}" ]; then - tags+=", $arch" - sharedTags+=", $version, latest" - fi - echo - echo "Tags: $tags" - [ -z "$sharedTags" ] || echo "SharedTags: $sharedTags" - echo "Architectures: $arch" - echo "File: Dockerfile.$variant" - : "${seenArches["$arch"]:=1}" -done +exec jq <<<"$arches" -r --arg commit "$commit" --arg version "$version" ' + with_entries(select(length > 0)) + | keys_unsorted as $variants + | (add | unique) as $arches + | . as $variantArches + | ( + reduce ( + to_entries[] + | { + variant: .key, + arch: .value[], + } + ) as $m ({}; + if has($m.arch) then . else + .[$m.arch] = $m.variant + end + ) + ) as $archVariants + | [ + { + Maintainers: "Tianon Gravi (@tianon)", + GitRepo: "https://github.com/tianon/gosu.git", + GitCommit: $commit, + Directory: "hub", + Builder: "buildkit", + }, + + reduce $arches[] as $arch ( + { + Tags: [ $version, "latest" ], + Architectures: $arches, + File: "Dockerfile.\($variants[0])", + }; + if has($arch + "-File") then . else + "Dockerfile.\($archVariants[$arch])" as $df + | if $df == .File then . else + .[$arch + "-File"] = $df + end + end + ), + + ( + $variants[] + | { + Tags: [ "\($version)-\(.)", . ], + Architectures: $variantArches[.], + File: "Dockerfile.\(.)", + }, + + ( + . as $variant + | $variantArches[.][] + | { + Tags: [ "\($variant)-\(.)", if $archVariants[.] == $variant then . else empty end ], + Architectures: ., + File: "Dockerfile.\($variant)", + } + ) + ), + + empty + ] + | map(to_entries | map(.key + ": " + ([ .value ] | flatten | join(", "))) | join("\n")) + | join("\n\n") +'