From 1cc5703fe8e2be17d79b8a8cb8af1f08d5d43795 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 8 Jun 2024 16:36:27 +0100 Subject: [PATCH] Add 'mirror' input --- README.md | 13 +++++++++++++ action.yml | 4 ++++ main.js | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 5a050ed..697ac1c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index b247429..fb012ba 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/main.js b/main.js index d1c9f98..8a78e97 100644 --- a/main.js +++ b/main.js @@ -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]);