Verify persisted repository root path in analyze action

This commit is contained in:
Michael B. Gale
2026-09-16 15:27:29 +01:00
parent 5dab0ccf51
commit ba615b5d9d
3 changed files with 27 additions and 3 deletions

13
lib/entry-points.js generated
View File

@@ -153805,7 +153805,7 @@ var CodeQLAnalysisError = class extends Error {
message;
error;
};
async function determineCheckoutPath(action) {
async function determineCheckoutPath(action, config) {
const checkoutPathInput = action.actions.getRequiredInput("checkout_path");
const repositoryRoot = await getGitRoot(checkoutPathInput);
if (repositoryRoot === void 0) {
@@ -153824,6 +153824,15 @@ async function determineCheckoutPath(action) {
"Set the 'checkout_path' input for the 'codeql-action/analyze' step to the root path of the checkout."
].join(" ")
);
} else if (config.repositoryRoot !== void 0 && repositoryRoot !== config.repositoryRoot) {
action.logger.warning(
[
`The repository path at '${repositoryRoot}' does not match that found by the 'codeql-action/init' step: '${config.repositoryRoot}'.`,
"Ensure that the 'checkout_path' input for the 'codeql-action/analyze' step is set to the path of the same repository that",
"the 'codeql-action/init' step determined. This is either the GitHub Actions workspace or the repository root corresponding to",
"the 'source-root' input if that was provided."
].join(" ")
);
}
return checkoutPathInput;
}
@@ -156638,7 +156647,7 @@ async function run(action) {
getOptionalInput("ram") || process.env["CODEQL_RAM"],
logger
);
const checkoutPath = await determineCheckoutPath(action);
const checkoutPath = await determineCheckoutPath(action, config);
const diffRangePackDir = await setupDiffInformedQueryRun(
logger,
checkoutPath

View File

@@ -310,7 +310,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
logger,
);
const checkoutPath = await determineCheckoutPath(action);
const checkoutPath = await determineCheckoutPath(action, config);
// Setup diff informed analysis if needed (based on whether init created the file)
const diffRangePackDir = await setupDiffInformedQueryRun(

View File

@@ -93,9 +93,11 @@ export interface QueriesStatusReport
* refers to the root of a repository.
*
* @param action The action state.
* @param config The CodeQL Action configuration state.
*/
export async function determineCheckoutPath(
action: ActionState<["Logger", "Actions"]>,
config: configUtils.Config,
) {
const checkoutPathInput = action.actions.getRequiredInput("checkout_path");
@@ -118,6 +120,19 @@ export async function determineCheckoutPath(
"Set the 'checkout_path' input for the 'codeql-action/analyze' step to the root path of the checkout.",
].join(" "),
);
} else if (
config.repositoryRoot !== undefined &&
repositoryRoot !== config.repositoryRoot
) {
// The repository root that was persisted by the `init` step doesn't match the one we have found here.
action.logger.warning(
[
`The repository path at '${repositoryRoot}' does not match that found by the 'codeql-action/init' step: '${config.repositoryRoot}'.`,
"Ensure that the 'checkout_path' input for the 'codeql-action/analyze' step is set to the path of the same repository that",
"the 'codeql-action/init' step determined. This is either the GitHub Actions workspace or the repository root corresponding to",
"the 'source-root' input if that was provided.",
].join(" "),
);
}
return checkoutPathInput;