Skip to content

Commit 5eb0fc8

Browse files
committed
Use ziglang.org community mirrors list
This new list supersedes the `mirrors.json` in this repo.
1 parent 0483960 commit 5eb0fc8

File tree

6 files changed

+25
-147
lines changed

6 files changed

+25
-147
lines changed

.github/workflows/check-mirrors.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ If you want to use one specific mirror, you can set it using the `mirror` option
4444

4545
Please don't do this unnecessarily; it's not nice to hammer one mirror. This mirror is not permitted to
4646
be https://ziglang.org/download to avoid the official website being hit with large amounts of requests.
47-
If you've experienced issues with a default mirror, please open an issue, and I will communicate with the
48-
mirror's owner or remove it from the list.
47+
If you've experienced issues with a default mirror, please [open an issue][report-bad-mirror] on the Zig
48+
website repository, which is where the list of mirrors is maintained.
4949

5050
If necessary, the caching of the global Zig cache directory can be disabled by setting the option
5151
`use-cache: false`. Don't do this without reason: preserving the Zig cache will typically speed things up
@@ -63,6 +63,7 @@ setting `cache-size-limit: 0`.
6363

6464
[mach-nominated]: https://machengine.org/about/nominated-zig/
6565
[matrix]: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow
66+
[report-bad-mirror]: https://github.com/ziglang/www.ziglang.org/issues/new
6667

6768
## Details
6869

@@ -75,65 +76,10 @@ local caches are redirected to the global cache directory to make optimal use of
7576

7677
## Adding a mirror
7778

