1
0

generate-repo-stub-readme.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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://docs.docker.com/docker-hub/official_repos/) 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 description from Docker Hub]($hubPage) is generated over in [docker-library/docs]($gitRepo), specifically in [docker-library/docs/$repo]($gitRepo/tree/master/$repo).
  38. ## See a change merged here that doesn't show up on Docker Hub yet?
  39. Check [the "library/$repo" manifest file in the docker-library/official-images repo](https://github.com/docker-library/official-images/blob/master/library/$repo), especially [PRs with the "library/$repo" label on that repo](https://github.com/docker-library/official-images/labels/library%2F$repo).
  40. For more information about the official images process, see the [docker-library/official-images readme](https://github.com/docker-library/official-images/blob/master/README.md).
  41. EOREADME
  42. badges=()
  43. n=$'\n'
  44. t=$'\t'
  45. travisImage="https://img.shields.io/travis/$travisRepo/master.svg"
  46. if svg="$(wget -qO- "$travisImage" 2>/dev/null)" && [[ "$svg" != *unknown* ]]; then
  47. travisLink="https://travis-ci.org/$travisRepo/branches"
  48. badges+=( "-${t}[Travis CI: ${n}${t}![build status badge]($travisImage)]($travisLink)" )
  49. fi
  50. # https://www.appveyor.com/docs/status-badges/#badges-for-projects-with-public-repositories-on-github-and-bitbucket
  51. appveyorImage="https://ci.appveyor.com/api/projects/status/github/docker-library/$repo?branch=master&svg=true"
  52. if svg="$(wget -qO- "$appveyorImage" 2>/dev/null)" && [[ "$svg" != *unknown* ]]; then
  53. appveyorLink="https://ci.appveyor.com/project/docker-library/$repo"
  54. badges+=( "-${t}[AppVeyor (Windows): ${n}${t}![build status badge]($appveyorImage)]($appveyorLink)" )
  55. fi
  56. jenkinsImage="https://doi-janky.infosiftr.net/job/update.sh/job/$repo/badge/icon"
  57. if wget -q --spider "$jenkinsImage" &> /dev/null; then
  58. jenkinsLink="https://doi-janky.infosiftr.net/job/update.sh/job/$repo"
  59. badges+=( "-${t}[Automated \`update.sh\`: ${n}${t}![build status badge]($jenkinsImage)]($jenkinsLink)" )
  60. fi
  61. arches="$(bashbrew cat --format '{{ range .Entries }}{{ join "\n" .Architectures }}{{ "\n" }}{{ end }}' "https://github.com/docker-library/official-images/raw/master/library/$repo" | sort -u)"
  62. if [ -n "$arches" ]; then
  63. archTable=
  64. i=0
  65. for arch in $arches; do
  66. jenkinsLink="https://doi-janky.infosiftr.net/job/multiarch/job/$arch/job/$repo"
  67. jenkinsImage="$jenkinsLink/badge/icon"
  68. if wget -q --spider "$jenkinsImage" &> /dev/null; then
  69. archTable="${archTable:-|} [\`$arch\`<br />![build status badge]($jenkinsImage)]($jenkinsLink) |"
  70. (( i = (i + 1) % 4 )) || : # modulo here needs to match the number of colums used below
  71. if [ "$i" = 0 ]; then
  72. archTable+="${n}|"
  73. fi
  74. fi
  75. done
  76. if [ -n "$archTable" ]; then
  77. badges+=( "${n}| Build | Status | Badges | (per-arch) |${n}|:-:|:-:|:-:|:-:|${n}${archTable%${n}|}" )
  78. fi
  79. fi
  80. if [ "${#badges[@]}" -gt 0 ]; then
  81. IFS=$'\n'
  82. cat <<-EOREADME
  83. ---
  84. ${badges[*]}
  85. EOREADME
  86. unset IFS
  87. fi
  88. cat <<EOREADME
  89. <!-- THIS FILE IS GENERATED BY $gitRepo/blob/master/generate-repo-stub-readme.sh -->
  90. EOREADME