generate.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. bashbrewDir="$1"; shift
  4. if [ "$#" -eq 0 ]; then
  5. git fetch --quiet https://github.com/docker-library/official-images.git master
  6. changes="$(git diff --numstat FETCH_HEAD...HEAD -- library/ | cut -d$'\t' -f3-)"
  7. repos="$(xargs -rn1 basename <<<"$changes")"
  8. set -- $repos
  9. fi
  10. strategy='{}'
  11. for repo; do
  12. newStrategy="$(GITHUB_REPOSITORY="$repo" GENERATE_STACKBREW_LIBRARY='cat "library/$GITHUB_REPOSITORY"' "$bashbrewDir/scripts/github-actions/generate.sh")"
  13. newStrategy="$(jq -c --arg repo "$repo" '.matrix.include = [
  14. .matrix.include[]
  15. | ([ .meta.entries[].tags[0] ]) as $tags
  16. | .name = ($tags | join(", "))
  17. # replace "build" steps with something that uses "bashbrew" instead of "docker build"
  18. # https://github.com/docker-library/bashbrew/blob/a40a54d4d81b9fd2e39b4d7ba3fe203e8b022a67/scripts/github-actions/generate.sh#L74-L93
  19. | .runs.prepare += "\ngit clone --depth 1 https://github.com/docker-library/bashbrew.git ~/bashbrew\n~/bashbrew/bashbrew.sh --version"
  20. | .runs.build = (
  21. (if .os | startswith("windows-") then "export BASHBREW_ARCH=windows-amd64 BASHBREW_CONSTRAINTS=" + ([ .meta.entries[].constraints[] ] | join(", ") | @sh) + "\n" else "" end)
  22. + "export BASHBREW_LIBRARY=\"$PWD/library\"\n"
  23. + ([ $tags[] | "~/bashbrew/bashbrew.sh build " + @sh ] | join("\n"))
  24. )
  25. # use our local clone of official-images for running tests (so test changes can be tested too, if they live in the PR with the image change)
  26. # https://github.com/docker-library/bashbrew/blob/a40a54d4d81b9fd2e39b4d7ba3fe203e8b022a67/scripts/github-actions/generate.sh#L95
  27. | .runs.test |= gsub("[^\n\t ]+/run[.]sh "; "./test/run.sh ")
  28. ]' <<<"$newStrategy")"
  29. jq -c . <<<"$newStrategy" > /dev/null # sanity check
  30. strategy="$(jq -c '
  31. # https://stackoverflow.com/a/53666584/433558
  32. def meld(a; b):
  33. if (a | type) == "object" and (b | type) == "object" then
  34. # for some reason, "a" and "b" go out of scope for reduce??
  35. a as $a | b as $b |
  36. reduce (a + b | keys_unsorted[]) as $k
  37. ({}; .[$k] = meld($a[$k]; $b[$k]))
  38. elif (a | type) == "array" and (b | type) == "array" then
  39. a + b
  40. elif b == null then
  41. a
  42. else
  43. b
  44. end;
  45. meld(.[0]; .[1])
  46. ' <<<"[$strategy,$newStrategy]")"
  47. done
  48. jq -c . <<<"$strategy" > /dev/null # sanity check
  49. if [ -t 1 ]; then
  50. jq <<<"$strategy"
  51. else
  52. cat <<<"$strategy"
  53. fi