Skip to content

Commit 1300bbd

Browse files
committed
prepare release 1.4.0
1 parent cf0065b commit 1300bbd

File tree

4,344 files changed

+1429641
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,344 files changed

+1429641
-0
lines changed

lib/AzModuleInstaller.js

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27+
return new (P || (P = Promise))(function (resolve, reject) {
28+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31+
step((generator = generator.apply(thisArg, _arguments || [])).next());
32+
});
33+
};
34+
var __importDefault = (this && this.__importDefault) || function (mod) {
35+
return (mod && mod.__esModule) ? mod : { "default": mod };
36+
};
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
exports.AzModuleInstaller = exports.AzModuleSource = void 0;
39+
const core = __importStar(require("@actions/core"));
40+
const tc = __importStar(require("@actions/tool-cache"));
41+
const os = __importStar(require("os"));
42+
const ArchiveTools_1 = require("./Utilities/ArchiveTools");
43+
const FileUtils_1 = __importDefault(require("./Utilities/FileUtils"));
44+
const Utils_1 = __importDefault(require("./Utilities/Utils"));
45+
const path_1 = __importDefault(require("path"));
46+
const Constants_1 = __importDefault(require("./Constants"));
47+
exports.AzModuleSource = {
48+
PrivateAgent: "privateAgent",
49+
Folder: "hostedAgentFolder",
50+
Zip: "hostedAgentZip",
51+
GHRelease: "hostedAgentGHRelease",
52+
PSGallery: "hostedAgentPSGallery"
53+
};
54+
class AzModuleInstaller {
55+
constructor(version, githubAuth) {
56+
var _a;
57+
this.isWin = false;
58+
this.version = version;
59+
this.githubAuth = githubAuth;
60+
this.installResult = {
61+
moduleSource: "Others",
62+
isInstalled: false
63+
};
64+
const platform = (_a = (process.env.RUNNER_OS || os.type())) === null || _a === void 0 ? void 0 : _a.toLowerCase();
65+
core.debug(`Platform: ${platform}`);
66+
this.moduleRoot = Utils_1.default.getDefaultAzInstallFolder(platform);
67+
if (platform == "windows" || platform == "windows_nt") {
68+
this.isWin = true;
69+
}
70+
this.modulePath = path_1.default.join(this.moduleRoot, `${Constants_1.default.prefix}${this.version}`);
71+
this.moduleZipPath = `${this.modulePath}.zip`;
72+
}
73+
install() {
74+
return __awaiter(this, void 0, void 0, function* () {
75+
if (Utils_1.default.isHostedAgent(this.moduleRoot)) {
76+
yield this.tryInstallingLatest();
77+
yield this.tryInstallFromFolder();
78+
yield this.tryInstallFromZip();
79+
yield this.tryInstallFromGHRelease();
80+
yield this.tryInstallFromPSGallery();
81+
}
82+
else {
83+
core.debug("File layout is not like hosted agent, skippig module install.");
84+
this.installResult = {
85+
isInstalled: false,
86+
moduleSource: exports.AzModuleSource.PrivateAgent
87+
};
88+
}
89+
return this.installResult;
90+
});
91+
}
92+
tryInstallingLatest() {
93+
return __awaiter(this, void 0, void 0, function* () {
94+
if (this.installResult.isInstalled) {
95+
core.debug(`Module already installed skipping tryInstallingLatest`);
96+
return;
97+
}
98+
if (this.version === "latest") {
99+
core.debug("Latest selected, will use latest Az module available in agent as folder.");
100+
this.installResult = {
101+
isInstalled: true,
102+
moduleSource: exports.AzModuleSource.Folder
103+
};
104+
}
105+
});
106+
}
107+
tryInstallFromFolder() {
108+
return __awaiter(this, void 0, void 0, function* () {
109+
if (this.installResult.isInstalled) {
110+
core.debug(`Module already installed skipping tryInstallFromFolder`);
111+
return;
112+
}
113+
if (FileUtils_1.default.pathExists(this.modulePath)) {
114+
core.debug(`Az ${this.version} present at ${this.modulePath} as folder.`);
115+
this.installResult = {
116+
isInstalled: true,
117+
moduleSource: exports.AzModuleSource.Folder
118+
};
119+
}
120+
});
121+
}
122+
tryInstallFromZip() {
123+
return __awaiter(this, void 0, void 0, function* () {
124+
if (this.installResult.isInstalled) {
125+
core.debug(`Module already installed skipping tryInstallFromZip`);
126+
return;
127+
}
128+
if (FileUtils_1.default.pathExists(this.moduleZipPath)) {
129+
core.debug(`Az ${this.version} present at ${this.moduleZipPath} as zip, expanding it.`);
130+
yield new ArchiveTools_1.ArchiveTools(this.isWin).unzip(this.moduleZipPath, this.moduleRoot);
131+
yield FileUtils_1.default.deleteFile(this.moduleZipPath);
132+
this.installResult = {
133+
isInstalled: true,
134+
moduleSource: exports.AzModuleSource.Zip
135+
};
136+
}
137+
});
138+
}
139+
tryInstallFromGHRelease() {
140+
return __awaiter(this, void 0, void 0, function* () {
141+
if (this.installResult.isInstalled) {
142+
core.debug(`Module already installed skipping tryInstallFromGHRelease`);
143+
return;
144+
}
145+
try {
146+
const downloadUrl = yield this.getDownloadUrlFromGHRelease();
147+
core.debug(`Downloading Az ${this.version} from GHRelease using url ${downloadUrl}`);
148+
yield tc.downloadTool(downloadUrl, this.moduleZipPath, this.githubAuth);
149+
core.debug(`Expanding Az ${this.version} downloaded at ${this.moduleZipPath} as zip.`);
150+
yield new ArchiveTools_1.ArchiveTools(this.isWin).unzip(this.moduleZipPath, this.moduleRoot);
151+
yield FileUtils_1.default.deleteFile(this.moduleZipPath);
152+
this.installResult = {
153+
isInstalled: true,
154+
moduleSource: exports.AzModuleSource.GHRelease
155+
};
156+
}
157+
catch (err) {
158+
core.debug(err);
159+
core.info("Download from GHRelease failed, will fallback to PSGallery");
160+
}
161+
});
162+
}
163+
tryInstallFromPSGallery() {
164+
return __awaiter(this, void 0, void 0, function* () {
165+
if (this.installResult.isInstalled) {
166+
core.debug(`Module already installed skipping tryInstallFromPSGallery`);
167+
return;
168+
}
169+
yield Utils_1.default.saveAzModule(this.version, this.modulePath);
170+
this.installResult = {
171+
isInstalled: true,
172+
moduleSource: exports.AzModuleSource.PSGallery
173+
};
174+
});
175+
}
176+
getDownloadUrlFromGHRelease() {
177+
var _a;
178+
return __awaiter(this, void 0, void 0, function* () {
179+
core.debug("Getting versions manifest from GHRelease.");
180+
const releases = yield tc.getManifestFromRepo("Azure", "az-ps-module-versions", this.githubAuth, "main");
181+
core.debug(JSON.stringify(releases));
182+
const releaseInfo = (_a = releases.filter(release => release.version === this.version)) === null || _a === void 0 ? void 0 : _a[0];
183+
if (!releaseInfo || releaseInfo.files.length === 0) {
184+
throw new Error(`Version ${this.version} not present in versions manifest of GHRelease.`);
185+
}
186+
return releaseInfo.files[0].download_url;
187+
});
188+
}
189+
}
190+
exports.AzModuleInstaller = AzModuleInstaller;

