diff --git a/dist/index.js b/dist/index.js index 43034a7..601bcb6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -82166,15 +82166,15 @@ var require_versions = __commonJS({ x64: "x86_64" }[arch]; const host = `${resolvedArch}-${resolvedOs}`; - const index = await getJSON({ url: "https://ziglang.org/download/index.json" }); - const availableVersions = Object.keys(index); + const machIndex = await getJSON({ url: "https://machengine.org/zig/index.json" }); + const availableVersions = Object.keys(machIndex); const useVersion = semver2.valid(version3) ? semver2.maxSatisfying(availableVersions.filter((v) => semver2.valid(v)), version3) : null; - const meta = index[useVersion || version3]; + const meta = machIndex[useVersion || version3] || (await getJSON({ url: "https://ziglang.org/download/index.json" }))[useVersion || version3]; if (!meta || !meta[host]) { throw new Error(`Could not find version ${useVersion || version3} for platform ${host}`); } const downloadUrl = meta[host].tarball; - const variantName = path2.basename(meta[host].tarball).replace(`.${ext}`, ""); + const variantName = path2.basename(meta[host].tarball).replace(`.${ext}`, "").replace(/\+\S*$/, ""); return { downloadUrl, variantName, version: useVersion || version3 }; } __name(resolveVersion2, "resolveVersion"); @@ -82225,6 +82225,7 @@ async function downloadZig(arch, platform, version3, useCache = true) { actions.info(`no cached version found. downloading zig ${variantName}`); const downloadPath = await toolCache.downloadTool(downloadUrl); const zigPath = ext === "zip" ? await toolCache.extractZip(downloadPath) : await toolCache.extractTar(downloadPath, void 0, "x"); + actions.info(`${variantName} zig downloaded and extracted to ${zigPath}`); const binPath = path.join(zigPath, fileWithoutFileType); const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion); if (useCache) { diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ad157bd --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1714245158, + "narHash": "sha256-9P2M0+tf1TE7Z5PwDVwhheuD2mFf6/phPr0Jvl7cxcc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2b1f64b358f2cab62617f26b3870fd0ee375d848", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixpkgs-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/index.js b/index.js index 4f4c900..a62212f 100644 --- a/index.js +++ b/index.js @@ -49,6 +49,7 @@ async function downloadZig (arch, platform, version, useCache = true) { ? await toolCache.extractZip(downloadPath) : await toolCache.extractTar(downloadPath, undefined, 'x') + actions.info(`${variantName} zig downloaded and extracted to ${zigPath}`) const binPath = path.join(zigPath, fileWithoutFileType) const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion) diff --git a/test.js b/test.js index 81c5c35..7418d53 100644 --- a/test.js +++ b/test.js @@ -45,6 +45,29 @@ async function test () { variantName: 'zig-macos-aarch64-0.11.0', version: '0.11.0' }) + assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.1.0-mach'), { + downloadUrl: 'https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz', + variantName: 'zig-macos-aarch64-0.12.0-dev.2063', + version: '2024.1.0-mach' + }) + assert.deepEqual(await resolveVersion('x64', 'linux', '2024.3.0-mach'), { + downloadUrl: 'https://pkg.machengine.org/zig/zig-linux-x86_64-0.12.0-dev.3180+83e578a18.tar.xz', + variantName: 'zig-linux-x86_64-0.12.0-dev.3180', + version: '2024.3.0-mach' + }) + assert.deepEqual(await resolveVersion('x64', 'win32', '2024.1.0-mach'), { + downloadUrl: 'https://pkg.machengine.org/zig/zig-windows-x86_64-0.12.0-dev.2063+804cee3b9.zip', + variantName: 'zig-windows-x86_64-0.12.0-dev.2063', + version: '2024.1.0-mach' + }) + assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.3.0-mach'), { + downloadUrl: 'https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.3180+83e578a18.tar.xz', + variantName: 'zig-macos-aarch64-0.12.0-dev.3180', + version: '2024.3.0-mach' + }) + await assert.doesNotReject(resolveVersion('x64', 'linux', 'mach-latest')) + await assert.doesNotReject(resolveVersion('x64', 'win32', 'mach-latest')) + await assert.doesNotReject(resolveVersion('arm64', 'darwin', 'mach-latest')) await assert.doesNotReject(resolveVersion('x64', 'linux', 'master')) await assert.doesNotReject(resolveVersion('x64', 'win32', 'master')) await assert.doesNotReject(resolveVersion('arm64', 'darwin', 'master')) diff --git a/versions.js b/versions.js index ad91fc9..019cf4c 100644 --- a/versions.js +++ b/versions.js @@ -10,6 +10,12 @@ function extForPlatform (platform) { }[platform] } +/** + * resolveCommit resolves a specific commit, so is only used + * in cases where the zig version is specified through the use of a plus + * sign. It does not require any fetch from an external resource as the + * data (downloadUrl, etc) can be resolved directly + */ function resolveCommit (arch, platform, version) { const ext = extForPlatform(platform) const resolvedOs = { @@ -27,6 +33,11 @@ function resolveCommit (arch, platform, version) { }[arch] const downloadUrl = `https://ziglang.org/builds/zig-${resolvedOs}-${resolvedArch}-${version}.${ext}` + // This function is only called if the version includes a '+' sign, so mach versions + // will not come through here + // + // Mach builds come from pkg.machengine.org + // const machDownloadUrl = `https://pkg.machengine.org/zig/zig-${resolvedOs}-${resolvedArch}-${version}.${ext}` const versionWithoutBuildHash = semver.clean(version) const fileWithoutFileType = `zig-${resolvedOs}-${resolvedArch}-${version}` const variantName = `zig-${resolvedOs}-${resolvedArch}-${versionWithoutBuildHash}` @@ -51,6 +62,16 @@ function getJSON (opts) { }) } +/** + * resolveVersion resolves a generic commit, so is only used + * in cases where the zig version is specified through WITHOUT the use of a plus + * sign. It needs to fetch data from the index files provided by zig (or mach) + * to determine the appropriate downloadUrl, etc. + * + * @returns {string} download URL for the version + * @returns {string} variant name for the version - should be used as cache key + * @returns {string} version name - use for display only + */ async function resolveVersion (arch, platform, version) { const ext = extForPlatform(platform) const resolvedOs = { @@ -69,20 +90,29 @@ async function resolveVersion (arch, platform, version) { const host = `${resolvedArch}-${resolvedOs}` - const index = await getJSON({ url: 'https://ziglang.org/download/index.json' }) + // const index = await getJSON({ url: 'https://ziglang.org/download/index.json' }) + const machIndex = await getJSON({ url: 'https://machengine.org/zig/index.json' }) - const availableVersions = Object.keys(index) + const availableVersions = Object.keys(machIndex) const useVersion = semver.valid(version) ? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version) : null - const meta = index[useVersion || version] + // The mach index is advertised as a strict superset of the ziglang index, + // but we will fall back to the the ziglang index just in case + const meta = machIndex[useVersion || version] || + (await getJSON({ url: 'https://ziglang.org/download/index.json' }))[useVersion || version] + if (!meta || !meta[host]) { throw new Error(`Could not find version ${useVersion || version} for platform ${host}`) } const downloadUrl = meta[host].tarball - const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '') + // If this is mach, we could end up with '+sha...' at the end of this, as + // a version of '2024.1.0-mach' will resolve to a specific dev version + // So, while the function is not called with "+...", we still have to deal with + // it. This is important as it is used as the cache key + const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '').replace(/\+\S*$/, '') return { downloadUrl, variantName, version: useVersion || version } }