Skip to content

Commit 21c57f5

Browse files
mluggjiacai2050
andcommitted
check-mirrors: output results as markdown table
This builds on the changes in #27. Co-authored-by: jiacai2050 <[email protected]>
1 parent 7dccf5e commit 21c57f5

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
check-mirrors-summary.md

check-mirrors.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
#!/bin/sh
22

3+
summary_path="${GITHUB_STEP_SUMMARY:-check-mirrors-summary.md}"
34
temp_path="$(mktemp)"
45

56
zig_version="$(curl -sSL 'https://ziglang.org/download/index.json' | jq -r '.master.version')"
6-
filename="zig-linux-x86_64-$zig_version.tar.xz"
7+
filename="zig-x86_64-linux-$zig_version.tar.xz"
78

89
curl -L "https://ziglang.org/builds/$filename" >"$temp_path"
910
correct_sum="$(sha512sum "$temp_path")"
1011

12+
rm "$summary_path"
13+
14+
echo "| URL | Owner | Result | Time (s) |" >>"$summary_path"
15+
echo "|:----|:------|:-------|---------:|" >>"$summary_path"
16+
1117
jq '.[] | .[0] + " " + .[1]' -r <mirrors.json | while read -r mirror_url mirror_name; do
12-
curl -L "$mirror_url/$filename" >"$temp_path"
18+
time_secs="$(curl -w "%{time_total}" -L "$mirror_url/$filename" -o "$temp_path")"
1319
download_status="$?"
14-
mirror_sum="$(sha512sum "$temp_path")"
1520

1621
if [ "$download_status" -eq 0 ]; then
22+
mirror_sum="$(sha512sum "$temp_path")"
1723
if [ "$mirror_sum" = "$correct_sum" ]; then
18-
continue
24+
err="" # success
25+
else
26+
err="checksum mismatch: $mirror_sum (expected $correct_sum)"
1927
fi
28+
else
29+
err="curl exit status: $download_status"
30+
fi
31+
32+
md_time_secs="$(printf '`%0.2f`' "$time_secs")" # 2dp, backticks
33+
md_mirror_name="$(echo "$mirror_name" | sed -e 's/[<>]/\\\0/g')" # backslash-prefix angle brackets
34+
md_status="$(if [ "$err" = "" ]; then echo ":white_check_mark:"; else echo ":warning: \`$err\`"; fi)" # tick or cross for success
35+
echo "| $mirror_url | $md_mirror_name | $md_status | $md_time_secs |" >>"$summary_path"
36+
37+
if [ "$err" = "" ]; then
38+
continue # success
2039
fi
2140

2241
curl -s \

0 commit comments

Comments
 (0)