lib/Constants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
class Constants {
4+
}
5+
exports.default = Constants;
6+
Constants.prefix = "az_";
7+
Constants.moduleName = "Az";
8+
Constants.versionPattern = /[0-9]\.[0-9]\.[0-9]/;
9+
Constants.Success = "Success";
10+
Constants.Error = "Error";
11+
Constants.AzVersion = "AzVersion";
12+
Constants.versionExists = "versionExists";

lib/InitializeAzure.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27+
return new (P || (P = Promise))(function (resolve, reject) {
28+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31+
step((generator = generator.apply(thisArg, _arguments || [])).next());
32+
});
33+
};
34+
var __importDefault = (this && this.__importDefault) || function (mod) {
35+
return (mod && mod.__esModule) ? mod : { "default": mod };
36+
};
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
const core = __importStar(require("@actions/core"));
39+
const Utils_1 = __importDefault(require("./Utilities/Utils"));
40+
const Constants_1 = __importDefault(require("./Constants"));
41+
class InitializeAzure {
42+
static importAzModule(azPSVersion) {
43+
return __awaiter(this, void 0, void 0, function* () {
44+
yield Utils_1.default.setPSModulePath();
45+
if (azPSVersion === "latest") {
46+
azPSVersion = yield Utils_1.default.getLatestModule(Constants_1.default.moduleName);
47+
}
48+
else {
49+
yield Utils_1.default.checkModuleVersion(Constants_1.default.moduleName, azPSVersion);
50+
}
51+
core.debug(`Az Module version used: ${azPSVersion}`);
52+
yield Utils_1.default.setPSModulePath(`${Constants_1.default.prefix}${azPSVersion}`);
53+
});
54+
}
55+
}
56+
exports.default = InitializeAzure;

