Skip to content

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Oct 6, 2025

This triggers a subset of the behavior of CODEQL_ACTION_TEST_MODE, specifically just skipping the SARIF upload step. This is required for our internal testing where we want the SARIF file (via CODEQL_ACTION_DUMP_SARIF_DIR) but don't want to actually upload it, but we don't want the rest of the behaviour of CODEQL_ACTION_TEST_MODE that is specific for codeql-action own CI checks.

This is a fresh take at #3089, with less impact on the codebase.

Risk assessment

For internal use only. Please select the risk level of this change:

  • Low risk: Changes are fully under feature flags, or have been fully tested and validated in pre-production environments and are highly observable, or are documentation or test only.
  • High risk: Changes are not fully under feature flags, have limited visibility and/or cannot be tested outside of production.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

This triggers a subset of the behavior of `CODEQL_ACTION_TEST_MODE`,
specifically just skipping the SARIF upload step. This is required for
our internal testing where we want the SARIF file (via
`CODEQL_ACTION_DUMP_SARIF_DIR`) but don't want to actually upload it,
but we don't want the rest of the behaviour of `CODEQL_ACTION_TEST_MODE`
that is specific for `codeql-action` own CI checks.
@redsun82 redsun82 requested a review from a team as a code owner October 6, 2025 13:10
@redsun82 redsun82 requested review from Copilot and mbg October 6, 2025 13:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new environment variable CODEQL_ACTION_SKIP_SARIF_UPLOAD that provides more granular control over SARIF upload behavior. It allows skipping SARIF uploads without enabling full test mode, which is useful for internal testing scenarios where SARIF files are needed locally but should not be uploaded to GitHub.

