mirror of
https://github.com/github/codeql-action.git
synced 2025-12-06 07:48:17 +08:00
Compare commits
1 Commits
f0ac9bfbe3
...
NlightNFot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58a59d31f6 |
112
lib/system-reqs.js
generated
Normal file
112
lib/system-reqs.js
generated
Normal file
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
// Enforce system requirements for the CodeQL CLI.
|
||||
// https://codeql.github.com/docs/codeql-overview/system-requirements/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.passesSystemRequirements = passesSystemRequirements;
|
||||
const macos_version_1 = require("macos-version");
|
||||
const util_1 = require("./util");
|
||||
const fs_1 = require("fs");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const platformMap = {
|
||||
'darwin': 'macOS',
|
||||
'linux': 'Linux',
|
||||
'win32': 'Windows',
|
||||
};
|
||||
const platformRequirements = {
|
||||
'macOS': {
|
||||
'version': ['13.0.1', '14.0.1'],
|
||||
'arch': ['arm64', 'x64'],
|
||||
},
|
||||
'Linux': {
|
||||
// We only accept Ubuntu 20.04, 21.04, and 22.04
|
||||
'version': ['20.04', '21.04', '22.04'],
|
||||
'arch': ['x64'],
|
||||
},
|
||||
'Windows': {
|
||||
'version': ['10', 'Server 2019', '11', 'Server 2022'],
|
||||
'arch': ['x64'],
|
||||
},
|
||||
};
|
||||
function passesSystemRequirements() {
|
||||
// CodeQL System requirements are two-level: the CLI must run on a specific platform,
|
||||
// and that platform must have certain capabilities.
|
||||
const platform = getPlatform();
|
||||
switch (platform) {
|
||||
case 'macOS':
|
||||
return checkMacOSPlatform();
|
||||
case 'Linux':
|
||||
return checkLinuxPlatform();
|
||||
case 'Windows':
|
||||
return checkWindowsPlatform();
|
||||
default:
|
||||
(0, util_1.assertNever)(platform);
|
||||
}
|
||||
}
|
||||
// MacOS checks
|
||||
function checkMacOSPlatform() {
|
||||
const macOSPlatformRequirements = platformRequirements['macOS'];
|
||||
const passesSystemRequirements = checkMacOSVersion(macOSPlatformRequirements['version']) && checkMacOSArch(macOSPlatformRequirements['arch']);
|
||||
return passesSystemRequirements;
|
||||
}
|
||||
function checkMacOSVersion(supportedVersions) {
|
||||
return supportedVersions.some((version) => {
|
||||
(0, macos_version_1.isMacOSVersionGreaterThanOrEqualTo)(version);
|
||||
});
|
||||
}
|
||||
function checkMacOSArch(supportedArchs) {
|
||||
const arch = getArch();
|
||||
return supportedArchs.includes(arch);
|
||||
}
|
||||
// Linux checks
|
||||
function checkLinuxPlatform() {
|
||||
const linuxPlatformRequirements = platformRequirements['Linux'];
|
||||
return checkLinuxVersion(linuxPlatformRequirements['version']) && checkLinuxArch(linuxPlatformRequirements['arch']);
|
||||
}
|
||||
function checkLinuxVersion(supportedVersions) {
|
||||
const data = (0, fs_1.readFileSync)('/etc/os-release', 'utf8');
|
||||
const lines = data.split('\n');
|
||||
const releaseDetails = {};
|
||||
lines.forEach((line) => {
|
||||
// Split the line into a key and value delimited by '='
|
||||
const words = line.split('=');
|
||||
if (words.length === 2) {
|
||||
releaseDetails[words[0].trim().toLowerCase()] = words[1].trim();
|
||||
}
|
||||
});
|
||||
return releaseDetails.name == 'Ubuntu' && supportedVersions.includes(releaseDetails.version_id);
|
||||
}
|
||||
function checkLinuxArch(supportedArchs) {
|
||||
const arch = getArch();
|
||||
return supportedArchs.includes(arch);
|
||||
}
|
||||
// Windows checks
|
||||
function checkWindowsPlatform() {
|
||||
const windowsPlatformRequirements = platformRequirements['Windows'];
|
||||
return checkWindowsVersion(windowsPlatformRequirements['version']) && checkWindowsArch(windowsPlatformRequirements['arch']);
|
||||
}
|
||||
function checkWindowsVersion(supportedVersions) {
|
||||
// os.release() on windows returns a string like "Windows 11 Home"
|
||||
const windowsVersion = os_1.default.release();
|
||||
return supportedVersions.some(version => new RegExp(version, 'i').test(windowsVersion));
|
||||
}
|
||||
function checkWindowsArch(supportedArchs) {
|
||||
const arch = getArch();
|
||||
return supportedArchs.includes(arch);
|
||||
}
|
||||
;
|
||||
// Auxiliary functions
|
||||
function getPlatform() {
|
||||
const platform = process.platform;
|
||||
const mappedPlatform = platformMap[platform];
|
||||
if (mappedPlatform === undefined) {
|
||||
throw new util_1.ConfigurationError(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
return mappedPlatform;
|
||||
}
|
||||
function getArch() {
|
||||
return process.arch;
|
||||
}
|
||||
//# sourceMappingURL=system-reqs.js.map
|
||||
1
lib/system-reqs.js.map
Normal file
1
lib/system-reqs.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"system-reqs.js","sourceRoot":"","sources":["../src/system-reqs.ts"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,sEAAsE;;;;;AA6BtE,4DAgBC;AA3CD,iDAAmE;AACnE,iCAAyD;AACzD,2BAAkC;AAClC,4CAAoB;AAEpB,MAAM,WAAW,GAAG;IAChB,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,SAAS;CACrB,CAAA;AAED,MAAM,oBAAoB,GAAG;IACzB,OAAO,EAAE;QACL,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC/B,MAAM,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC;KAC3B;IACD,OAAO,EAAE;QACL,gDAAgD;QAChD,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;QACtC,MAAM,EAAE,CAAC,KAAK,CAAC;KAClB;IACD,SAAS,EAAE;QACP,SAAS,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,CAAC;QACrD,MAAM,EAAE,CAAC,KAAK,CAAC;KAClB;CACJ,CAAC;AAEF,SAAgB,wBAAwB;IACtC,qFAAqF;IACrF,oDAAoD;IAEpD,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,QAAQ,QAAQ,EAA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,IAAI,CAAC,CAAC;AACzC,CAAC;AAAA,CAAC;AAEF,sBAAsB;AAEtB,SAAS,WAAW;IAChB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,cAAc,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,yBAAkB,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED,SAAS,OAAO;IACZ,OAAO,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC"}
|
||||
14
node_modules/.package-lock.json
generated
vendored
14
node_modules/.package-lock.json
generated
vendored
@@ -6010,6 +6010,20 @@
|
||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/macos-version": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/macos-version/-/macos-version-6.0.0.tgz",
|
||||
"integrity": "sha512-O2S8voA+pMfCHhBn/TIYDXzJ1qNHpPDU32oFxglKnVdJABiYYITt45oLkV9yhwA3E2FDwn3tQqUFrTsr1p3sBQ==",
|
||||
"dependencies": {
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/map-age-cleaner": {
|
||||
"version": "0.1.3",
|
||||
"dev": true,
|
||||
|
||||
15
package-lock.json
generated
15
package-lock.json
generated
@@ -36,6 +36,7 @@
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonschema": "1.4.1",
|
||||
"long": "^5.3.1",
|
||||
"macos-version": "^6.0.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"octokit": "^4.1.2",
|
||||
"path": "^0.12.7",
|
||||
@@ -6078,6 +6079,20 @@
|
||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/macos-version": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/macos-version/-/macos-version-6.0.0.tgz",
|
||||
"integrity": "sha512-O2S8voA+pMfCHhBn/TIYDXzJ1qNHpPDU32oFxglKnVdJABiYYITt45oLkV9yhwA3E2FDwn3tQqUFrTsr1p3sBQ==",
|
||||
"dependencies": {
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/map-age-cleaner": {
|
||||
"version": "0.1.3",
|
||||
"dev": true,
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonschema": "1.4.1",
|
||||
"long": "^5.3.1",
|
||||
"macos-version": "^6.0.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"octokit": "^4.1.2",
|
||||
"path": "^0.12.7",
|
||||
|
||||
139
src/system-reqs.ts
Normal file
139
src/system-reqs.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
// Enforce system requirements for the CodeQL CLI.
|
||||
// https://codeql.github.com/docs/codeql-overview/system-requirements/
|
||||
|
||||
import { readFileSync } from "fs";
|
||||
import os from "os";
|
||||
|
||||
import { isMacOSVersionGreaterThanOrEqualTo } from "macos-version";
|
||||
|
||||
import { assertNever, ConfigurationError } from "./util";
|
||||
|
||||
const platformMap = {
|
||||
darwin: "macOS",
|
||||
linux: "Linux",
|
||||
win32: "Windows",
|
||||
};
|
||||
|
||||
const platformRequirements = {
|
||||
macOS: {
|
||||
version: ["13.0.1", "14.0.1"],
|
||||
arch: ["arm64", "x64"],
|
||||
},
|
||||
Linux: {
|
||||
// We only accept Ubuntu 20.04, 21.04, and 22.04
|
||||
version: ["20.04", "21.04", "22.04"],
|
||||
arch: ["x64"],
|
||||
},
|
||||
Windows: {
|
||||
version: ["10", "Server 2019", "11", "Server 2022"],
|
||||
arch: ["x64"],
|
||||
},
|
||||
};
|
||||
|
||||
export function passesSystemRequirements(): boolean {
|
||||
// CodeQL System requirements are two-level: the CLI must run on a specific platform,
|
||||
// and that platform must have certain capabilities.
|
||||
|
||||
const platform = getPlatform();
|
||||
switch (platform) {
|
||||
case "macOS":
|
||||
return checkMacOSPlatform();
|
||||
case "Linux":
|
||||
return checkLinuxPlatform();
|
||||
case "Windows":
|
||||
return checkWindowsPlatform();
|
||||
default:
|
||||
assertNever(platform);
|
||||
}
|
||||
}
|
||||
|
||||
// MacOS checks
|
||||
|
||||
function checkMacOSPlatform(): boolean {
|
||||
const macOSPlatformRequirements = platformRequirements["macOS"];
|
||||
return (
|
||||
checkMacOSVersion(macOSPlatformRequirements["version"]) &&
|
||||
checkMacOSArch(macOSPlatformRequirements["arch"])
|
||||
);
|
||||
}
|
||||
|
||||
function checkMacOSVersion(supportedVersions: string[]): boolean {
|
||||
return supportedVersions.some((version) => {
|
||||
return isMacOSVersionGreaterThanOrEqualTo(version);
|
||||
});
|
||||
}
|
||||
|
||||
function checkMacOSArch(supportedArchs: string[]): boolean {
|
||||
const arch = getArch();
|
||||
return supportedArchs.includes(arch);
|
||||
}
|
||||
|
||||
// Linux checks
|
||||
|
||||
function checkLinuxPlatform(): boolean {
|
||||
const linuxPlatformRequirements = platformRequirements["Linux"];
|
||||
return (
|
||||
checkLinuxVersion(linuxPlatformRequirements["version"]) &&
|
||||
checkLinuxArch(linuxPlatformRequirements["arch"])
|
||||
);
|
||||
}
|
||||
|
||||
function checkLinuxVersion(supportedVersions: string[]): boolean {
|
||||
const data = readFileSync("/etc/os-release", "utf8");
|
||||
const lines = data.split("\n");
|
||||
const releaseDetails: Record<string, string> = {};
|
||||
for (const line of lines) {
|
||||
const words = line.split("=");
|
||||
if (words.length === 2) {
|
||||
releaseDetails[words[0].trim().toLowerCase()] = words[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
releaseDetails.name === "Ubuntu" &&
|
||||
supportedVersions.includes(releaseDetails.version_id)
|
||||
);
|
||||
}
|
||||
|
||||
function checkLinuxArch(supportedArchs: string[]): boolean {
|
||||
const arch = getArch();
|
||||
return supportedArchs.includes(arch);
|
||||
}
|
||||
|
||||
// Windows checks
|
||||
|
||||
function checkWindowsPlatform(): boolean {
|
||||
const windowsPlatformRequirements = platformRequirements["Windows"];
|
||||
return (
|
||||
checkWindowsVersion(windowsPlatformRequirements["version"]) &&
|
||||
checkWindowsArch(windowsPlatformRequirements["arch"])
|
||||
);
|
||||
}
|
||||
|
||||
function checkWindowsVersion(supportedVersions: string[]): boolean {
|
||||
// os.release() on windows returns a string like "Windows 11 Home"
|
||||
const windowsVersion = os.release();
|
||||
return supportedVersions.some((version) =>
|
||||
new RegExp(version, "i").test(windowsVersion),
|
||||
);
|
||||
}
|
||||
|
||||
function checkWindowsArch(supportedArchs: string[]): boolean {
|
||||
const arch = getArch();
|
||||
return supportedArchs.includes(arch);
|
||||
}
|
||||
|
||||
// Auxiliary functions
|
||||
|
||||
function getPlatform(): "macOS" | "Linux" | "Windows" {
|
||||
const platform = process.platform;
|
||||
const mappedPlatform = platformMap[platform];
|
||||
if (mappedPlatform === undefined) {
|
||||
throw new ConfigurationError(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
return mappedPlatform;
|
||||
}
|
||||
|
||||
function getArch(): string {
|
||||
return process.arch;
|
||||
}
|
||||
Reference in New Issue
Block a user