generate-repo-stub-readme.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. hello-world | buildpack-deps) 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/workflow/status/$githubRepoName/GitHub%20CI/$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/travis/$githubRepoName/$branch.svg?label=Travis%20CI"
  58. "https://travis-ci.org/$githubRepoName/branches"
  59. "https://github.com/$githubRepoName/blob/$branch/.travis.yml"
  60. "https://img.shields.io/appveyor/ci/$githubRepoName/$branch.svg?label=AppVeyor"
  61. "https://ci.appveyor.com/project/$githubRepoName"
  62. "https://github.com/$githubRepoName/blob/$branch/.appveyor.yml"
  63. "https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/update.sh/job/$repo.svg?label=Automated%20update.sh"
  64. "https://doi-janky.infosiftr.net/job/update.sh/job/$repo/"
  65. "https://doi-janky.infosiftr.net/job/update.sh/job/$repo/"
  66. )
  67. _wget_spider() {
  68. wget -q -o /dev/null -O /dev/null --spider "$@"
  69. }
  70. set -- "${toTest[@]}"
  71. while [ "$#" -gt 0 ]; do
  72. image="$1"; shift
  73. url="$1"; shift
  74. testUrl="$1"; shift
  75. if _wget_spider "$testUrl"; then
  76. badges+=( "-${t}[![build status badge]($image)]($url)" )
  77. fi
  78. done
  79. arches="$(bashbrew cat --format '{{ range .Entries }}{{ join "\n" .Architectures }}{{ "\n" }}{{ end }}' "https://github.com/docker-library/official-images/raw/master/library/$repo" | sort -u)"
  80. if [ -n "$arches" ]; then
  81. archTable=
  82. i=0
  83. for arch in $arches put-shared; do
  84. if [ "$arch" = 'put-shared' ]; then
  85. jenkinsJob="job/put-shared/job/light/job/$repo"
  86. if ! _wget_spider "https://doi-janky.infosiftr.net/$jenkinsJob/"; then
  87. jenkinsJob='job/put-shared/job/heavy'
  88. fi
  89. else
  90. jenkinsJob="job/multiarch/job/$arch/job/$repo"
  91. fi
  92. jenkinsLink="https://doi-janky.infosiftr.net/$jenkinsJob/"
  93. jenkinsImage="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/$jenkinsJob.svg?label=$arch"
  94. if _wget_spider "$jenkinsLink"; then
  95. archTable="${archTable:-|} [![$arch build status badge]($jenkinsImage)]($jenkinsLink) |"
  96. (( i = (i + 1) % 4 )) || : # modulo here needs to match the number of colums used below
  97. if [ "$i" = 0 ]; then
  98. archTable+="${n}|"
  99. fi
  100. fi
  101. done
  102. if [ -n "$archTable" ]; then
  103. if [ "${#badges[@]}" -gt 0 ]; then
  104. badges+=( '' )
  105. fi
  106. badges+=( "| Build | Status | Badges | (per-arch) |${n}|:-:|:-:|:-:|:-:|${n}${archTable%${n}|}" )
  107. fi
  108. fi
  109. if [ "${#badges[@]}" -gt 0 ]; then
  110. IFS=$'\n'
  111. cat <<-EOREADME
  112. ---
  113. ${badges[*]}
  114. EOREADME
  115. unset IFS
  116. fi
  117. cat <<EOREADME
  118. <!-- THIS FILE IS GENERATED BY $gitRepo/blob/master/generate-repo-stub-readme.sh -->
  119. EOREADME