-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
101 lines (84 loc) · 2.98 KB
/
index.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import * as util from 'util'
import * as os from 'os'
import * as fs from 'fs'
import * as path from 'path'
import * as core from '@actions/core'
import * as cache from '@actions/tool-cache'
const toolName = 'helmwave'
const downloadUrl = 'https://github.com/helmwave/helmwave/releases/download'
export async function run() {
let version = core.getInput('version', { 'required': true })
let cachedPath = await download(version)
console.log(`Helmwave tool version: '${version}' has been cached at ${cachedPath}`)
core.setOutput('path', cachedPath)
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
core.addPath(path.dirname(cachedPath))
}
}
export function getURL(version: string): string {
const arch = os.arch() == 'x64' ? 'amd64' : os.arch()
switch (os.type()) {
case 'Linux':
return util.format('%s/v%s/helmwave_%s_linux_%s.tar.gz',downloadUrl, version, version, arch)
case 'Darwin':
return util.format('%s/v%s/helmwave_%s_darwin_%s.tar.gz',downloadUrl, version, version, arch)
case 'Windows_NT':
default:
return util.format('%s/v%s/helmwave_%s_windows_%s.zip', downloadUrl, version, version, arch)
}
}
export async function download(version: string): Promise<string> {
let cached = cache.find(toolName, version)
let url = getURL(version)
if (!cached) {
let downloadPath
try {
downloadPath = await cache.downloadTool(url)
} catch (exception) {
throw new Error(util.format("Failed to download Helmwave from location", url))
}
fs.chmodSync(downloadPath, '777')
const untarPath = await cache.extractTar(downloadPath)
cached = await cache.cacheDir(untarPath, toolName, version)
}
const pathBin = findBin(cached)
if (!pathBin) {
throw new Error(util.format("Helmwave executable not found in path", cached))
}
fs.chmodSync(pathBin, '777')
return pathBin
}
export function findBin(rootDir: string): string {
fs.chmodSync(rootDir, '777')
let fileList: string[] = []
walkSync(rootDir, fileList, toolName + getExecutableExtension())
if (!fileList || fileList.length == 0) {
throw new Error(util.format("Helmwave executable not found in path", rootDir))
}
else {
return fileList[0]
}
}
export function getExecutableExtension(): string {
if (os.type().match(/^Win/)) {
return '.exe'
}
return ''
}
export var walkSync = function (dir, fileList, fileToFind) {
let files = fs.readdirSync(dir)
fileList = fileList || []
files.forEach(function (file) {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
fileList = walkSync(path.join(dir, file), fileList, fileToFind)
}
else {
core.debug(file)
if (file == fileToFind) {
fileList.push(path.join(dir, file))
}
}
})
return fileList
}
run().catch(core.setFailed)