Merge pull request #1298 from github/edoardo/caching-hosted
TRAP Caching: Disable on self-hosted runners
This commit is contained in:
commit
0c7f674831
6 changed files with 61 additions and 7 deletions
8
lib/init-action.js
generated
8
lib/init-action.js
generated
|
|
@ -159,10 +159,14 @@ async function run() {
|
|||
await sendSuccessStatusReport(startedAt, config, toolsVersion, logger);
|
||||
}
|
||||
async function getTrapCachingEnabled(featureEnablement) {
|
||||
// If the workflow specified something always respect that
|
||||
const trapCaching = (0, actions_util_1.getOptionalInput)("trap-caching");
|
||||
if (trapCaching !== undefined) {
|
||||
if (trapCaching !== undefined)
|
||||
return trapCaching === "true";
|
||||
}
|
||||
// On self-hosted runners which may have slow network access, disable TRAP caching by default
|
||||
if (!(0, util_1.isHostedRunner)())
|
||||
return false;
|
||||
// On hosted runners, respect the feature flag
|
||||
return await featureEnablement.getValue(feature_flags_1.Feature.TrapCachingEnabled);
|
||||
}
|
||||
async function runWrapper() {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
24
lib/util.js
generated
24
lib/util.js
generated
|
|
@ -23,6 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.withTimeout = exports.tryGetFolderBytes = exports.isGoExtractionReconciliationEnabled = exports.listFolder = exports.doesDirectoryExist = exports.logCodeScanningConfigInCli = exports.useCodeScanningConfigInCli = exports.isInTestMode = exports.checkActionVersion = exports.getMlPoweredJsQueriesStatus = exports.getMlPoweredJsQueriesPack = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isGitHubGhesVersionBelow = exports.isHTTPError = exports.UserError = exports.HTTPError = exports.getRequiredEnvParam = exports.isActions = exports.getMode = exports.enrichEnvironment = exports.initializeEnvironment = exports.EnvVar = exports.Mode = exports.assertNever = exports.getGitHubAuth = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DID_AUTOBUILD_GO_ENV_VAR_NAME = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
|
||||
exports.isHostedRunner = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
|
|
@ -751,4 +752,27 @@ async function withTimeout(timeoutMs, promise, onTimeout) {
|
|||
return await Promise.race([mainTask(), timeout]);
|
||||
}
|
||||
exports.withTimeout = withTimeout;
|
||||
/**
|
||||
* This function implements a heuristic to determine whether the
|
||||
* runner we are on is hosted by GitHub. It does this by checking
|
||||
* the name of the runner against the list of known GitHub-hosted
|
||||
* runner names. It also checks for the presence of a toolcache
|
||||
* directory with the name hostedtoolcache which is present on
|
||||
* GitHub-hosted runners.
|
||||
*
|
||||
* @returns true iff the runner is hosted by GitHub
|
||||
*/
|
||||
function isHostedRunner() {
|
||||
var _a, _b, _c;
|
||||
return (
|
||||
// Name of the runner on hosted Windows runners
|
||||
((_a = process.env["RUNNER_NAME"]) === null || _a === void 0 ? void 0 : _a.includes("Hosted Agent")) ||
|
||||
(
|
||||
// Name of the runner on hosted POSIX runners
|
||||
(_b = process.env["RUNNER_NAME"]) === null || _b === void 0 ? void 0 : _b.includes("GitHub Actions")) ||
|
||||
(
|
||||
// Segment of the path to the tool cache on all hosted runners
|
||||
(_c = process.env["RUNNER_TOOL_CACHE"]) === null || _c === void 0 ? void 0 : _c.includes("hostedtoolcache")));
|
||||
}
|
||||
exports.isHostedRunner = isHostedRunner;
|
||||
//# sourceMappingURL=util.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -39,6 +39,7 @@ import {
|
|||
getRequiredEnvParam,
|
||||
getThreadsFlagValue,
|
||||
initializeEnvironment,
|
||||
isHostedRunner,
|
||||
Mode,
|
||||
} from "./util";
|
||||
|
||||
|
|
@ -320,10 +321,14 @@ async function run() {
|
|||
async function getTrapCachingEnabled(
|
||||
featureEnablement: FeatureEnablement
|
||||
): Promise<boolean> {
|
||||
// If the workflow specified something always respect that
|
||||
const trapCaching = getOptionalInput("trap-caching");
|
||||
if (trapCaching !== undefined) {
|
||||
return trapCaching === "true";
|
||||
}
|
||||
if (trapCaching !== undefined) return trapCaching === "true";
|
||||
|
||||
// On self-hosted runners which may have slow network access, disable TRAP caching by default
|
||||
if (!isHostedRunner()) return false;
|
||||
|
||||
// On hosted runners, respect the feature flag
|
||||
return await featureEnablement.getValue(Feature.TrapCachingEnabled);
|
||||
}
|
||||
|
||||
|
|
|
|||
21
src/util.ts
21
src/util.ts
|
|
@ -892,3 +892,24 @@ export async function withTimeout<T>(
|
|||
|
||||
return await Promise.race([mainTask(), timeout]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function implements a heuristic to determine whether the
|
||||
* runner we are on is hosted by GitHub. It does this by checking
|
||||
* the name of the runner against the list of known GitHub-hosted
|
||||
* runner names. It also checks for the presence of a toolcache
|
||||
* directory with the name hostedtoolcache which is present on
|
||||
* GitHub-hosted runners.
|
||||
*
|
||||
* @returns true iff the runner is hosted by GitHub
|
||||
*/
|
||||
export function isHostedRunner() {
|
||||
return (
|
||||
// Name of the runner on hosted Windows runners
|
||||
process.env["RUNNER_NAME"]?.includes("Hosted Agent") ||
|
||||
// Name of the runner on hosted POSIX runners
|
||||
process.env["RUNNER_NAME"]?.includes("GitHub Actions") ||
|
||||
// Segment of the path to the tool cache on all hosted runners
|
||||
process.env["RUNNER_TOOL_CACHE"]?.includes("hostedtoolcache")
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue