Added getlatestazmodule version

This commit is contained in:
aksm-ms
2020-03-06 12:26:11 +05:30
parent 7882b87bc3
commit 12e896239f
2 changed files with 53 additions and 14 deletions

View File

@@ -16,24 +16,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const io = __importStar(require("@actions/io"));
var psPath;
exports.initializeAz = (servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId) => __awaiter(void 0, void 0, void 0, function* () {
psPath = yield io.which("pwsh", true);
setPSModulePath();
setPSModulePath(yield getLatestAzModule());
yield loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId);
});
function setPSModulePath() {
// TODO: get latest module/setup action
let azPSVersion = "3.5.0";
function setPSModulePath(azPSVersion = "") {
let modulePath = "";
switch (process.env.RUNNER_OS) {
case "Linux":
modulePath = `/usr/share/az_${azPSVersion}:`;
modulePath = `/usr/share/${azPSVersion}:`;
break;
case "Windows":
modulePath = `C:\\Modules\\az_${azPSVersion};`;
modulePath = `C:\\Modules\\${azPSVersion};`;
break;
case "macOS":
// TODO: add modulepath
@@ -41,6 +41,26 @@ function setPSModulePath() {
}
process.env.PSModulePath = `${modulePath}${process.env.PSModulePath}`;
}
function getLatestAzModule() {
return __awaiter(this, void 0, void 0, function* () {
const moduleName = "Az.Accounts";
let output = "";
let error = "";
let options = {
listeners: {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
error += data.toString();
}
}
};
yield executePowerShellCommand(`(Get-Module -Name ${moduleName} -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()`, options);
core.debug(`Az Module version used: ${output}`);
return `az_${output}`;
});
}
function loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId) {
return __awaiter(this, void 0, void 0, function* () {
const environment = "AzureCloud";
@@ -53,10 +73,10 @@ function loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscri
yield executePowerShellCommand(`Get-AzContext`);
});
}
function executePowerShellCommand(command) {
function executePowerShellCommand(command, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield exec.exec(`"${psPath}" -Command "${command}"`, [], {});
yield exec.exec(`"${psPath}" -Command "${command}"`, [], options);
}
catch (error) {
throw new Error(error);