Skip to content

Commit 8105447

Browse files
committed
prepare node24_test
1 parent 305b704 commit 8105447

10 files changed

Lines changed: 984 additions & 0 deletions

lib/AzModuleInstaller.js

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

lib/InitializeAzure.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 () {
19+
var ownKeys = function(o) {
20+
ownKeys = Object.getOwnPropertyNames || function (o) {
21+
var ar = [];
22+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23+
return ar;
24+
};
25+
return ownKeys(o);
26+
};
27+
return function (mod) {
28+
if (mod && mod.__esModule) return mod;
29+
var result = {};
30+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31+
__setModuleDefault(result, mod);
32+
return result;
33+
};
34+
})();
35+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37+
return new (P || (P = Promise))(function (resolve, reject) {
38+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41+
step((generator = generator.apply(thisArg, _arguments || [])).next());
42+
});
43+
};
44+
var __importDefault = (this && this.__importDefault) || function (mod) {
45+
return (mod && mod.__esModule) ? mod : { "default": mod };
46+
};
47+
Object.defineProperty(exports, "__esModule", { value: true });
48+
const core = __importStar(require("@actions/core"));
49+
const Utils_1 = __importDefault(require("./Utilities/Utils"));
50+
const Constants_1 = __importDefault(require("./Constants"));
51+
class InitializeAzure {
52+
static importAzModule(azPSVersion) {
53+
return __awaiter(this, void 0, void 0, function* () {
54+
yield Utils_1.default.setPSModulePath();
55+
if (azPSVersion === "latest") {
56+
azPSVersion = yield Utils_1.default.getLatestModule(Constants_1.default.moduleName);
57+
}
58+
else {
59+
yield Utils_1.default.checkModuleVersion(Constants_1.default.moduleName, azPSVersion);
60+
}
61+
core.debug(`Az Module version used: ${azPSVersion}`);
62+
yield Utils_1.default.setPSModulePath(`${Constants_1.default.prefix}${azPSVersion}`);
63+
});
64+
}
65+
}
66+
exports.default = InitializeAzure;

lib/ScriptRunner.js

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

0 commit comments

Comments
 (0)