78-
Anyone is welcome to host a Zig download mirror; thanks to the tarball signatures, the mirror provider need
79-
not be trusted. Naturally, if a mirror is found to be a bad actor, it will be removed, and likewise if a
80-
mirror repeatedly encounters reliability problems.
81-
82-
The rules for adding a mirror are listed below. Note that I (@mlugg) reserve the right to, for any or no
83-
reason, exclude mirrors which obey these rules, or include mirrors which violate them.
84-
85-
> [!NOTE]
86-
> While there are a lot of rules listed here, most of them should be obvious. They are stated explicitly here
87-
> to ensure complete clarity on what is expected of a mirror. Please do read these requirements through before
88-
> attempting to add a mirror.
89-
90-
* A mirror provides a single base URL, which we will call `X`.
91-
* `X` **may** include a path component, but is not required to. For instance, `https://foo.bar/zig/` is okay,
92-
as is `https://zig.baz.qux/`.
93-
* The mirror **must** have working HTTPS support. `X` **must** start with `https://`.
94-
* The mirror **must** cache tarballs locally. For instance, it may not simply forward all requests to another
95-
mirror.
96-
* The mirror **may** routinely evict its local tarball caches based on any reasonable factor, such as age,
97-
access frequency, or the existence of newer versions. This does not affect whether the mirror may return 404
98-
for requests to these files (see below).
99-
* The mirror **must** download its tarballs from either `https://ziglang.org/`, or another mirror which
100-
follows these rules.
101-
* Tarballs **must** be accessible by sending GET requests for files under `X`, where the filename matches that
102-
of the files provided by `https://ziglang.org/`, not including the directory part. For instance,
103-
`X/zig-linux-x86_64-0.13.0.tar.xz` is a valid access, and should return the same file as
104-
`https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz`.
105-
* Files provided by the mirror **must** be bit-for-bit identical to their `https://ziglang.org/` counterparts.
106-
* If a file is accessed whose Zig version is a master branch build (i.e. a `-dev` version), and the version is
107-
ordered before the latest major release of Zig, the mirror **may** respond with 404 Not Found, but is not
108-
required to. For instance, at the time of writing, `0.13.0` is the latest major release of Zig, so a mirror
109-
may respond with 404 for `0.13.0-dev...` builds, but *not* for `0.14.0-dev...` builds.
110-
* If a file is accessed whose Zig version is `0.5.0` or below, the mirror **may** respond with 404 Not Found,
111-
but is not required to.
112-
* If a file is acccessed which represents a *source* tarball, such as `X/zig-0.13.0.tar.xz`, the mirror
113-
**may** respond with 404 Not Found, but is not required to. The same applies to "bootstrap source tarballs",
114-
such as `X/zig-bootstrap-0.13.0.tar.xz`.
115-
* For all other accesses of valid Zig tarballs, the mirror **must** respond with status code 200 OK and the
116-
file in question. If the mirror has not yet cached the file locally, it should immediately download it from
117-
a permitted source (as covered above), and respond with the downloaded file.
118-
* If a tarball `X/foo.ext` is available by the above rules, requesting the minisign signature file
119-
`X/foo.ext.minisig` **must** also respond with status code 200 OK and the signature file in question, like
120-
the tarball itself.
121-
* The mirror **may** rate-limit accesses. If an access failed due to rate-limiting, the mirror **should**
122-
return HTTP status code 429 Too Many Requests.
123-
* The mirror **may** undergo maintenance, upgrades, and other scheduled downtime. If an access fails for this
124-
reason, where possible, the mirror **should** return HTTP status code 503 Unavailable. The mirror **should**
125-
try to minimize such downtime.
126-
* The mirror **may** undergo occasional unintended and unscheduled downtime. The mirror **must** go to all
127-
efforts to minimize such outages, and **must** resolve such outages within a reasonable time upon being
128-
notified of them.
129-
* The mirror **may** observe the `?source=github-actions` query parameter to track how many requests originate
130-
from this Action. This Action will provide this query parameter to all mirror requests.
131-
132-
The easiest way to set up a mirror right now is using Mach's [Wrench][wrench]. For instructions, please see
133-
[the relevant section of their README][setup-wrench].
134-
135-
[wrench]: https://github.com/hexops/wrench
136-
[setup-wrench]: https://github.com/hexops/wrench?tab=readme-ov-file#run-your-own-ziglangorgdownload-mirror
137-
138-
After setting up a mirror, you can add it to this GitHub Action by opening a PR which adds it to the list in
139-
[mirrors.json](https://github.com/mlugg/setup-zig/blob/main/mirrors.json).
79+
The list of tarball mirrors is not in this repository; rather, the [community mirror list][mirrors] from
80+
ziglang.org is used. If you are interested in hosting a mirror of your own, check out the
81+
[documentation][host-mirror] on the Zig website repository. That way, your mirror can benefit not just
82+
setup-zig, but also any other tooling which wants to fetch Zig!
83+
84+
[mirrors]: https://ziglang.org/download/community-mirrors/
85+
[host-mirror]: https://github.com/ziglang/www.ziglang.org/blob/main/MIRRORS.md

check-mirrors.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ const MINISIGN_KEY = 'RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U';
1313
// The base URL of the official builds of Zig. This is only used as a fallback, if all mirrors fail.
1414
const CANONICAL = 'https://ziglang.org/builds';
1515

16-
// The list of mirrors we attempt to fetch from. These need not be trusted, as
17-
// we always verify the minisign signature.
18-
// This is an array of URLs.
19-
const MIRRORS = require('./mirrors.json').map((x) => x[0]);
16+
// The URL of the mirror list. This should be an ASCII-encoded text file, with one mirror per LF-separated line.
17+
const MIRRORS_URL = 'https://ziglang.org/download/community-mirrors.txt';
2018

2119
async function downloadFromMirror(mirror, tarball_filename) {
2220
const tarball_path = await tc.downloadTool(`${mirror}/${tarball_filename}?source=github-actions`);
@@ -52,9 +50,21 @@ async function downloadTarball(tarball_filename) {
5250
return await downloadFromMirror(preferred_mirror, tarball_filename);
5351
}
5452

53+
// Fetch the list of mirrors from ziglang.org. Caching the mirror list is awkward in this context,
54+
// so if the list is inaccessible, we just fetch from ziglang.org as a fallback.
55+
let mirrors = [];
56+
try {
57+
const mirrors_response = await fetch(MIRRORS_URL);
58+
mirrors = (await mirrors_response.text()).split('\n').filter((url) => url.length != 0);
59+
} catch {
60+
// For some reason the mirrors are inaccessible. That's okay; allow ourselves to fall back to ziglang.org below.
61+
}
62+
63+
core.info(`Available mirrors: ${mirrors.join(", ")}`);
64+
5565
// We will attempt all mirrors before making a last-ditch attempt to the official download.
5666
// To avoid hammering a single mirror, we first randomize the array.
57-
const shuffled_mirrors = MIRRORS.map((m) => [m, Math.random()]).sort((a, b) => a[1] - b[1]).map((a) => a[0]);
67+
const shuffled_mirrors = mirrors.map((m) => [m, Math.random()]).sort((a, b) => a[1] - b[1]).map((a) => a[0]);
5868
for (const mirror of shuffled_mirrors) {
5969
core.info(`Attempting mirror: ${mirror}`);
6070
try {

mirrors.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)