check-mirrors: output results as markdown table

This builds on the changes in #27.

Co-authored-by: jiacai2050 <[email protected]>
This commit is contained in:
mlugg
2025-05-24 18:21:06 +01:00
co-authored by jiacai2050
parent 7dccf5e6d0
commit 21c57f5c6e
2 changed files with 24 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
check-mirrors-summary.md
+23 -4
View File
@@ -1,22 +1,41 @@
#!/bin/sh
summary_path="${GITHUB_STEP_SUMMARY:-check-mirrors-summary.md}"
temp_path="$(mktemp)"
zig_version="$(curl -sSL 'https://ziglang.org/download/index.json' | jq -r '.master.version')"
filename="zig-linux-x86_64-$zig_version.tar.xz"
filename="zig-x86_64-linux-$zig_version.tar.xz"
curl -L "https://ziglang.org/builds/$filename" >"$temp_path"
correct_sum="$(sha512sum "$temp_path")"
rm "$summary_path"
echo "| URL | Owner | Result | Time (s) |" >>"$summary_path"
echo "|:----|:------|:-------|---------:|" >>"$summary_path"
jq '.[] | .[0] + " " + .[1]' -r <mirrors.json | while read -r mirror_url mirror_name; do
curl -L "$mirror_url/$filename" >"$temp_path"
time_secs="$(curl -w "%{time_total}" -L "$mirror_url/$filename" -o "$temp_path")"
download_status="$?"
mirror_sum="$(sha512sum "$temp_path")"
if [ "$download_status" -eq 0 ]; then
mirror_sum="$(sha512sum "$temp_path")"
if [ "$mirror_sum" = "$correct_sum" ]; then
continue
err="" # success
else
err="checksum mismatch: $mirror_sum (expected $correct_sum)"
fi
else
err="curl exit status: $download_status"
fi
md_time_secs="$(printf '`%0.2f`' "$time_secs")" # 2dp, backticks
md_mirror_name="$(echo "$mirror_name" | sed -e 's/[<>]/\\\0/g')" # backslash-prefix angle brackets
md_status="$(if [ "$err" = "" ]; then echo ":white_check_mark:"; else echo ":warning: \`$err\`"; fi)" # tick or cross for success
echo "| $mirror_url | $md_mirror_name | $md_status | $md_time_secs |" >>"$summary_path"
if [ "$err" = "" ]; then
continue # success
fi
curl -s \