فهرست منبع

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

Tianon Gravi 5 سال پیش
والد
کامیت
23c82fb190
1فایلهای تغییر یافته به همراه30 افزوده شده و 21 حذف شده
  1. 30 21
      generate-repo-stub-readme.sh

+ 30 - 21
generate-repo-stub-readme.sh

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