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