2023-05-18 06:30:28 -06:00
|
|
|
'use strict'
|
|
|
|
|
2019-10-05 04:44:40 -06:00
|
|
|
const os = require('os')
|
|
|
|
const path = require('path')
|
|
|
|
const semver = require('semver')
|
|
|
|
const actions = require('@actions/core')
|
|
|
|
const cache = require('@actions/tool-cache')
|
2020-11-11 04:38:41 -07:00
|
|
|
const {
|
|
|
|
extForPlatform,
|
|
|
|
resolveCommit,
|
|
|
|
resolveVersion
|
|
|
|
} = require('./versions')
|
2020-11-11 04:27:49 -07:00
|
|
|
|
2023-05-18 06:30:28 -06:00
|
|
|
const TOOL_NAME = 'zig'
|
|
|
|
|
2020-11-11 04:27:49 -07:00
|
|
|
async function downloadZig (platform, version) {
|
|
|
|
const ext = extForPlatform(platform)
|
|
|
|
|
2023-05-18 06:30:28 -06:00
|
|
|
const { downloadUrl, variantName, version: useVersion } = version.includes('+')
|
2020-11-11 04:27:49 -07:00
|
|
|
? resolveCommit(platform, version)
|
|
|
|
: await resolveVersion(platform, version)
|
|
|
|
|
2023-05-18 06:30:28 -06:00
|
|
|
const cachedPath = cache.find(TOOL_NAME, useVersion)
|
|
|
|
if (cachedPath) {
|
|
|
|
actions.info(`using cached zig install: ${cachedPath}`)
|
|
|
|
return cachedPath
|
|
|
|
}
|
|
|
|
|
|
|
|
actions.info(`no cached version found. downloading zig ${variantName}`)
|
2020-11-11 04:27:49 -07:00
|
|
|
const downloadPath = await cache.downloadTool(downloadUrl)
|
|
|
|
const zigPath = ext === 'zip'
|
|
|
|
? await cache.extractZip(downloadPath)
|
|
|
|
: await cache.extractTar(downloadPath, undefined, 'x')
|
|
|
|
|
|
|
|
const binPath = path.join(zigPath, variantName)
|
2023-05-18 06:30:28 -06:00
|
|
|
const cachePath = await cache.cacheDir(binPath, TOOL_NAME, useVersion)
|
|
|
|
actions.info(`added zig ${useVersion} to the tool cache`)
|
2020-11-11 04:27:49 -07:00
|
|
|
|
|
|
|
return cachePath
|
2019-10-05 04:44:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function main () {
|
2022-11-07 05:19:37 -07:00
|
|
|
const version = actions.getInput('version') || 'master'
|
2020-01-23 02:55:01 -07:00
|
|
|
if (semver.valid(version) && semver.lt(version, '0.3.0')) {
|
2019-10-05 04:44:40 -06:00
|
|
|
actions.setFailed('This action does not work with Zig 0.1.0 and Zig 0.2.0')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 06:30:28 -06:00
|
|
|
const zigPath = await downloadZig(os.platform(), version)
|
2019-10-05 04:44:40 -06:00
|
|
|
|
|
|
|
// Add the `zig` binary to the $PATH
|
|
|
|
actions.addPath(zigPath)
|
2023-05-18 06:30:28 -06:00
|
|
|
actions.info(`zig installed at ${zigPath}`)
|
2019-10-05 04:44:40 -06:00
|
|
|
}
|
|
|
|
|
2020-02-01 11:01:44 -07:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err.stack)
|
|
|
|
actions.setFailed(err.message)
|
|
|
|
process.exit(1)
|
|
|
|
})
|