-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 1.05 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
const fs = require('fs')
const core = require('@actions/core')
const tc = require('@actions/tool-cache')
const { getDownloadUrl } = require('./lib/utils')
function isInstalled(toolPath) {
return toolPath !== undefined && toolPath !== ''
}
async function installVersion(version, { pythonVersion }) {
const downloadUrl = getDownloadUrl({ kapitanVersion: version, pythonVersion })
const path = await tc.downloadTool(downloadUrl, './kapitan')
fs.chmodSync(path, '0755')
return tc.cacheFile(path, 'kapitan', 'kapitan', version)
}
async function setup() {
try {
// Get version of tool to be installed
const kapitanVersion = core.getInput('version')
const pythonVersion = core.getInput('python-version')
let toolPath = tc.find('kapitan', kapitanVersion)
if (!isInstalled(toolPath)) {
toolPath = await installVersion(kapitanVersion, { pythonVersion })
}
core.info(`Adding ${toolPath} to path`)
core.addPath(toolPath)
} catch (e) {
core.setFailed(e)
}
}
module.exports = setup
if (require.main === module) {
setup()
}