lib/ScriptRunner.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27+
return new (P || (P = Promise))(function (resolve, reject) {
28+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31+
step((generator = generator.apply(thisArg, _arguments || [])).next());
32+
});
33+
};
34+
var __importDefault = (this && this.__importDefault) || function (mod) {
35+
return (mod && mod.__esModule) ? mod : { "default": mod };
36+
};
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
const core = __importStar(require("@actions/core"));
39+
const FileUtils_1 = __importDefault(require("./Utilities/FileUtils"));
40+
const PowerShellToolRunner_1 = __importDefault(require("./Utilities/PowerShellToolRunner"));
41+
const ScriptBuilder_1 = __importDefault(require("./Utilities/ScriptBuilder"));
42+
class ScriptRunner {
43+
constructor(inlineScript, errorActionPreference, failOnStandardErr) {
44+
this.inlineScript = inlineScript;
45+
this.errorActionPreference = errorActionPreference;
46+
this.failOnStandardErr = failOnStandardErr;
47+
}
48+
executeFile() {
49+
return __awaiter(this, void 0, void 0, function* () {
50+
const error = [];
51+
const options = {
52+
listeners: {
53+
stderr: (data) => {
54+
if (error.length < 10) {
55+
// Truncate to at most 1000 bytes
56+
if (data.length > 1000) {
57+
error.push(`${data.toString('utf8', 0, 1000)}<truncated>`);
58+
}
59+
else {
60+
error.push(data.toString('utf8'));
61+
}
62+
}
63+
else if (error.length === 10) {
64+
error.push('Additional writes to stderr truncated');
65+
}
66+
}
67+
}
68+
};
69+
const scriptToExecute = new ScriptBuilder_1.default().getInlineScriptFile(this.inlineScript, this.errorActionPreference);
70+
ScriptRunner.filePath = yield FileUtils_1.default.createScriptFile(scriptToExecute);
71+
core.debug(`script file to run: ${ScriptRunner.filePath}`);
72+
const exitCode = yield PowerShellToolRunner_1.default.executePowerShellScriptBlock(ScriptRunner.filePath, options);
73+
if (exitCode !== 0) {
74+
core.setOutput(`Azure PowerShell exited with code:`, exitCode.toString());
75+
if (this.failOnStandardErr) {
76+
error.forEach((err) => {
77+
core.error(err);
78+
});
79+
throw new Error(`Standard error stream contains one or more lines`);
80+
}
81+
}
82+
});
83+
}
84+
}
85+
exports.default = ScriptRunner;

0 commit comments

Comments
 (0)