Add 'mirror' input

This commit is contained in:
mlugg
2024-06-08 16:36:58 +01:00
parent 2a0f10ede6
commit 1cc5703fe8
3 changed files with 23 additions and 0 deletions
+13
View File
@@ -31,6 +31,19 @@ for the latest full release. The default is `latest`.
> Mirrors, including the official Zig website, may purge old nightly builds at their leisure. This means
> that if you target an out-of-date nightly build, such as a `0.11.0-dev` build, the download may fail.
If you want to use one specific mirror, you can set it using the `mirror` option:
```yaml
- uses: mlugg/setup-zig@v1
with:
mirror: 'https://pkg.machengine.org/zig'
```
Please don't do this unnecessarily; it's not nice to hammer one mirror. This mirror is not permitted to
be https://ziglang.org/download to avoid the oggicial websote being hit with large amounts of requests.
If you've experienced issues with a default mirror, please open an issue, and I will communicate with the
mirror's owner or remove it from the list.
## Details
This action attempts to download the requested Zig tarball from a set of mirrors, in a random order. As
+4
View File
@@ -5,6 +5,10 @@ inputs:
description: 'Version of the Zig compiler, e.g. "0.13.0" or "0.13.0-dev.351+64ef45eb0". "master" uses the latest nightly build. "latest" uses the latest tagged release.'
required: true
default: 'latest'
mirror:
description: 'Override of Zig download mirror to use, e.g. "https://pkg.machengine.org/zig".'
required: false
default: ''
runs:
using: 'node20'
main: 'main.js'
+6
View File
@@ -38,6 +38,12 @@ async function downloadFromMirror(mirror, tarball_name, tarball_ext) {
}
async function downloadTarball(tarball_name, tarball_ext) {
const preferred_mirror = core.getInput('mirror');
if (preferred_mirror) {
core.info(`Using mirror: ${preferred_mirror}`);
return await downloadFromMirror(preferred_mirror, tarball_name, tarball_ext);
}
// We will attempt all mirrors before making a last-ditch attempt to the official download.
// To avoid hammering a single mirror, we first randomize the array.
const shuffled_mirrors = MIRRORS.map((m) => [m, Math.random()]).sort((a, b) => a[1] - b[1]).map((a) => a[0]);