-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.ts
47 lines (41 loc) · 1.31 KB
/
main.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
import * as fs from 'fs';
import * as os from 'os';
import * as child_process from 'child_process';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run() {
try {
if (os.platform() == 'darwin') {
core.setFailed('Not supported on darwin platform');
return;
}
const workspace = process.env['GITHUB_WORKSPACE'] || '.';
const args = core.getInput('args', {required: true});
if (os.platform() == 'win32') {
core.info('🏃 Running Choco...');
await exec.exec(`choco.exe ${args} --allow-unofficial`);
return;
}
core.info('🏃 Running Choco...');
fs.writeFileSync('/tmp/env.txt', child_process.execSync(`env`, {encoding: 'utf8'}).trim());
await exec.exec('docker', [
'run',
'--rm',
'--env-file',
'/tmp/env.txt',
'--workdir',
'/wksp',
'--volume',
`${workspace}:/wksp`,
'crazymax/ghaction-chocolatey',
args
]);
core.info('🔨 Fixing perms...');
const uid = parseInt(child_process.execSync(`id -u`, {encoding: 'utf8'}).trim());
const gid = parseInt(child_process.execSync(`id -g`, {encoding: 'utf8'}).trim());
await exec.exec('sudo', ['chown', '-R', `${uid}:${gid}`, workspace]);
} catch (error) {
core.setFailed(error.message);
}
}
run();