-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (66 loc) · 3 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
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
const https = require("https"),
fs = require("fs"),
path = require("path"),
spawnSync = require("child_process").spawnSync,
core = require("@actions/core")
class Action
{
constructor()
{
this.versionMajor = process.env.INPUT_VERSION_MAJOR
this.versionMinor = process.env.INPUT_VERSION_MINOR
this.versionBand = process.env.INPUT_VERSION_BAND
this.runtimeVersions = process.env.INPUT_RUNTIME_VERSIONS.split(';')
this.sdkVersion = process.env.INPUT_SDK_VERSION
}
_printErrorAndExit(msg)
{
console.log(`##[error]😭 ${msg}`)
throw new Error(msg)
}
_executeCommand(cmd, options)
{
const INPUT = cmd.split(" "), TOOL = INPUT[0], ARGS = INPUT.slice(1)
return spawnSync(TOOL, ARGS, options)
}
_getDotnetRoot()
{
// This is the default set in the install-dotnet scripts.
return process.platform === 'win32' ? path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet') : path.join(process.env['HOME'] + '', '.dotnet')
}
_addToPath()
{
var dotnetRoot = this._getDotnetRoot()
if (!process.env['DOTNET_INSTALL_DIR'])
{
core.addPath(dotnetRoot)
core.exportVariable('DOTNET_ROOT', dotnetRoot)
}
// Add DOTNET_INSTALL_DIR to path and export the variable DOTNET_ROOT if DOTNET_INSTALL_DIR is set.
if (process.env['DOTNET_INSTALL_DIR'])
{
core.addPath(process.env['DOTNET_INSTALL_DIR'])
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR'])
}
}
_DotnetInstallCommand()
{
return process.platform === 'win32' ? [`pwsh ${__dirname}/dotnet-install.ps1`, '-Channel', '-Quality', '-Version', '-Runtime'] : [`${__dirname}/dotnet-install.sh`, '--channel', '--quality', '--version', '--runtime']
}
run()
{
var command = this._DotnetInstallCommand()
this._executeCommand(`${command[0]} ${this.sdkVersion === '' ? `${command[1]} ${this.versionMajor}.${this.versionMinor}.${this.versionBand} ${command[2]} daily` : `${command[3]} ${this.sdkVersion}`}`, { encoding: "utf-8", stdio: [process.stdin, process.stdout, process.stderr] })
// Install the runtimes from the list of runtimes.
for (let runtimeVersion of this.runtimeVersions)
{
// install base runtime.
this._executeCommand(`${command[0]} ${runtimeVersion === '6.0.x' ? `${command[1]} 6.0 ${command[2]} daily`: `${command[3]} ${runtimeVersion}`} ${command[4]} dotnet`, { encoding: "utf-8", stdio: [process.stdin, process.stdout, process.stderr] })
// install aspnetcore runtime.
this._executeCommand(`${command[0]} ${runtimeVersion === '6.0.x' ? `${command[1]} 6.0 ${command[2]} daily`: `${command[3]} ${runtimeVersion}`} ${command[4]} aspnetcore`, { encoding: "utf-8", stdio: [process.stdin, process.stdout, process.stderr] })
}
this._addToPath()
}
}
const action = new Action();
action.run()