This commit is contained in:
Renée Kooi 2020-11-11 12:27:49 +01:00
parent a43b52f8f8
commit ab441cce53
No known key found for this signature in database
GPG Key ID: 9940E33D1A44ADBF

View File

@ -17,38 +17,36 @@ function getJSON (opts) {
})
}
async function downloadZig (version) {
const host = {
linux: 'x86_64-linux',
darwin: 'x86_64-macos',
win32: 'x86_64-windows'
}[os.platform()] || os.platform()
const ext = {
function extForPlatform (platform) {
return {
linux: 'tar.xz',
darwin: 'tar.xz',
win32: 'zip'
}[os.platform()]
}[platform]
}
if (version.includes('+')) {
// use exact commit hash
function resolveCommit (platform, version) {
const ext = extForPlatform(platform)
const addrhost = {
linux: 'linux-x86_64',
darwin: 'macos-x86_64',
win32: 'windows-x86_64'
}[os.platform()]
}[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'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')
return { downloadUrl, variantName }
}
const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
async function resolveVersion (platform, version) {
const ext = extForPlatform(platform)
const host = {
linux: 'x86_64-linux',
darwin: 'x86_64-macos',
win32: 'x86_64-windows'
}[platform] || platform
return cachePath
} else {
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
const availableVersions = Object.keys(index)
@ -61,9 +59,20 @@ async function downloadZig (version) {
throw new Error(`Could not find version ${version} for platform ${host}`)
}
const downloadUrl = meta[host].tarball
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
const downloadPath = await cache.downloadTool(meta[host].tarball)
return { downloadUrl, variantName }
}
async function downloadZig (platform, version) {
const ext = extForPlatform(platform)
const { downloadUrl, variantName } = version.includes('+')
? resolveCommit(platform, version)
: await resolveVersion(platform, version)
const downloadPath = await cache.downloadTool(downloadUrl)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')
@ -73,7 +82,6 @@ async function downloadZig (version) {
return cachePath
}
}
async function main () {
const version = actions.getInput('version') || '0.5.0'
@ -84,7 +92,7 @@ async function main () {
let zigPath = cache.find('zig', version)
if (!zigPath) {
zigPath = await downloadZig(version)
zigPath = await downloadZig(os.platform(), version)
}
// Add the `zig` binary to the $PATH