generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.js
42 lines (35 loc) · 1.02 KB
/
utils.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
const exec = require('@actions/exec');
exports.parseEtcRelease = async () => {
let osName = null;
let osVersion = null;
const options = {
listeners: {
stdline: (line) => {
// Split on = if only one present
const count = line.match(/=/g);
if (count && count.length == 1) {
const kvp = line.split('=');
if (kvp[0] === 'VERSION_ID' && !osVersion) {
osVersion = kvp[1].replace(/"/g, '').toString();
}
if (kvp[0] === 'NAME' && !osName) {
osName = kvp[1].replace(/"/g, '').toString();
}
}
},
},
};
await exec.exec('bash', ['-c', 'cat /etc/*-release'], options);
return {
name: osName,
versionId: osVersion,
};
};
exports.isSelfHosted = () =>
process.env['AGENT_ISSELFHOSTED'] === '1' ||
(process.env['AGENT_ISSELFHOSTED'] === undefined &&
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted');
exports.getWindowsDrive = (path) => {
const drive = path.split(':')[0];
return drive;
}