forked from chrisdickinson/setup-yq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const { promisify } = require('util')
const path = require('path')
const os = require('os')
const fs = require('fs')
const cache = require('@actions/tool-cache')
const core = require('@actions/core')
const chmod = promisify(fs.chmod)
if (require.main === module) {
main().catch(err => {
console.error(err.stack)
process.exit(1)
})
}
async function main () {
try {
const url = core.getInput('yq-url')
const version = core.getInput('yq-version')
const platform = os.platform()
let arch = os.arch()
if (arch === 'x64') {
arch = 'amd64'
}
let toolPath = cache.find('yq', version, arch)
if (!toolPath) {
const context = {
arch,
platform,
version
}
const rendered = url.replace(/\{(\w+?)\}/g, (a, match) => {
return context[match] || ''
})
const downloadPath = await cache.downloadTool(rendered)
toolPath = await cache.cacheFile(downloadPath, 'yq', 'yq', version)
}
await chmod(path.join(toolPath, 'yq'), 0o755) // just in case we haven't preserved the executable bit
core.addPath(toolPath)
} catch (error) {
core.setFailed(error.message)
}
}