mirror of
https://github.com/github/codeql-action.git
synced 2025-12-31 19:50:32 +08:00
Merge branch 'main' into henrymercer/prefer-fs-delete
This commit is contained in:
@@ -534,3 +534,12 @@ test("getCgroupCpuCountFromCpus returns undefined if the CPU file exists but is
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("checkDiskUsage succeeds and produces positive numbers", async (t) => {
|
||||
process.env["GITHUB_WORKSPACE"] = os.tmpdir();
|
||||
const diskUsage = await util.checkDiskUsage(getRunnerLogger(true));
|
||||
if (t.truthy(diskUsage)) {
|
||||
t.true(diskUsage.numAvailableBytes > 0);
|
||||
t.true(diskUsage.numTotalBytes > 0);
|
||||
}
|
||||
});
|
||||
|
||||
27
src/util.ts
27
src/util.ts
@@ -1,11 +1,11 @@
|
||||
import * as fs from "fs";
|
||||
import * as fsPromises from "fs/promises";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec/lib/exec";
|
||||
import * as io from "@actions/io";
|
||||
import checkDiskSpace from "check-disk-space";
|
||||
import getFolderSize from "get-folder-size";
|
||||
import * as yaml from "js-yaml";
|
||||
import * as semver from "semver";
|
||||
@@ -1098,24 +1098,17 @@ export async function checkDiskUsage(
|
||||
logger: Logger,
|
||||
): Promise<DiskUsage | undefined> {
|
||||
try {
|
||||
// We avoid running the `df` binary under the hood for macOS ARM runners with SIP disabled.
|
||||
if (
|
||||
process.platform === "darwin" &&
|
||||
(process.arch === "arm" || process.arch === "arm64") &&
|
||||
!(await checkSipEnablement(logger))
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const diskUsage = await checkDiskSpace(
|
||||
const diskUsage = await fsPromises.statfs(
|
||||
getRequiredEnvParam("GITHUB_WORKSPACE"),
|
||||
);
|
||||
const mbInBytes = 1024 * 1024;
|
||||
const gbInBytes = 1024 * 1024 * 1024;
|
||||
if (diskUsage.free < 2 * gbInBytes) {
|
||||
|
||||
const blockSizeInBytes = diskUsage.bsize;
|
||||
const numBlocksPerMb = (1024 * 1024) / blockSizeInBytes;
|
||||
const numBlocksPerGb = (1024 * 1024 * 1024) / blockSizeInBytes;
|
||||
if (diskUsage.bavail < 2 * numBlocksPerGb) {
|
||||
const message =
|
||||
"The Actions runner is running low on disk space " +
|
||||
`(${(diskUsage.free / mbInBytes).toPrecision(4)} MB available).`;
|
||||
`(${(diskUsage.bavail / numBlocksPerMb).toPrecision(4)} MB available).`;
|
||||
if (process.env[EnvVar.HAS_WARNED_ABOUT_DISK_SPACE] !== "true") {
|
||||
logger.warning(message);
|
||||
} else {
|
||||
@@ -1124,8 +1117,8 @@ export async function checkDiskUsage(
|
||||
core.exportVariable(EnvVar.HAS_WARNED_ABOUT_DISK_SPACE, "true");
|
||||
}
|
||||
return {
|
||||
numAvailableBytes: diskUsage.free,
|
||||
numTotalBytes: diskUsage.size,
|
||||
numAvailableBytes: diskUsage.bavail * blockSizeInBytes,
|
||||
numTotalBytes: diskUsage.blocks * blockSizeInBytes,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.warning(
|
||||
|
||||
Reference in New Issue
Block a user