Skip to content

Commit b923742

Browse files
committed
Add workflow to check mirrors are functional
This Actions workflow will run twice every day. It checks ziglang.org for the latest `master` build, downloads it from ziglang.org and runs it through sha512sum, and does the same for each mirror. If the download from the mirror fails, or the sha512sum output differs, it sends me personally a notification via an external webhook.
1 parent 2f99513 commit b923742

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

.github/workflows/check-mirrors.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "check-mirrors",
3+
"on": {
4+
"schedule": [
5+
{ "cron": "0 6,18 * * *" },
6+
],
7+
"workflow_dispatch": null,
8+
},
9+
"jobs": {
10+
"check-mirrors": {
11+
"runs-on": "ubuntu-latest",
12+
"steps": [
13+
{ "uses": "actions/checkout@v4" },
14+
{
15+
"name": "Check mirrors",
16+
"env": {
17+
"PUSHOVER_USER": "${{ secrets.PUSHOVER_USER }}",
18+
"PUSHOVER_TOKEN": "${{ secrets.PUSHOVER_TOKEN }}",
19+
},
20+
"run": "sh check-mirrors.sh",
21+
},
22+
],
23+
},
24+
},
25+
}

check-mirrors.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
temp_path="$(mktemp)"
4+
5+
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+
8+
curl -L "https://ziglang.org/builds/$filename" >"$temp_path"
9+
correct_sum="$(sha512sum "$temp_path")"
10+
11+
jq '.[] | .[0] + " " + .[1]' -r <mirrors.json | while read -r mirror_url mirror_name; do
12+
curl -L "$mirror_url/$filename" >"$temp_path"
13+
download_status="$?"
14+
mirror_sum="$(sha512sum "$temp_path")"
15+
16+
if [ "$download_status" -eq 0 ]; then
17+
if [ "$mirror_sum" = "$correct_sum" ]; then
18+
continue
19+
fi
20+
fi
21+
22+
curl -s \
23+
-F user="$PUSHOVER_USER" -F token="$PUSHOVER_TOKEN" \
24+
-F message="Zig download mirror '$mirror_name' is down" \
25+
https://api.pushover.net/1/messages.json
26+
done
27+
28+
rm "$temp_path"

main.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ const CANONICAL = 'https://ziglang.org/builds';
1515

1616
// The list of mirrors we attempt to fetch from. These need not be trusted, as
1717
// we always verify the minisign signature.
18-
const MIRRORS = [
19-
'https://pkg.machengine.org/zig', // slimsag <[email protected]>
20-
'https://zigmirror.hryx.net/zig', // hryx <[email protected]>
21-
'https://zig.linus.dev/zig', // linusg <[email protected]>
22-
];
18+
// This is an array of URLs.
19+
const MIRRORS = require('./mirrors.json').map((x) => x[0]);
2320

2421
async function downloadFromMirror(mirror, tarball_name, tarball_ext) {
2522
const tarball_path = await tc.downloadTool(`${mirror}/${tarball_name}${tarball_ext}?source=github-actions`);

mirrors.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
[ "https://pkg.machengine.org/zig", "slimsag <[email protected]>" ],
3+
[ "https://zigmirror.hryx.net/zig", "hryx <[email protected]>" ],
4+
[ "https://zig.linus.dev/zig", "linusg <[email protected]>" ]
5+
]

0 commit comments

Comments
 (0)