Key changes:

  • Adds new environment variable CODEQL_ACTION_SKIP_SARIF_UPLOAD for selective SARIF upload control
  • Introduces shouldSkipSarifUpload() function that combines test mode and the new skip flag
  • Updates upload logic and messaging to use the new function instead of direct test mode checks

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/environment.ts Adds the new SKIP_SARIF_UPLOAD environment variable enum
src/util.ts Introduces shouldSkipSarifUpload() function and updates test mode documentation
src/upload-lib.ts Updates upload logic to use new function and improves messaging
src/upload-sarif-action.ts Updates wait-for-processing logic to use new function
src/init-action-post-helper.ts Updates failed SARIF upload logic to use new function
lib/*.js Generated JavaScript code corresponding to TypeScript changes

Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but Michael should have the say.


// If in test mode we don't want to upload the results
if (util.isInTestMode()) {
// If in test mode we don't want to upload the results,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is a bit stale now, ditto at the other isInTestMode/shouldSkipSarifUpload switch.

Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is generally much neater! I've added a few minor comments.

It is probably worth adding a test case for this.


/**
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
* This setting is implied but is more specific than `CODEQL_ACTION_TEST_MODE`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the wording here isn't great.

Suggested change
* This setting is implied but is more specific than `CODEQL_ACTION_TEST_MODE`.
* This setting is more specific than `CODEQL_ACTION_TEST_MODE`, which also implies this option.

logger.info(
`In test mode. Results are not uploaded. Saving to ${payloadSaveFile}`,
);
logger.info(`SARIF upload disabled. Saving to ${payloadSaveFile}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: This no longer explains why the SARIF upload is disabled. A simple fix might be wording it like this:

Suggested change
logger.info(`SARIF upload disabled. Saving to ${payloadSaveFile}`);
logger.info(`SARIF upload disabled with an environment variable. Saving to ${payloadSaveFile}`);

A better fix would be to include the responsible environment variable, perhaps with:

Suggested change
logger.info(`SARIF upload disabled. Saving to ${payloadSaveFile}`);
logger.info(`SARIF upload disabled by `${ isInTestMode() ? EnvVar.TEST_MODE : EnvVar.SKIP_SARIF_UPLOAD }`. Saving to ${payloadSaveFile}`);

@redsun82
Copy link
Contributor Author

redsun82 commented Oct 6, 2025

It is probably worth adding a test case for this

@mbg: how would you go on about this?

  • the PR checks set CODEQL_ACTION_TEST_MODE, which "hides" this new behaviour. Maybe a PR check could unset that and set CODEQL_ACTION_SKIP_SARIF_UPLOAD instead? Wouldn't there be some other unwanted effects in the PR checks though?
  • on the unit test side, there's currently no unit tests for uploadSpecifiedFiles, and CODEQL_ACTION_TEST_MODE is not covered at all in there. Adding tests for uploadSpecifiedFiles would probably be nice, but maybe a tad too much for the scope of this PR?

src/util.ts Outdated
Comment on lines 776 to 784
export function getSarifUploadSkipReason(): string | null {
if (isInTestMode()) {
return `SARIF upload is disabled via ${EnvVar.TEST_MODE}`;
}
if (process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true") {
return `SARIF upload is disabled via ${EnvVar.SKIP_SARIF_UPLOAD}`;
}
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered something like this when I wrote my comment, but wasn't too keen on it. I also don't love using the human-readable reason phrase to mean true for enablement purposes. The previous version with the boolean function was preferable.

Also, in general, we don't use null in the codeql-action codebase (unless it comes to us from outside the codebase) and would go for undefined here.

Copy link
Contributor Author

@redsun82 redsun82 Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to avoid something like

    logger.info(`SARIF upload disabled by `${ isInTestMode() ? EnvVar.TEST_MODE : EnvVar.SKIP_SARIF_UPLOAD }`. Saving to ${payloadSaveFile}`);

as I didn't want to expose that util implementation detail. So I think I'll just go with your first proposal for a generic with an environment variable. The users of those variables (us) probably are savvy enough for that to be enough for them.

@mbg
Copy link
Member

mbg commented Oct 6, 2025

how would you go on about this?
on the unit test side, there's currently no unit tests [..]

Hmm yes. Unit tests for uploadPayload would be best. I don't think it would be too hard to set this up with mocks for the IO operations (fs.writeFileSync and client.request) and checking which ones were called for given permutations of the environment variables. That said, if there aren't any unit tests here already, then don't feel obligated to set this up as part of this PR.

@redsun82
Copy link
Contributor Author

redsun82 commented Oct 6, 2025

how would you go on about this?
on the unit test side, there's currently no unit tests [..]

Hmm yes. Unit tests for uploadPayload would be best. I don't think it would be too hard to set this up with mocks for the IO operations (fs.writeFileSync and client.request) and checking which ones were called for given permutations of the environment variables. That said, if there aren't any unit tests here already, then don't feel obligated to set this up as part of this PR.

Let's make that into a follow-up PR. I'll try to see what copilot can do there.

Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you accidentally reverted one of the changes we wanted to keep. Also two other minor suggestions for wording improvements.

Otherwise this LGTM and I am happy to approve.

/**
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
* This setting is implied by `CODEQL_ACTION_TEST_MODE`, but is more specific.
* This setting is implied by but is more specific than `CODEQL_ACTION_TEST_MODE`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope 😅

);
logger.info(
`In test mode. Results are not uploaded. Saving to ${payloadSaveFile}`,
`SARIF upload disabled via environment variable. Saving to ${payloadSaveFile}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor:

Suggested change
`SARIF upload disabled via environment variable. Saving to ${payloadSaveFile}`,
`SARIF upload disabled by an environment variable. Saving to ${payloadSaveFile}`,

core.debug("In test mode. Waiting for processing is disabled.");
if (shouldSkipSarifUpload()) {
core.debug(
"SARIF upload disabled via environment variable. Waiting for processing is disabled.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"SARIF upload disabled via environment variable. Waiting for processing is disabled.",
"SARIF upload disabled by an environment variable. Waiting for processing is disabled.",

@redsun82 redsun82 enabled auto-merge October 7, 2025 15:18
@redsun82
Copy link
Contributor Author

redsun82 commented Oct 7, 2025

@mbg thanks for the review! I think I addressed everything. I also opened a follow-up with unit tests: #3185 (with a little help from copilot)

Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing those minor issues!

@redsun82 redsun82 merged commit 8301b8b into main Oct 8, 2025
242 checks passed
@redsun82 redsun82 deleted the redsun82/skip-sarif-upload branch October 8, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants