diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index 904a09bb1..87ce60ef1 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -162327,10 +162327,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs2.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs2.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -162347,6 +162356,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/analyze-action.js b/lib/analyze-action.js index a665a6ef9..7a3c36e44 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -107922,10 +107922,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs3.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs3.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -107942,6 +107951,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index 0017ab87a..8d22f4268 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -104381,10 +104381,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs2.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs2.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -104401,6 +104410,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 55c74ea00..8ec12eb27 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -165839,10 +165839,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs3.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs3.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -165859,6 +165868,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/init-action.js b/lib/init-action.js index 76ef8f9f6..4d03be3ee 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -105491,10 +105491,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs3.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs3.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -105511,6 +105520,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); @@ -110588,8 +110602,8 @@ async function loadRepositoryProperties(repositoryNwo, logger) { } } async function computeAndPersistDiffRanges(codeql, features, logger) { - try { - await withGroupAsync("Compute PR diff ranges", async () => { + await withGroupAsync("Computing PR diff ranges", async () => { + try { const branches = await getDiffInformedAnalysisBranches( codeql, features, @@ -110607,12 +110621,12 @@ async function computeAndPersistDiffRanges(codeql, features, logger) { logger.info( `Persisted ${ranges.length} diff range(s) across ${distinctFiles} file(s).` ); - }); - } catch (e) { - logger.warning( - `Failed to compute and persist PR diff ranges: ${getErrorMessage(e)}` - ); - } + } catch (e) { + logger.warning( + `Failed to compute and persist PR diff ranges: ${getErrorMessage(e)}` + ); + } + }); } async function recordZstdAvailability(config, zstdAvailability) { addNoLanguageDiagnostic( diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index cf5710a71..c55a0bb1a 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -104374,10 +104374,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs2.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs2.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -104394,6 +104403,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index bbb235feb..8e901cda1 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -104265,10 +104265,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs3.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs3.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -104285,6 +104294,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 97be959c0..08a444719 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -107530,10 +107530,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs3.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs3.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -107550,6 +107559,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 6b6d24bfe..808098d96 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -107240,10 +107240,19 @@ function computeChangedFiles(baseFileOids, overlayFileOids) { } async function getDiffRangeFilePaths(sourceRoot, logger) { const jsonFilePath = getDiffRangesJsonFilePath(); + if (!fs3.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.` + ); + return []; + } let contents; try { contents = await fs3.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}` + ); return []; } let diffRanges; @@ -107260,6 +107269,11 @@ async function getDiffRangeFilePaths(sourceRoot, logger) { ); const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === void 0) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. Failing to avoid omitting files from the analysis." + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is." ); diff --git a/src/init-action.ts b/src/init-action.ts index 2dddc888a..b06903d5c 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -849,8 +849,8 @@ async function computeAndPersistDiffRanges( features: FeatureEnablement, logger: Logger, ): Promise { - try { - await withGroupAsync("Compute PR diff ranges", async () => { + await withGroupAsync("Computing PR diff ranges", async () => { + try { const branches = await getDiffInformedAnalysisBranches( codeql, features, @@ -868,12 +868,12 @@ async function computeAndPersistDiffRanges( logger.info( `Persisted ${ranges.length} diff range(s) across ${distinctFiles} file(s).`, ); - }); - } catch (e) { - logger.warning( - `Failed to compute and persist PR diff ranges: ${getErrorMessage(e)}`, - ); - } + } catch (e) { + logger.warning( + `Failed to compute and persist PR diff ranges: ${getErrorMessage(e)}`, + ); + } + }); } async function recordZstdAvailability( config: configUtils.Config, diff --git a/src/overlay/index.ts b/src/overlay/index.ts index 6c1074e55..4905b254f 100644 --- a/src/overlay/index.ts +++ b/src/overlay/index.ts @@ -5,6 +5,7 @@ import * as actionsCache from "@actions/cache"; import * as actionsUtil from "../actions-util"; import { + getOptionalInput, getRequiredInput, getTemporaryDirectory, getWorkflowRunAttempt, @@ -178,10 +179,20 @@ async function getDiffRangeFilePaths( ): Promise { const jsonFilePath = actionsUtil.getDiffRangesJsonFilePath(); + if (!fs.existsSync(jsonFilePath)) { + logger.debug( + `No diff ranges JSON file found at ${jsonFilePath}; skipping.`, + ); + return []; + } + let contents: string; try { contents = await fs.promises.readFile(jsonFilePath, "utf8"); - } catch { + } catch (e) { + logger.warning( + `Failed to read diff ranges JSON file at ${jsonFilePath}: ${e}`, + ); return []; } @@ -203,6 +214,12 @@ async function getDiffRangeFilePaths( // getFileOidsUnderPath output). Convert and filter accordingly. const repoRoot = await getGitRoot(sourceRoot); if (repoRoot === undefined) { + if (getOptionalInput("source-root")) { + throw new Error( + "Cannot determine git root to convert diff range paths relative to source-root. " + + "Failing to avoid omitting files from the analysis.", + ); + } logger.warning( "Cannot determine git root; returning diff range paths as-is.", );