generate-repo-stub-readme.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. repo="${1:-}"
  5. if [ -z "$repo" ]; then
  6. echo >&2 'error: no repo specified'
  7. cat >&2 <<EOUSAGE
  8. usage: $0 repo [> README.md]
  9. ie: $0 php > ../php/README.md
  10. This script generates a stub README to standard out for the specified repo.
  11. EOUSAGE
  12. exit 1
  13. fi
  14. gitRepo='https://github.com/docker-library/docs'
  15. hubPage="https://hub.docker.com/_/$repo/"
  16. canonicalRepo="https://github.com/docker-library/$repo"
  17. if [ -s "$repo/github-repo" ]; then
  18. canonicalRepo="$(< "$repo/github-repo")"
  19. fi
  20. canonicalRepo="$(curl -fsSLI -o /dev/null -w '%{url_effective}\n' "$canonicalRepo")" # follow redirects (http://stackoverflow.com/a/3077316/433558)
  21. githubRepoName="${canonicalRepo#*://github.com/}"
  22. if [[ "$githubRepoName" = elastic/* ]]; then
  23. # Elastic points "github-repo" at their upstream elastic/xyz-docker repos, but we want our README stubs to still point at our integration repos
  24. githubRepoName="docker-library/$repo"
  25. fi
  26. maintainer="$(sed -e 's!%%GITHUB-REPO%%!'"$canonicalRepo"'!g' "$repo/maintainer.md")"
  27. if [ -f "$repo/deprecated.md" ]; then
  28. echo '# DEPRECATED'
  29. echo
  30. cat "$repo/deprecated.md"
  31. echo
  32. fi
  33. case "$repo" in
  34. buildpack-deps | docker | hello-world | hylang) disclaimer='' ;;
  35. *) disclaimer=" (not to be confused with any official \`$repo\` image provided by \`$repo\` upstream)" ;;
  36. esac
  37. cat <<EOREADME
  38. # $canonicalRepo
  39. ## Maintained by: $maintainer
  40. This is the Git repo of the [Docker "Official Image"](https://github.com/docker-library/official-images#what-are-official-images) for [\`$repo\`]($hubPage)$disclaimer. See [the Docker Hub page]($hubPage) for the full readme on how to use this Docker image and for information regarding contributing and issues.
  41. The [full image description on Docker Hub]($hubPage) is generated/maintained over in [the docker-library/docs repository]($gitRepo), specifically in [the \`$repo\` directory]($gitRepo/tree/master/$repo).
  42. ## See a change merged here that doesn't show up on Docker Hub yet?
  43. For more information about the full official images change lifecycle, see [the "An image's source changed in Git, now what?" FAQ entry](https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what).
  44. For outstanding \`$repo\` image PRs, check [PRs with the "library/$repo" label on the official-images repository](https://github.com/docker-library/official-images/labels/library%2F$repo). For the current "source of truth" for [\`$repo\`]($hubPage), see [the \`library/$repo\` file in the official-images repository](https://github.com/docker-library/official-images/blob/master/library/$repo).
  45. EOREADME
  46. badges=()
  47. n=$'\n'
  48. t=$'\t'
  49. branch='master'
  50. toTest=(
  51. # "image badge URL"
  52. # "image badge link/href"
  53. # "badge test URL (to determine whether badge applies)"
  54. "https://img.shields.io/github/actions/workflow/status/$githubRepoName/ci.yml?branch=$branch&label=GitHub%20CI"
  55. "https://github.com/$githubRepoName/actions?query=workflow%3A%22GitHub+CI%22+branch%3A$branch"
  56. "https://github.com/$githubRepoName/blob/$branch/.github/workflows/ci.yml"
  57. "https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/update.sh/job/$repo.svg?label=Automated%20update.sh"
  58. "https://doi-janky.infosiftr.net/job/update.sh/job/$repo/"
  59. "https://doi-janky.infosiftr.net/job/update.sh/job/$repo/"
  60. )
  61. _wget_spider() {
  62. wget -q -o /dev/null -O /dev/null --spider "$@"
  63. }
  64. set -- "${toTest[@]}"
  65. while [ "$#" -gt 0 ]; do
  66. image="$1"; shift
  67. url="$1"; shift
  68. testUrl="$1"; shift
  69. if _wget_spider "$testUrl"; then
  70. badges+=( "-${t}[![build status badge]($image)]($url)" )
  71. fi
  72. done
  73. arches="$(bashbrew cat --format '{{ range .Entries }}{{ join "\n" .Architectures }}{{ "\n" }}{{ end }}' "https://github.com/docker-library/official-images/raw/master/library/$repo" | sort -u)"
  74. if [ -n "$arches" ]; then
  75. archTable=
  76. i=0
  77. for arch in $arches put-shared; do
  78. if [ "$arch" = 'put-shared' ]; then
  79. jenkinsJob="job/put-shared/job/light/job/$repo"
  80. if ! _wget_spider "https://doi-janky.infosiftr.net/$jenkinsJob/"; then
  81. jenkinsJob='job/put-shared/job/heavy'
  82. fi
  83. else
  84. jenkinsJob="job/multiarch/job/$arch/job/$repo"
  85. fi
  86. jenkinsLink="https://doi-janky.infosiftr.net/$jenkinsJob/"
  87. jenkinsImage="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/$jenkinsJob.svg?label=$arch"
  88. if _wget_spider "$jenkinsLink"; then
  89. archTable="${archTable:-|} [![$arch build status badge]($jenkinsImage)]($jenkinsLink) |"
  90. (( i = (i + 1) % 4 )) || : # modulo here needs to match the number of colums used below
  91. if [ "$i" = 0 ]; then
  92. archTable+="${n}|"
  93. fi
  94. fi
  95. done
  96. if [ -n "$archTable" ]; then
  97. if [ "${#badges[@]}" -gt 0 ]; then
  98. badges+=( '' )
  99. fi
  100. badges+=( "| Build | Status | Badges | (per-arch) |${n}|:-:|:-:|:-:|:-:|${n}${archTable%${n}|}" )
  101. fi
  102. fi
  103. if [ "${#badges[@]}" -gt 0 ]; then
  104. IFS=$'\n'
  105. cat <<-EOREADME
  106. ---
  107. ${badges[*]}
  108. EOREADME
  109. unset IFS
  110. fi
  111. cat <<EOREADME
  112. <!-- THIS FILE IS GENERATED BY $gitRepo/blob/master/generate-repo-stub-readme.sh -->
  113. EOREADME