generate-repo-stub-readme.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. set -e
  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. travisRepo="${canonicalRepo#*://github.com/}"
  22. if [[ "$travisRepo" = 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. travisRepo="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. cat <<EOREADME
  34. # $canonicalRepo
  35. ## Maintained by: $maintainer
  36. This is the Git repo of the [Docker "Official Image"](https://github.com/docker-library/official-images#what-are-official-images) for [\`$repo\`]($hubPage) (not to be confused with any official \`$repo\` image provided by \`$repo\` upstream). See [the Docker Hub page]($hubPage) for the full readme on how to use this Docker image and for information regarding contributing and issues.
  37. 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).
  38. ## See a change merged here that doesn't show up on Docker Hub yet?
  39. 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).
  40. 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).
  41. EOREADME
  42. badges=()
  43. n=$'\n'
  44. t=$'\t'
  45. toTest=(
  46. "https://img.shields.io/travis/$travisRepo/master.svg?label=Travis%20CI" "https://travis-ci.org/$travisRepo/branches"
  47. "https://img.shields.io/appveyor/ci/$travisRepo/master.svg?label=AppVeyor" "https://ci.appveyor.com/project/$travisRepo"
  48. "https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/update.sh/job/$repo.svg?label=Automated%20update.sh" "https://doi-janky.infosiftr.net/job/update.sh/job/$repo"
  49. )
  50. _check_shields_io_image() {
  51. wget -qO- "$1" 2>/dev/null \
  52. | grep -qvE 'unknown|invalid|access denied|not found'
  53. }
  54. set -- "${toTest[@]}"
  55. while [ "$#" -gt 0 ]; do
  56. image="$1"; shift
  57. url="$1"; shift
  58. if _check_shields_io_image "$image"; then
  59. badges+=( "-${t}[![build status badge]($image)]($url)" )
  60. fi
  61. done
  62. arches="$(bashbrew cat --format '{{ range .Entries }}{{ join "\n" .Architectures }}{{ "\n" }}{{ end }}' "https://github.com/docker-library/official-images/raw/master/library/$repo" | sort -u)"
  63. if [ -n "$arches" ]; then
  64. archTable=
  65. i=0
  66. for arch in $arches; do
  67. jenkinsLink="https://doi-janky.infosiftr.net/job/multiarch/job/$arch/job/$repo"
  68. jenkinsImage="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/$arch/job/$repo.svg?label=$arch"
  69. if _check_shields_io_image "$jenkinsImage"; then
  70. archTable="${archTable:-|} [![$arch build status badge]($jenkinsImage)]($jenkinsLink) |"
  71. (( i = (i + 1) % 4 )) || : # modulo here needs to match the number of colums used below
  72. if [ "$i" = 0 ]; then
  73. archTable+="${n}|"
  74. fi
  75. fi
  76. done
  77. if [ -n "$archTable" ]; then
  78. if [ "${#badges[@]}" -gt 0 ]; then
  79. badges+=( '' )
  80. fi
  81. badges+=( "| Build | Status | Badges | (per-arch) |${n}|:-:|:-:|:-:|:-:|${n}${archTable%${n}|}" )
  82. fi
  83. fi
  84. if [ "${#badges[@]}" -gt 0 ]; then
  85. IFS=$'\n'
  86. cat <<-EOREADME
  87. ---
  88. ${badges[*]}
  89. EOREADME
  90. unset IFS
  91. fi
  92. cat <<EOREADME
  93. <!-- THIS FILE IS GENERATED BY $gitRepo/blob/master/generate-repo-stub-readme.sh -->
  94. EOREADME