forked from actionshub/chef-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (47 loc) · 1.64 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
40
41
42
43
44
45
46
47
48
49
const core = require('@actions/core');
const exec = require('@actions/exec')
const os = require('os')
async function main() {
try {
// Get the variables we care about
const channel = core.getInput('channel') || 'stable';
const project = core.getInput('project') || 'chef-workstation';
const version = core.getInput('version');
const omnitruckUrl = core.getInput('omnitruckUrl') || 'omnitruck.chef.io';
// This tool has intimate knowledge of the os
// as Windows and Linux/MacOs run different installers
// so we will check what OS and run appropriately
// Create the args that the bash script will need
if (os.platform() != 'win32')
{
var channelParam = `-c ${channel}`
var projectParam = `-P ${project}`
if (version) {
versionParam = `-v ${version}`
}
else {
versionParam = ''
}
await exec.exec(`curl -L https://${omnitruckUrl}/install.sh -o chefDownload.sh`)
await exec.exec(`chmod +x chefDownload.sh`)
await exec.exec(`./chefDownload.sh ${channelParam} ${projectParam} ${versionParam}`)
await exec.exec(`rm -f chefDownload.sh`)
}
// We are on windows so assume powershell
else
{
var channelParam = `-channel ${channel}`
var projectParam = `-project ${project}`
if (version) {
versionParam = `-version ${version}`
}
else {
versionParam = ''
}
await exec.exec(`powershell.exe -command ". { iwr -useb https://${omnitruckUrl}/install.ps1 } | iex; install ${channelParam} ${projectParam} ${versionParam}"`)
}
} catch (error){
core.setFailed(error.message);
}
}
main()