2019-10-05 10:44:40 +00: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 11:38:41 +00:00
|
|
|
const {
|
|
|
|
extForPlatform,
|
|
|
|
resolveCommit,
|
|
|
|
resolveVersion
|
|
|
|
} = require('./versions')
|
2020-11-11 11:27:49 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
const binPath = path.join(zigPath, variantName)
|
|
|
|
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
|
|
|
|
|
|
|
|
return cachePath
|
2019-10-05 10:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function main () {
|
2022-11-07 12:19:37 +00:00
|
|
|
const version = actions.getInput('version') || 'master'
|
2020-01-23 09:55:01 +00:00
|
|
|
if (semver.valid(version) && semver.lt(version, '0.3.0')) {
|
2019-10-05 10:44:40 +00:00
|
|
|
actions.setFailed('This action does not work with Zig 0.1.0 and Zig 0.2.0')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-06 13:52:14 +00:00
|
|
|
let zigPath = cache.find('zig', version)
|
|
|
|
if (!zigPath) {
|
2020-11-11 11:27:49 +00:00
|
|
|
zigPath = await downloadZig(os.platform(), version)
|
2019-10-06 13:52:14 +00:00
|
|
|
}
|
2019-10-05 10:44:40 +00:00
|
|
|
|
|
|
|
// Add the `zig` binary to the $PATH
|
|
|
|
actions.addPath(zigPath)
|
|
|
|
}
|
|
|
|
|
2020-02-01 18:01:44 +00:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err.stack)
|
|
|
|
actions.setFailed(err.message)
|
|
|
|
process.exit(1)
|
|
|
|
})
|