Skip to content

Commit d8ee17c

Browse files
committed
prepare node24_test
1 parent 08df9dd commit d8ee17c

10 files changed

Lines changed: 874 additions & 0 deletions

lib/AzModuleInstaller.js

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

lib/InitializeAzure.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
36+
return (mod && mod.__esModule) ? mod : { "default": mod };
37+
};
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
const core = __importStar(require("@actions/core"));
40+
const Utils_1 = __importDefault(require("./Utilities/Utils"));
41+
const Constants_1 = __importDefault(require("./Constants"));
42+
class InitializeAzure {
43+
static async importAzModule(azPSVersion) {
44+
await Utils_1.default.setPSModulePath();
45+
if (azPSVersion === "latest") {
46+
azPSVersion = await Utils_1.default.getLatestModule(Constants_1.default.moduleName);
47+
}
48+
else {
49+
await Utils_1.default.checkModuleVersion(Constants_1.default.moduleName, azPSVersion);
50+
}
51+
core.debug(`Az Module version used: ${azPSVersion}`);
52+
await Utils_1.default.setPSModulePath(`${Constants_1.default.prefix}${azPSVersion}`);
53+
}
54+
}
55+
exports.default = InitializeAzure;

lib/ScriptRunner.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
36+
return (mod && mod.__esModule) ? mod : { "default": mod };
37+
};
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
const core = __importStar(require("@actions/core"));
40+
const FileUtils_1 = __importDefault(require("./Utilities/FileUtils"));
41+
const PowerShellToolRunner_1 = __importDefault(require("./Utilities/PowerShellToolRunner"));
42+
const ScriptBuilder_1 = __importDefault(require("./Utilities/ScriptBuilder"));
43+
class ScriptRunner {
44+
static filePath;
45+
inlineScript;
46+
errorActionPreference;
47+
failOnStandardErr;
48+
constructor(inlineScript, errorActionPreference, failOnStandardErr) {
49+
this.inlineScript = inlineScript;
50+
this.errorActionPreference = errorActionPreference;
51+
this.failOnStandardErr = failOnStandardErr;
52+
}
53+
async executeFile() {
54+
const error = [];
55+
const options = {
56+
listeners: {
57+
stderr: (data) => {
58+
if (error.length < 10) {
59+
// Truncate to at most 1000 bytes
60+
if (data.length > 1000) {
61+
error.push(`${data.toString('utf8', 0, 1000)}<truncated>`);
62+
}
63+
else {
64+
error.push(data.toString('utf8'));
65+
}
66+
}
67+
else if (error.length === 10) {
68+
error.push('Additional writes to stderr truncated');
69+
}
70+
}
71+
}
72+
};
73+
const scriptToExecute = new ScriptBuilder_1.default().getInlineScriptFile(this.inlineScript, this.errorActionPreference);
74+
ScriptRunner.filePath = await FileUtils_1.default.createScriptFile(scriptToExecute);
75+
core.debug(`script file to run: ${ScriptRunner.filePath}`);
76+
const exitCode = await PowerShellToolRunner_1.default.executePowerShellScriptBlock(ScriptRunner.filePath, options);
77+
if (exitCode !== 0) {
78+
core.setOutput(`Azure PowerShell exited with code:`, exitCode.toString());
79+
if (this.failOnStandardErr) {
80+
error.forEach((err) => {
81+
core.error(err);
82+
});
83+
throw new Error(`Standard error stream contains one or more lines`);
84+
}
85+
}
86+
}
87+
}
88+
exports.default = ScriptRunner;

lib/Utilities/ArchiveTools.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.ArchiveTools = void 0;
7+
const core_1 = require("@actions/core");
8+
const exec_1 = require("@actions/exec");
9+
const io_1 = require("@actions/io");
10+
const PowerShellToolRunner_1 = __importDefault(require("./PowerShellToolRunner"));
11+
class ArchiveTools {
12+
use7Zip;
13+
constructor(use7Zip = false) {
14+
this.use7Zip = use7Zip;
15+
}
16+
async unzip(zipPath, destination) {
17+
if (this.use7Zip) {
18+
await this.unzipUsing7Zip(zipPath, destination);
19+
}
20+
else {
21+
await this.unzipUsingPowerShell(zipPath, destination);
22+
}
23+
}
24+
async unzipUsing7Zip(zipPath, destination) {
25+
(0, core_1.debug)(`Using 7zip to extract ${zipPath} to ${destination}`);
26+
const path7Zip = await (0, io_1.which)("7z.exe", true);
27+
const exitCode = await (0, exec_1.exec)(`${path7Zip} x -o${destination} ${zipPath}`);
28+
if (exitCode != 0) {
29+
throw new Error(`Extraction using 7zip failed from ${zipPath} to ${destination}`);
30+
}
31+
}
32+
async unzipUsingPowerShell(zipPath, destination) {
33+
(0, core_1.debug)(`Using powershell Expand-Archive cmdlet to extract ${zipPath} to ${destination}`);
34+
const script = `
35+
$prevProgressPref = $ProgressPreference
36+
$ProgressPreference = 'SilentlyContinue'
37+
Expand-Archive -Path ${zipPath} -DestinationPath ${destination}
38+
$ProgressPreference = $prevProgressPref`;
39+
const exitCode = await PowerShellToolRunner_1.default.executePowerShellScriptBlock(script);
40+
if (exitCode != 0) {
41+
throw new Error(`Extraction using Expand-Archive cmdlet failed from ${zipPath} to ${destination}`);
42+
}
43+
}
44+
}
45+
exports.ArchiveTools = ArchiveTools;

0 commit comments

Comments
 (0)