generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.ts
68 lines (59 loc) · 2.11 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as core from '@actions/core';
import { exec } from '@actions/exec';
import * as os from 'os'
import * as path from 'path'
import { Inputs } from './settings';
async function run() {
try {
// install nbgv
let installArgs = ['tool', 'install', '-g', 'nbgv'];
if (Inputs.toolVersion) {
installArgs.push('--version', Inputs.toolVersion);
}
let exitCode = await exec('dotnet', installArgs, { ignoreReturnCode: true });
if (exitCode > 1) {
throw new Error("dotnet tool install failed.");
}
// add .dotnet/tools to the path
core.addPath(path.join(os.homedir(), '.dotnet', 'tools'));
// Collect a JSON string of all the version properties.
let args = ['get-version', '-f', 'json'];
if (Inputs.path) {
args.push('-p', Inputs.path);
}
let versionJson = '';
await exec('nbgv', args, { listeners: { stdout: (data: Buffer) => { versionJson += data.toString() } } });
core.setOutput('versionJson', versionJson);
// Break up the JSON into individual outputs.
const versionProperties = JSON.parse(versionJson);
for (let name in versionProperties.CloudBuildAllVars) {
// Trim off the leading NBGV_
core.setOutput(name.substring(5), versionProperties.CloudBuildAllVars[name]);
}
// Set environment variables if desired.
if (Inputs.setCommonVars || Inputs.setAllVars) {
args = ['cloud'];
if (Inputs.path) {
args.push('-p', Inputs.path);
}
if (Inputs.setCommonVars) {
args.push('-c');
}
if (Inputs.setAllVars) {
args.push('-a');
}
await exec('nbgv', args);
}
// Stamp the version on an existing file, if desired.
if (Inputs.stamp) {
if (path.basename(Inputs.stamp) === 'package.json') {
await exec('npm', ['version', versionProperties.NpmPackageVersion, '--git-tag-version=false', '--allow-same-version'], { cwd: path.dirname(Inputs.stamp) });
} else {
throw new Error(`Unable to stamp unsupported file format: ${path.basename(Inputs.stamp)}`);
}
}
} catch (error) {
core.setFailed(error.message);
}
}
run();