mirror of
https://github.com/github/codeql-action.git
synced 2026-11-06 21:19:42 +00:00
Propagate checkoutPath to getRef
This commit is contained in:
90
lib/entry-points.js
generated
90
lib/entry-points.js
generated
@@ -142187,6 +142187,12 @@ var Env = class extends ReadOnlyEnv {
|
||||
this.vars[name] = value;
|
||||
this.changed = true;
|
||||
}
|
||||
/** Sets all environment variables given by `vars`. */
|
||||
setAll(vars) {
|
||||
for (const [key, val] of Object.entries(vars)) {
|
||||
this.set(key, val);
|
||||
}
|
||||
}
|
||||
/** Gets a value indicating whether `set` was called at least once. */
|
||||
hasChanged() {
|
||||
return this.changed;
|
||||
@@ -147019,7 +147025,7 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage, o
|
||||
throw error3;
|
||||
}
|
||||
};
|
||||
var getCommitOid = async function(checkoutPath, ref = "HEAD") {
|
||||
var getCommitOid = async function(env, checkoutPath, ref = "HEAD") {
|
||||
try {
|
||||
const stdout = await runGitCommand(
|
||||
checkoutPath,
|
||||
@@ -147028,7 +147034,7 @@ var getCommitOid = async function(checkoutPath, ref = "HEAD") {
|
||||
);
|
||||
return stdout.trim();
|
||||
} catch {
|
||||
return getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA");
|
||||
return getOptionalInput("sha") || env.getRequired("GITHUB_SHA" /* GITHUB_SHA */);
|
||||
}
|
||||
};
|
||||
var determineBaseBranchHeadCommitOid = async function(checkoutPathOverride) {
|
||||
@@ -147138,12 +147144,12 @@ var getFileOidsUnderPath = async function(basePath) {
|
||||
}
|
||||
return fileOidMap;
|
||||
};
|
||||
function getRefFromEnv() {
|
||||
function getRefFromEnv(env) {
|
||||
let refEnv;
|
||||
try {
|
||||
refEnv = getRequiredEnvParam("GITHUB_REF");
|
||||
refEnv = env.getRequired("GITHUB_REF" /* GITHUB_REF */);
|
||||
} catch (e) {
|
||||
const maybeRef = process.env["CODE_SCANNING_REF"];
|
||||
const maybeRef = env.getOptional("CODE_SCANNING_REF" /* CODE_SCANNING_REF */);
|
||||
if (maybeRef === void 0 || maybeRef.length === 0) {
|
||||
throw e;
|
||||
}
|
||||
@@ -147151,10 +147157,10 @@ function getRefFromEnv() {
|
||||
}
|
||||
return refEnv;
|
||||
}
|
||||
async function getRef() {
|
||||
async function getRef(env, checkoutPath) {
|
||||
const refInput = getOptionalInput("ref");
|
||||
const shaInput = getOptionalInput("sha");
|
||||
const checkoutPath = getOptionalInput("checkout_path") || getOptionalInput("source-root") || getRequiredEnvParam("GITHUB_WORKSPACE");
|
||||
checkoutPath = checkoutPath ?? env.getRequired("GITHUB_WORKSPACE" /* GITHUB_WORKSPACE */);
|
||||
const hasRefInput = !!refInput;
|
||||
const hasShaInput = !!shaInput;
|
||||
if ((hasRefInput || hasShaInput) && !(hasRefInput && hasShaInput)) {
|
||||
@@ -147162,8 +147168,8 @@ async function getRef() {
|
||||
"Both 'ref' and 'sha' are required if one of them is provided."
|
||||
);
|
||||
}
|
||||
const ref = refInput || getRefFromEnv();
|
||||
const sha = shaInput || getRequiredEnvParam("GITHUB_SHA");
|
||||
const ref = refInput || getRefFromEnv(env);
|
||||
const sha = shaInput || env.getRequired("GITHUB_SHA" /* GITHUB_SHA */);
|
||||
if (refInput) {
|
||||
return refInput;
|
||||
}
|
||||
@@ -147171,8 +147177,9 @@ async function getRef() {
|
||||
if (!pull_ref_regex.test(ref)) {
|
||||
return ref;
|
||||
}
|
||||
const head = await getCommitOid(checkoutPath, "HEAD");
|
||||
const head = await getCommitOid(env, checkoutPath, "HEAD");
|
||||
const hasChangedRef = sha !== head && await getCommitOid(
|
||||
env,
|
||||
checkoutPath,
|
||||
ref.replace(/^refs\/pull\//, "refs/remotes/pull/")
|
||||
) !== head;
|
||||
@@ -147189,16 +147196,16 @@ async function getRef() {
|
||||
function removeRefsHeadsPrefix(ref) {
|
||||
return ref.startsWith("refs/heads/") ? ref.slice("refs/heads/".length) : ref;
|
||||
}
|
||||
async function isAnalyzingDefaultBranch() {
|
||||
if (process.env.CODE_SCANNING_IS_ANALYZING_DEFAULT_BRANCH === "true") {
|
||||
async function isAnalyzingDefaultBranch(env, checkoutPath) {
|
||||
if (env.getOptional("CODE_SCANNING_IS_ANALYZING_DEFAULT_BRANCH") === "true") {
|
||||
return true;
|
||||
}
|
||||
let currentRef = await getRef();
|
||||
let currentRef = await getRef(env, checkoutPath);
|
||||
currentRef = removeRefsHeadsPrefix(currentRef);
|
||||
const event = getWorkflowEvent();
|
||||
const event = getWorkflowEvent(env);
|
||||
let defaultBranch = event?.repository?.default_branch;
|
||||
if (getWorkflowEventName() === "schedule") {
|
||||
defaultBranch = removeRefsHeadsPrefix(getRefFromEnv());
|
||||
if (getWorkflowEventName(env) === "schedule") {
|
||||
defaultBranch = removeRefsHeadsPrefix(getRefFromEnv(env));
|
||||
}
|
||||
return currentRef === defaultBranch;
|
||||
}
|
||||
@@ -147470,7 +147477,7 @@ function getRegistryTypesFromEnv(logger, env = getEnv()) {
|
||||
async function createStatusReportBase(actionName, status, actionStartedAt, config, diskInfo, logger, cause, exception) {
|
||||
try {
|
||||
const commitOid = getOptionalInput("sha") || process.env["GITHUB_SHA"] || "";
|
||||
const ref = await getRef();
|
||||
const ref = await getRef(getEnv(), config?.repositoryRoot);
|
||||
const jobRunUUID = process.env["CODEQL_ACTION_JOB_RUN_UUID" /* JOB_RUN_UUID */] || "";
|
||||
const workflowRunID = getWorkflowRunID();
|
||||
const workflowRunAttempt = getWorkflowRunAttempt();
|
||||
@@ -150101,7 +150108,7 @@ var CACHE_VERSION = 1;
|
||||
var CODEQL_TRAP_CACHE_PREFIX = "codeql-trap";
|
||||
var MINIMUM_CACHE_MB_TO_UPLOAD = 10;
|
||||
var MAX_CACHE_OPERATION_MS2 = 12e4;
|
||||
async function downloadTrapCaches(codeql, languages, logger) {
|
||||
async function downloadTrapCaches(codeql, languages, logger, repositoryRoot) {
|
||||
const result = {};
|
||||
const languagesSupportingCaching = await getLanguagesSupportingCaching(
|
||||
codeql,
|
||||
@@ -150121,7 +150128,7 @@ async function downloadTrapCaches(codeql, languages, logger) {
|
||||
fs9.mkdirSync(cacheDir2, { recursive: true });
|
||||
result[language] = cacheDir2;
|
||||
}
|
||||
if (await isAnalyzingDefaultBranch()) {
|
||||
if (await isAnalyzingDefaultBranch(getEnv(), repositoryRoot)) {
|
||||
logger.info(
|
||||
"Analyzing default branch. Skipping downloading of TRAP caches."
|
||||
);
|
||||
@@ -150160,7 +150167,9 @@ async function downloadTrapCaches(codeql, languages, logger) {
|
||||
return result;
|
||||
}
|
||||
async function uploadTrapCaches(codeql, config, logger) {
|
||||
if (!await isAnalyzingDefaultBranch()) return false;
|
||||
if (!await isAnalyzingDefaultBranch(getEnv(), config.repositoryRoot)) {
|
||||
return false;
|
||||
}
|
||||
for (const language of config.languages) {
|
||||
const cacheDir2 = config.trapCaches[language];
|
||||
if (cacheDir2 === void 0) continue;
|
||||
@@ -150196,6 +150205,7 @@ async function uploadTrapCaches(codeql, config, logger) {
|
||||
return true;
|
||||
}
|
||||
async function cleanupTrapCaches(config, features, logger) {
|
||||
const env = getEnv();
|
||||
if (!await features.getValue("cleanup_trap_caches" /* CleanupTrapCaches */)) {
|
||||
return {
|
||||
trap_cache_cleanup_skipped_because: "feature disabled"
|
||||
@@ -150204,7 +150214,7 @@ async function cleanupTrapCaches(config, features, logger) {
|
||||
logger.warning(
|
||||
"TRAP cache cleanup is deprecated and will be removed in May 2026. We recommend instead disabling TRAP caching by passing the `trap-caching: false` input to the `init` Action."
|
||||
);
|
||||
if (!await isAnalyzingDefaultBranch()) {
|
||||
if (!await isAnalyzingDefaultBranch(env, config.repositoryRoot)) {
|
||||
return {
|
||||
trap_cache_cleanup_skipped_because: "not analyzing default branch"
|
||||
};
|
||||
@@ -150213,7 +150223,7 @@ async function cleanupTrapCaches(config, features, logger) {
|
||||
let totalBytesCleanedUp = 0;
|
||||
const allCaches = await listActionsCaches(
|
||||
CODEQL_TRAP_CACHE_PREFIX,
|
||||
await getRef()
|
||||
await getRef(env, config.repositoryRoot)
|
||||
);
|
||||
for (const language of config.languages) {
|
||||
if (config.trapCaches[language]) {
|
||||
@@ -150505,9 +150515,14 @@ async function initActionState({
|
||||
enableFileCoverageInformation
|
||||
};
|
||||
}
|
||||
async function downloadCacheWithTime(codeQL, languages, logger) {
|
||||
async function downloadCacheWithTime(codeQL, languages, logger, repositoryRoot) {
|
||||
const start = import_perf_hooks2.performance.now();
|
||||
const trapCaches = await downloadTrapCaches(codeQL, languages, logger);
|
||||
const trapCaches = await downloadTrapCaches(
|
||||
codeQL,
|
||||
languages,
|
||||
logger,
|
||||
repositoryRoot
|
||||
);
|
||||
const trapCacheDownloadTime = import_perf_hooks2.performance.now() - start;
|
||||
return { trapCaches, trapCacheDownloadTime };
|
||||
}
|
||||
@@ -150705,7 +150720,7 @@ async function checkOverlayEnablement(codeql, features, languages, repositoryRoo
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} with caching because we are analyzing a pull request.`
|
||||
);
|
||||
} else if (await isAnalyzingDefaultBranch()) {
|
||||
} else if (await isAnalyzingDefaultBranch(getEnv(), repositoryRoot)) {
|
||||
overlayDatabaseMode = "overlay-base" /* OverlayBase */;
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} with caching because we are analyzing the default branch.`
|
||||
@@ -150992,7 +151007,8 @@ async function initConfig(actionState, inputs) {
|
||||
const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime(
|
||||
inputs.codeql,
|
||||
config.languages,
|
||||
logger
|
||||
logger,
|
||||
repositoryRoot
|
||||
);
|
||||
config.trapCaches = trapCaches;
|
||||
config.trapCacheDownloadTime = trapCacheDownloadTime;
|
||||
@@ -151455,7 +151471,7 @@ async function getCacheSaveKey(config, codeQlVersion, checkoutPath, logger) {
|
||||
`Failed to get workflow run ID or attempt ID. Reason: ${getErrorMessage(e)}`
|
||||
);
|
||||
}
|
||||
const sha = await getCommitOid(checkoutPath);
|
||||
const sha = await getCommitOid(getEnv(), checkoutPath);
|
||||
const restoreKeyPrefix = await getCacheRestoreKeyPrefix(
|
||||
config,
|
||||
codeQlVersion
|
||||
@@ -153408,7 +153424,7 @@ async function getTrapCachingExtractorConfigArgs(config) {
|
||||
async function getTrapCachingExtractorConfigArgsForLang(config, language) {
|
||||
const cacheDir2 = config.trapCaches[language];
|
||||
if (cacheDir2 === void 0) return [];
|
||||
const write = await isAnalyzingDefaultBranch();
|
||||
const write = await isAnalyzingDefaultBranch(getEnv(), config.repositoryRoot);
|
||||
return [
|
||||
`-O=${language}.trap.cache.dir=${cacheDir2}`,
|
||||
`-O=${language}.trap.cache.bound=${TRAP_CACHE_SIZE_MB}`,
|
||||
@@ -154227,7 +154243,7 @@ async function cleanupAndUploadDatabases(action, repositoryNwo, codeql, config,
|
||||
logger.debug("Not running against github.com or GHEC-DR. Skipping upload.");
|
||||
return [];
|
||||
}
|
||||
if (!await isAnalyzingDefaultBranch()) {
|
||||
if (!await isAnalyzingDefaultBranch(action.env, checkoutPath)) {
|
||||
logger.debug("Not analyzing default branch. Skipping upload.");
|
||||
return [];
|
||||
}
|
||||
@@ -154244,7 +154260,7 @@ async function cleanupAndUploadDatabases(action, repositoryNwo, codeql, config,
|
||||
includeDiagnostics: false
|
||||
});
|
||||
bundledDbSize = fs18.statSync(bundledDb).size;
|
||||
const commitOid = await getCommitOid(checkoutPath);
|
||||
const commitOid = await getCommitOid(action.env, checkoutPath);
|
||||
const maxAttempts = 4;
|
||||
let uploadDurationMs;
|
||||
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||
@@ -156242,12 +156258,13 @@ async function uploadPostProcessedFiles(logger, checkoutPath, uploadTarget, post
|
||||
logger.debug(`Compressing serialized SARIF`);
|
||||
const zippedSarif = import_zlib.default.gzipSync(sarifPayload).toString("base64");
|
||||
const checkoutURI = url.pathToFileURL(checkoutPath).href;
|
||||
const env = getEnv();
|
||||
const payload = uploadTarget.transformPayload(
|
||||
buildPayload(
|
||||
await getCommitOid(checkoutPath),
|
||||
await getRef(),
|
||||
await getCommitOid(env, checkoutPath),
|
||||
await getRef(env, checkoutPath),
|
||||
postProcessingResults.analysisKey,
|
||||
getRequiredEnvParam("GITHUB_WORKFLOW"),
|
||||
env.getRequired("GITHUB_WORKFLOW" /* GITHUB_WORKFLOW */),
|
||||
zippedSarif,
|
||||
getWorkflowRunID(),
|
||||
getWorkflowRunAttempt(),
|
||||
@@ -156723,7 +156740,7 @@ async function run(action) {
|
||||
checkoutPath
|
||||
);
|
||||
databaseUploadResults = await cleanupAndUploadDatabases(
|
||||
{ logger, features },
|
||||
{ ...action, features },
|
||||
repositoryNwo,
|
||||
codeql,
|
||||
config,
|
||||
@@ -163024,6 +163041,7 @@ async function removeUploadedSarif(uploadFailedSarifResult, logger) {
|
||||
// src/init-action-post.ts
|
||||
async function run4(startedAt) {
|
||||
const logger = getActionsLogger();
|
||||
const env = getEnv();
|
||||
let config;
|
||||
let uploadFailedSarifResult;
|
||||
let dependencyCachingUsage;
|
||||
@@ -163054,10 +163072,10 @@ async function run4(startedAt) {
|
||||
repositoryNwo,
|
||||
features,
|
||||
jobStatus2,
|
||||
getEnv(),
|
||||
env,
|
||||
logger
|
||||
);
|
||||
if (await isAnalyzingDefaultBranch() && config.dependencyCachingEnabled !== "none" /* None */) {
|
||||
if (await isAnalyzingDefaultBranch(env, config.repositoryRoot) && config.dependencyCachingEnabled !== "none" /* None */) {
|
||||
dependencyCachingUsage = await getDependencyCacheUsage(logger);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user