-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (45 loc) · 1.6 KB
/
index.js
File metadata and controls
58 lines (45 loc) · 1.6 KB
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
const core = require('@actions/core');
const cache = require('@actions/tool-cache');
const semver = require('semver');
const fs = require('fs').promises;
const os = require('os');
const toolName = 'ize';
async function exec() {
try {
let toolPath;
const version = core.getInput('version');
// is this version already in our cache
toolPath = cache.find(toolName, version);
if (!toolPath) {
toolPath = await downloadCLI(version);
}
// add tool to path for this and future actions to use
core.addPath(toolPath);
} catch (error) {
core.setFailed(error.message);
}
}
function getPlatform() {
const arch = os.arch();
// Map Node.js architecture names to ize release naming
const archMap = {
'x64': 'amd64',
'arm64': 'arm64'
};
if (!archMap[arch]) {
throw new Error(`Unsupported architecture: ${arch}. Supported architectures: x64, arm64`);
}
return archMap[arch];
}
async function downloadCLI(version) {
const cleanVersion = semver.clean(version) || '';
const platform = getPlatform();
const downloadURL = encodeURI(`https://github.com/hazelops/ize/releases/download/${cleanVersion}/ize_${cleanVersion}_linux_${platform}.tar.gz`);
const downloadedTool = await cache.downloadTool(downloadURL);
const extractedPath = await cache.extractTar(downloadedTool);
const toolPath = `${extractedPath}/ize`
const permissions = 0o755;
await fs.chmod(toolPath, permissions);
return await cache.cacheFile(toolPath, toolName, toolName, version, os.arch());
}
exec();