From 21c57f5c6e1778ef2f072abfa8fd5504baf2ce76 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 24 May 2025 18:21:06 +0100 Subject: [PATCH] check-mirrors: output results as markdown table This builds on the changes in #27. Co-authored-by: jiacai2050 --- .gitignore | 1 + check-mirrors.sh | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41afe05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +check-mirrors-summary.md diff --git a/check-mirrors.sh b/check-mirrors.sh index 3ad7c1b..b0c74cf 100755 --- a/check-mirrors.sh +++ b/check-mirrors.sh @@ -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 "$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 \