Skip to content

Commit

Permalink
Add 'mirror' input
Browse files Browse the repository at this point in the history
  • Loading branch information
mlugg committed Jun 8, 2024
1 parent 2a0f10e commit 1cc5703
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 1cc5703

Please sign in to comment.