mirror of
https://github.com/actions/setup-go.git
synced 2026-05-06 03:34:24 +00:00
perf: log cache directory sizes for visibility
Log GOMODCACHE and GOCACHE sizes (in human-readable format) after restore and before save. This helps diagnose cache bloat and monitor the impact of cache-build settings. https://claude.ai/code/session_01CqrWSjzGgd7Zi6LyJkd9XW
This commit is contained in:
parent
cf0b11600c
commit
867e185dcc
5 changed files with 141 additions and 4 deletions
46
dist/cache-save/index.js
vendored
46
dist/cache-save/index.js
vendored
|
|
@ -102605,6 +102605,7 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey} and build hash ${buildHash}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey} and build hash ${buildHash}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
(0, cache_utils_1.logCacheSizes)(cachePaths);
|
||||||
const updatedKey = primaryKey + (buildHash ? `-${buildHash}` : '');
|
const updatedKey = primaryKey + (buildHash ? `-${buildHash}` : '');
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const cacheId = yield cache.saveCache(cachePaths, updatedKey);
|
const cacheId = yield cache.saveCache(cachePaths, updatedKey);
|
||||||
|
|
@ -102660,11 +102661,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
exports.isCacheFeatureAvailable = exports.isGhes = exports.logCacheSizes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
||||||
const cache = __importStar(__nccwpck_require__(27799));
|
const cache = __importStar(__nccwpck_require__(27799));
|
||||||
const core = __importStar(__nccwpck_require__(42186));
|
const core = __importStar(__nccwpck_require__(42186));
|
||||||
const exec = __importStar(__nccwpck_require__(71514));
|
const exec = __importStar(__nccwpck_require__(71514));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(57147));
|
||||||
|
const path_1 = __importDefault(__nccwpck_require__(71017));
|
||||||
const package_managers_1 = __nccwpck_require__(96663);
|
const package_managers_1 = __nccwpck_require__(96663);
|
||||||
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
|
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
|
||||||
|
|
@ -102706,6 +102712,44 @@ const getCacheDirectoryPath = (packageManagerInfo_1, ...args_1) => __awaiter(voi
|
||||||
return cachePaths;
|
return cachePaths;
|
||||||
});
|
});
|
||||||
exports.getCacheDirectoryPath = getCacheDirectoryPath;
|
exports.getCacheDirectoryPath = getCacheDirectoryPath;
|
||||||
|
function getDirSizeBytes(dirPath) {
|
||||||
|
if (!fs_1.default.existsSync(dirPath))
|
||||||
|
return 0;
|
||||||
|
const stat = fs_1.default.statSync(dirPath);
|
||||||
|
if (!stat.isDirectory())
|
||||||
|
return stat.size;
|
||||||
|
let total = 0;
|
||||||
|
for (const entry of fs_1.default.readdirSync(dirPath, { withFileTypes: true })) {
|
||||||
|
const entryPath = path_1.default.join(dirPath, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
total += getDirSizeBytes(entryPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
total += fs_1.default.statSync(entryPath).size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
function formatSize(bytes) {
|
||||||
|
if (bytes < 1024)
|
||||||
|
return `${bytes} B`;
|
||||||
|
if (bytes < 1024 * 1024)
|
||||||
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
if (bytes < 1024 * 1024 * 1024)
|
||||||
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||||
|
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
||||||
|
}
|
||||||
|
function logCacheSizes(cachePaths) {
|
||||||
|
const labels = ['GOMODCACHE', 'GOCACHE'];
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < cachePaths.length; i++) {
|
||||||
|
const size = getDirSizeBytes(cachePaths[i]);
|
||||||
|
total += size;
|
||||||
|
core.info(`Cache size ${labels[i] || cachePaths[i]}: ${formatSize(size)}`);
|
||||||
|
}
|
||||||
|
core.info(`Cache size total: ${formatSize(total)}`);
|
||||||
|
}
|
||||||
|
exports.logCacheSizes = logCacheSizes;
|
||||||
function isGhes() {
|
function isGhes() {
|
||||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||||
|
|
|
||||||
46
dist/setup/index.js
vendored
46
dist/setup/index.js
vendored
|
|
@ -107854,6 +107854,7 @@ const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awa
|
||||||
}
|
}
|
||||||
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
|
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
core.info(`Cache restored from key: ${cacheKey}`);
|
||||||
|
(0, cache_utils_1.logCacheSizes)(cachePaths);
|
||||||
if (cachePaths.length > 1) {
|
if (cachePaths.length > 1) {
|
||||||
const buildHash = (0, hashdir_1.computeMetaHash)([cachePaths[1]]);
|
const buildHash = (0, hashdir_1.computeMetaHash)([cachePaths[1]]);
|
||||||
core.debug(`build hash is ${buildHash}`);
|
core.debug(`build hash is ${buildHash}`);
|
||||||
|
|
@ -107912,11 +107913,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
exports.isCacheFeatureAvailable = exports.isGhes = exports.logCacheSizes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
||||||
const cache = __importStar(__nccwpck_require__(27799));
|
const cache = __importStar(__nccwpck_require__(27799));
|
||||||
const core = __importStar(__nccwpck_require__(42186));
|
const core = __importStar(__nccwpck_require__(42186));
|
||||||
const exec = __importStar(__nccwpck_require__(71514));
|
const exec = __importStar(__nccwpck_require__(71514));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(57147));
|
||||||
|
const path_1 = __importDefault(__nccwpck_require__(71017));
|
||||||
const package_managers_1 = __nccwpck_require__(96663);
|
const package_managers_1 = __nccwpck_require__(96663);
|
||||||
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
|
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
|
||||||
|
|
@ -107958,6 +107964,44 @@ const getCacheDirectoryPath = (packageManagerInfo_1, ...args_1) => __awaiter(voi
|
||||||
return cachePaths;
|
return cachePaths;
|
||||||
});
|
});
|
||||||
exports.getCacheDirectoryPath = getCacheDirectoryPath;
|
exports.getCacheDirectoryPath = getCacheDirectoryPath;
|
||||||
|
function getDirSizeBytes(dirPath) {
|
||||||
|
if (!fs_1.default.existsSync(dirPath))
|
||||||
|
return 0;
|
||||||
|
const stat = fs_1.default.statSync(dirPath);
|
||||||
|
if (!stat.isDirectory())
|
||||||
|
return stat.size;
|
||||||
|
let total = 0;
|
||||||
|
for (const entry of fs_1.default.readdirSync(dirPath, { withFileTypes: true })) {
|
||||||
|
const entryPath = path_1.default.join(dirPath, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
total += getDirSizeBytes(entryPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
total += fs_1.default.statSync(entryPath).size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
function formatSize(bytes) {
|
||||||
|
if (bytes < 1024)
|
||||||
|
return `${bytes} B`;
|
||||||
|
if (bytes < 1024 * 1024)
|
||||||
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
if (bytes < 1024 * 1024 * 1024)
|
||||||
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||||
|
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
||||||
|
}
|
||||||
|
function logCacheSizes(cachePaths) {
|
||||||
|
const labels = ['GOMODCACHE', 'GOCACHE'];
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < cachePaths.length; i++) {
|
||||||
|
const size = getDirSizeBytes(cachePaths[i]);
|
||||||
|
total += size;
|
||||||
|
core.info(`Cache size ${labels[i] || cachePaths[i]}: ${formatSize(size)}`);
|
||||||
|
}
|
||||||
|
core.info(`Cache size total: ${formatSize(total)}`);
|
||||||
|
}
|
||||||
|
exports.logCacheSizes = logCacheSizes;
|
||||||
function isGhes() {
|
function isGhes() {
|
||||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,11 @@ import fs from 'fs';
|
||||||
|
|
||||||
import {State, Outputs} from './constants';
|
import {State, Outputs} from './constants';
|
||||||
import {PackageManagerInfo} from './package-managers';
|
import {PackageManagerInfo} from './package-managers';
|
||||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
import {
|
||||||
|
getCacheDirectoryPath,
|
||||||
|
getPackageManagerInfo,
|
||||||
|
logCacheSizes
|
||||||
|
} from './cache-utils';
|
||||||
import {computeMetaHash} from './hashdir';
|
import {computeMetaHash} from './hashdir';
|
||||||
|
|
||||||
export const restoreCache = async (
|
export const restoreCache = async (
|
||||||
|
|
@ -67,6 +71,7 @@ export const restoreCache = async (
|
||||||
|
|
||||||
core.saveState(State.CacheMatchedKey, cacheKey);
|
core.saveState(State.CacheMatchedKey, cacheKey);
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
core.info(`Cache restored from key: ${cacheKey}`);
|
||||||
|
logCacheSizes(cachePaths);
|
||||||
|
|
||||||
if (cachePaths.length > 1) {
|
if (cachePaths.length > 1) {
|
||||||
const buildHash = computeMetaHash([cachePaths[1]]);
|
const buildHash = computeMetaHash([cachePaths[1]]);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@ import * as core from '@actions/core';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
import {
|
||||||
|
getCacheDirectoryPath,
|
||||||
|
getPackageManagerInfo,
|
||||||
|
logCacheSizes
|
||||||
|
} from './cache-utils';
|
||||||
import {computeMetaHash} from './hashdir';
|
import {computeMetaHash} from './hashdir';
|
||||||
|
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
|
|
@ -87,6 +91,8 @@ const cachePackages = async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logCacheSizes(cachePaths);
|
||||||
|
|
||||||
const updatedKey = primaryKey + (buildHash ? `-${buildHash}` : '');
|
const updatedKey = primaryKey + (buildHash ? `-${buildHash}` : '');
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const cacheId = await cache.saveCache(cachePaths, updatedKey);
|
const cacheId = await cache.saveCache(cachePaths, updatedKey);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
||||||
|
|
||||||
export const getCommandOutput = async (toolCommand: string) => {
|
export const getCommandOutput = async (toolCommand: string) => {
|
||||||
|
|
@ -62,6 +64,42 @@ export const getCacheDirectoryPath = async (
|
||||||
return cachePaths;
|
return cachePaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getDirSizeBytes(dirPath: string): number {
|
||||||
|
if (!fs.existsSync(dirPath)) return 0;
|
||||||
|
const stat = fs.statSync(dirPath);
|
||||||
|
if (!stat.isDirectory()) return stat.size;
|
||||||
|
|
||||||
|
let total = 0;
|
||||||
|
for (const entry of fs.readdirSync(dirPath, {withFileTypes: true})) {
|
||||||
|
const entryPath = path.join(dirPath, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
total += getDirSizeBytes(entryPath);
|
||||||
|
} else {
|
||||||
|
total += fs.statSync(entryPath).size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSize(bytes: number): string {
|
||||||
|
if (bytes < 1024) return `${bytes} B`;
|
||||||
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
if (bytes < 1024 * 1024 * 1024)
|
||||||
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||||
|
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function logCacheSizes(cachePaths: string[]): void {
|
||||||
|
const labels = ['GOMODCACHE', 'GOCACHE'];
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < cachePaths.length; i++) {
|
||||||
|
const size = getDirSizeBytes(cachePaths[i]);
|
||||||
|
total += size;
|
||||||
|
core.info(`Cache size ${labels[i] || cachePaths[i]}: ${formatSize(size)}`);
|
||||||
|
}
|
||||||
|
core.info(`Cache size total: ${formatSize(total)}`);
|
||||||
|
}
|
||||||
|
|
||||||
export function isGhes(): boolean {
|
export function isGhes(): boolean {
|
||||||
const ghUrl = new URL(
|
const ghUrl = new URL(
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue