Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add module for checking basic system requirements#2835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
NlightNFotis wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromNlightNFotis/enforce_system_reqs
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletionslib/system-reqs.js
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionslib/system-reqs.js.map
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

14 changes: 14 additions & 0 deletionsnode_modules/.package-lock.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

15 changes: 15 additions & 0 deletionspackage-lock.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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",
Expand Down
139 changes: 139 additions & 0 deletionssrc/system-reqs.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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;
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp