Adjust "generate-repo-stub-readme.sh" to make less/lighter requests, and use a more deterministic detector for each badge

This commit is contained in:
Tianon Gravi 2020-07-28 10:11:24 -07:00
parent 6cbd2e9b43
commit 23c82fb190
1 changed files with 30 additions and 21 deletions

View File

@ -63,22 +63,37 @@ t=$'\t'
branch='master' branch='master'
toTest=( toTest=(
"https://img.shields.io/github/workflow/status/$githubRepoName/GitHub%20CI/$branch?label=GitHub%20CI" "https://github.com/$githubRepoName/actions?query=workflow%3A%22GitHub+CI%22+branch%3A$branch" # "image badge URL"
"https://img.shields.io/travis/$githubRepoName/$branch.svg?label=Travis%20CI" "https://travis-ci.org/$githubRepoName/branches" # "image badge link/href"
"https://img.shields.io/appveyor/ci/$githubRepoName/$branch.svg?label=AppVeyor" "https://ci.appveyor.com/project/$githubRepoName" # "badge test URL (to determine whether badge applies)"
"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/"
"https://img.shields.io/github/workflow/status/$githubRepoName/GitHub%20CI/$branch?label=GitHub%20CI"
"https://github.com/$githubRepoName/actions?query=workflow%3A%22GitHub+CI%22+branch%3A$branch"
"https://github.com/$githubRepoName/blob/$branch/.github/workflows/ci.yml"
"https://img.shields.io/travis/$githubRepoName/$branch.svg?label=Travis%20CI"
"https://travis-ci.org/$githubRepoName/branches"
"https://github.com/$githubRepoName/blob/$branch/.travis.yml"
"https://img.shields.io/appveyor/ci/$githubRepoName/$branch.svg?label=AppVeyor"
"https://ci.appveyor.com/project/$githubRepoName"
"https://github.com/$githubRepoName/blob/$branch/.appveyor.yml"
"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/"
"https://doi-janky.infosiftr.net/job/update.sh/job/$repo/"
) )
_check_shields_io_image() { _wget_spider() {
wget -qO- "$1" 2>/dev/null \ wget -q -o /dev/null -O /dev/null --spider "$@"
| grep -qvE 'unknown|invalid|access denied|not found'
} }
set -- "${toTest[@]}" set -- "${toTest[@]}"
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
image="$1"; shift image="$1"; shift
url="$1"; shift url="$1"; shift
if _check_shields_io_image "$image"; then testUrl="$1"; shift
if _wget_spider "$testUrl"; then
badges+=( "-${t}[![build status badge]($image)]($url)" ) badges+=( "-${t}[![build status badge]($image)]($url)" )
fi fi
done done
@ -89,22 +104,16 @@ if [ -n "$arches" ]; then
i=0 i=0
for arch in $arches put-shared; do for arch in $arches put-shared; do
if [ "$arch" = 'put-shared' ]; then if [ "$arch" = 'put-shared' ]; then
jenkinsLink= jenkinsJob="job/put-shared/job/light/job/$repo"
for jenkinsJob in "job/put-shared/job/light/job/$repo" 'job/put-shared/job/heavy'; do if ! _wget_spider "https://doi-janky.infosiftr.net/$jenkinsJob/"; then
jenkinsImage="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/$jenkinsJob.svg?label=$arch" jenkinsJob='job/put-shared/job/heavy'
if _check_shields_io_image "$jenkinsImage"; then
jenkinsLink="https://doi-janky.infosiftr.net/$jenkinsJob/"
break
fi
done
if [ -z "$jenkinsLink" ]; then
continue
fi fi
else else
jenkinsLink="https://doi-janky.infosiftr.net/job/multiarch/job/$arch/job/$repo/" jenkinsJob="job/multiarch/job/$arch/job/$repo"
jenkinsImage="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/$arch/job/$repo.svg?label=$arch"
fi fi
if _check_shields_io_image "$jenkinsImage"; then jenkinsLink="https://doi-janky.infosiftr.net/$jenkinsJob/"
jenkinsImage="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/$jenkinsJob.svg?label=$arch"
if _wget_spider "$jenkinsLink"; then
archTable="${archTable:-|} [![$arch build status badge]($jenkinsImage)]($jenkinsLink) |" archTable="${archTable:-|} [![$arch build status badge]($jenkinsImage)]($jenkinsLink) |"
(( i = (i + 1) % 4 )) || : # modulo here needs to match the number of colums used below (( i = (i + 1) % 4 )) || : # modulo here needs to match the number of colums used below
if [ "$i" = 0 ]; then if [ "$i" = 0 ]; then