forked from Azure/login
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.ts
More file actions
55 lines (50 loc) · 1.85 KB
/
Copy pathUtils.ts
File metadata and controls
55 lines (50 loc) · 1.85 KB
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
import * as os from 'os';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import Constants from '../Constants';
import PowerShellToolRunner from './PowerShellToolRunner';
export default class Utils {
static async getLatestModule(moduleName: string): Promise<string> {
let output: string = "";
let error: string = "";
const options: any = {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
},
stderr: (data: Buffer) => {
error += data.toString();
}
}
};
await PowerShellToolRunner.init();
await PowerShellToolRunner.executePowerShellCommand(`(Get-Module -Name ${moduleName} -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()`, options);
if(!Utils.isValidVersion(output.trim())) {
return "";
}
return output.trim();
}
private static isValidVersion(version: string): boolean {
return !!version.match(Constants.versionPattern);
}
static setPSModulePath(azPSVersion: string = "") {
let modulePath: string = "";
const runner: string = process.env.RUNNER_OS || os.type();
switch (runner.toLowerCase()) {
case "linux":
modulePath = `/usr/share/${azPSVersion}:`;
break;
case "windows":
case "windows_nt":
modulePath = `C:\\Modules\\${azPSVersion};`;
break;
case "macos":
case "darwin":
// TODO: add modulepath
break;
default:
throw new Error("Unknown os");
}
process.env.PSModulePath = `${modulePath}${process.env.PSModulePath}`;
}
}