From 4c5e0a7005f0fabab3d1884795577b04404b2704 Mon Sep 17 00:00:00 2001 From: CodeHz Date: Sat, 24 Oct 2020 17:47:20 +0800 Subject: [PATCH 1/3] allow use exact commit hash --- dist/index.js | 50 +++++++++++++++++++++++++++++++++----------------- index.js | 50 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 34 deletions(-) diff --git a/dist/index.js b/dist/index.js index 039608e6..65bfaa92 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,29 +36,45 @@ async function downloadZig (version) { win32: 'zip' }[os.platform()] - const index = await getJSON({ url: 'https://ziglang.org/download/index.json' }) + if (version.includes('+')) { + // use exact commit hash + const downloadUrl = `https://ziglang.org/builds/zig-${host}-${version}.${ext}` + const variantName = `zig-${host}-${version}` - const availableVersions = Object.keys(index) - const useVersion = semver.valid(version) - ? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version) - : null + const downloadPath = await cache.downloadTool(downloadUrl) + const zigPath = ext === 'zip' + ? await cache.extractZip(downloadPath) + : await cache.extractTar(downloadPath, undefined, 'x') - const meta = index[useVersion || version] - if (!meta || !meta[host]) { - throw new Error(`Could not find version ${version} for platform ${host}`) - } + const binPath = path.join(zigPath, variantName) + const cachePath = await cache.cacheDir(binPath, 'zig', variantName) + + return cachePath + } else { + const index = await getJSON({ url: 'https://ziglang.org/download/index.json' }) - const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '') + const availableVersions = Object.keys(index) + const useVersion = semver.valid(version) + ? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version) + : null - const downloadPath = await cache.downloadTool(meta[host].tarball) - const zigPath = ext === 'zip' - ? await cache.extractZip(downloadPath) - : await cache.extractTar(downloadPath, undefined, 'x') + const meta = index[useVersion || version] + if (!meta || !meta[host]) { + throw new Error(`Could not find version ${version} for platform ${host}`) + } - const binPath = path.join(zigPath, variantName) - const cachePath = await cache.cacheDir(binPath, 'zig', variantName) + const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '') - return cachePath + const downloadPath = await cache.downloadTool(meta[host].tarball) + const zigPath = ext === 'zip' + ? await cache.extractZip(downloadPath) + : await cache.extractTar(downloadPath, undefined, 'x') + + const binPath = path.join(zigPath, variantName) + const cachePath = await cache.cacheDir(binPath, 'zig', variantName) + + return cachePath + } } async function main () { diff --git a/index.js b/index.js index e2fe21fb..aa6b9268 100644 --- a/index.js +++ b/index.js @@ -29,29 +29,45 @@ async function downloadZig (version) { win32: 'zip' }[os.platform()] - const index = await getJSON({ url: 'https://ziglang.org/download/index.json' }) + if (version.includes('+')) { + // use exact commit hash + const downloadUrl = `https://ziglang.org/builds/zig-${host}-${version}.${ext}` + const variantName = `zig-${host}-${version}` - const availableVersions = Object.keys(index) - const useVersion = semver.valid(version) - ? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version) - : null + const downloadPath = await cache.downloadTool(downloadUrl) + const zigPath = ext === 'zip' + ? await cache.extractZip(downloadPath) + : await cache.extractTar(downloadPath, undefined, 'x') - const meta = index[useVersion || version] - if (!meta || !meta[host]) { - throw new Error(`Could not find version ${version} for platform ${host}`) - } + const binPath = path.join(zigPath, variantName) + const cachePath = await cache.cacheDir(binPath, 'zig', variantName) + + return cachePath + } else { + const index = await getJSON({ url: 'https://ziglang.org/download/index.json' }) + + const availableVersions = Object.keys(index) + const useVersion = semver.valid(version) + ? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version) + : null - const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '') + const meta = index[useVersion || version] + if (!meta || !meta[host]) { + throw new Error(`Could not find version ${version} for platform ${host}`) + } - const downloadPath = await cache.downloadTool(meta[host].tarball) - const zigPath = ext === 'zip' - ? await cache.extractZip(downloadPath) - : await cache.extractTar(downloadPath, undefined, 'x') + const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '') - const binPath = path.join(zigPath, variantName) - const cachePath = await cache.cacheDir(binPath, 'zig', variantName) + const downloadPath = await cache.downloadTool(meta[host].tarball) + const zigPath = ext === 'zip' + ? await cache.extractZip(downloadPath) + : await cache.extractTar(downloadPath, undefined, 'x') - return cachePath + const binPath = path.join(zigPath, variantName) + const cachePath = await cache.cacheDir(binPath, 'zig', variantName) + + return cachePath + } } async function main () { From 4892f7845504fef5da2bc0e89c069a6558ff059e Mon Sep 17 00:00:00 2001 From: CodeHz Date: Sat, 24 Oct 2020 17:57:48 +0800 Subject: [PATCH 2/3] fix url --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index aa6b9268..4ee7d610 100644 --- a/index.js +++ b/index.js @@ -31,8 +31,13 @@ async function downloadZig (version) { if (version.includes('+')) { // use exact commit hash - const downloadUrl = `https://ziglang.org/builds/zig-${host}-${version}.${ext}` - const variantName = `zig-${host}-${version}` + const addrhost = { + linux: 'linux-x86_64', + darwin: 'macos-x86_64', + win32: 'windows-x86_64' + }[os.platform()] + const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}` + const variantName = `zig-${addrhost}-${version}` const downloadPath = await cache.downloadTool(downloadUrl) const zigPath = ext === 'zip' From 94220ae07a3fd8bd937891aa0aa9714494efc9b0 Mon Sep 17 00:00:00 2001 From: CodeHz Date: Sat, 24 Oct 2020 17:59:26 +0800 Subject: [PATCH 3/3] fix prepare --- dist/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 65bfaa92..996c3871 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38,8 +38,13 @@ async function downloadZig (version) { if (version.includes('+')) { // use exact commit hash - const downloadUrl = `https://ziglang.org/builds/zig-${host}-${version}.${ext}` - const variantName = `zig-${host}-${version}` + const addrhost = { + linux: 'linux-x86_64', + darwin: 'macos-x86_64', + win32: 'windows-x86_64' + }[os.platform()] + const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}` + const variantName = `zig-${addrhost}-${version}` const downloadPath = await cache.downloadTool(downloadUrl) const zigPath = ext === 'zip'