Skip to content

Persist CodeQL version output to file rather than environment - #4081

Merged
mario-campos merged 23 commits into
mainfrom
mario-campos/version-cache-to-disk
Aug 13, 2026
Merged

Persist CodeQL version output to file rather than environment#4081
mario-campos merged 23 commits into
mainfrom
mario-campos/version-cache-to-disk

Conversation

@mario-campos

@mario-campos mario-campos commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Currently, the output of codeql version is cached and persisted between steps as an environment variable. This is fine, for now, but, as we begin to cache more of the CLI, we should persist that output to a file instead because:

  1. There is a limit to the size of a process' environment. On GitHub Actions, the runners already have a populated environment. And, the output of these CLI commands may be verbose.
  2. There is data to suggest that a larger environment has performance implications (more environment variables -> more memory for the kernel to copy during execve(2)).

To that end, and as a precaution, this PR replaces $CODEQL_ACTION_CLI_VERSION_INFO with $CODEQL_ACTION_TEMP/version.json, a file-backed cache for codeql version.

Changes

  • Moved the CodeQL CLI version caching logic from util.ts (which used environment variables) into a new module src/cli/output-cache.ts, which now uses a temporary on-disk file (codeql-action-command-cache.json) for cross-step persistence. This includes new functions for caching, retrieving, and resetting the cached version, as well as improved validation of persisted data.
  • Moved the VersionInfo type definition from codeql.ts to a new shared file src/cli/types.ts, and updated all references to use the new location. This centralizes type definitions to avoid cyclic dependencies.
  • Removed the now-obsolete CODEQL_VERSION_INFO environment variable from EnvVar in environment.ts.

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.

Which use cases does this change impact?

Workflow types:

  • Advanced setup - Impacts users who have custom CodeQL workflows.
  • Managed - Impacts users with dynamic workflows (Default Setup, Code Quality, ...).

Products:

  • Code Scanning - The changes impact analyses when analysis-kinds: code-scanning.
  • Code Quality - The changes impact analyses when analysis-kinds: code-quality.

Environments:

  • Dotcom - Impacts CodeQL workflows on github.com and/or GitHub Enterprise Cloud with Data Residency.
  • GHES - Impacts CodeQL workflows on GitHub Enterprise Server.

How did/will you validate this change?

  • Unit tests - I am depending on unit test coverage (i.e. tests in .test.ts files).
  • End-to-end tests - I am depending on PR checks (i.e. tests in pr-checks).

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Rollback - Change can only be disabled by rolling back the release or releasing a new version with a fix.

How will you know if something goes wrong after this change is released?

  • Telemetry - I rely on existing telemetry or have made changes to the telemetry.
    • Alerts - New or existing monitors will trip if something goes wrong with this change.

Are there any special considerations for merging or releasing this change?

  • No special considerations - This change can be merged at any time.

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.

Copilot AI balanced review requested due to automatic review settings August 7, 2026 20:18
@mario-campos
mario-campos requested a review from a team as a code owner August 7, 2026 20:18
@github-actions github-actions Bot added the size/S Should be easy to review label Aug 7, 2026
@mario-campos
mario-campos requested a review from mbg August 7, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Moves persisted CodeQL CLI version metadata from an environment variable to a temporary JSON file.

Changes:

  • Writes and reads version metadata from $CODEQL_ACTION_TEMP/version.json.
  • Removes the obsolete environment variable.
  • Updates persistence tests.
Show a summary per file
File Description
src/util.ts Implements file-based version caching.
src/util.test.ts Updates cache-reading tests.
src/environment.ts Removes the old cache environment variable.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/util.ts Outdated
This is particularly important for the first time that `getCachedCodeQlVersion` is invoked, as this cache file will not yet exist.
@mario-campos
mario-campos force-pushed the mario-campos/version-cache-to-disk branch from a1f3399 to 9183a7b Compare August 10, 2026 15:45

@mbg mbg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this back up! I have added a few inline (mostly style) comments.

Some high-level points:

  • Also added as an in-line comment, but do you plan to have a separate file for each command? If so, why? On the same topic, if not, then should the file be more structured to allow for relevant metadata and other command output down the line?
  • Have you had any more thoughts about either checking that the cached file is intended for the current analysis (e.g. by checking the generated jobUuid) or deleting cache files on "startup"?
  • Add a unit test for the case where the file cannot be read (e.g. because it doesn't exist).
  • The linter CI is failing. Remember to run npm lint locally before committing / pushing changes.

Much more minor, but I spotted this in the PR description:

This is fine, for now, but, as we begin to cache more of the CLI, we should persist that output to a file instead.

The reasoning here ("as we begin to cache more of the CLI") doesn't really justify the conclusion ("we should persist that output to a file instead). Could you edit that to actually highlight why files are preferable to environment variables?

Comment thread src/util.ts Outdated
Comment thread src/util.ts Outdated
Comment thread src/util.ts Outdated
Comment thread src/util.ts Outdated
Comment thread src/util.ts Outdated
Comment thread src/util.ts Outdated
Comment thread src/util.test.ts Outdated
Comment thread src/util.test.ts Outdated
@github-actions github-actions Bot added size/L May be hard to review and removed size/S Should be easy to review labels Aug 11, 2026
@mario-campos
mario-campos force-pushed the mario-campos/version-cache-to-disk branch from 139c544 to 11569df Compare August 11, 2026 20:55
@mario-campos
mario-campos force-pushed the mario-campos/version-cache-to-disk branch from b11737e to 40f80a8 Compare August 11, 2026 23:09
Comment thread src/util.test.ts Outdated
Comment thread src/cli/output-cache.ts Outdated
Comment thread src/cli/output-cache.ts Outdated
Comment thread src/cli/output-cache.ts Outdated
Comment thread src/cli/output-cache.ts Outdated
Comment thread src/cli/output-cache.ts Outdated
This will ensure it works nicely with `JSON.stringify`. And, then we can validate the type before marshaling.
Comment thread src/cli/output-cache.ts Outdated
mbg
mbg previously approved these changes Aug 13, 2026

@mbg mbg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, aside from addressing the minor point about the logging the error and resolving the merge conflict.

@mario-campos
mario-campos enabled auto-merge August 13, 2026 14:27
@mario-campos
mario-campos added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit c2fd8f5 Aug 13, 2026
222 checks passed
@mario-campos
mario-campos deleted the mario-campos/version-cache-to-disk branch August 13, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L May be hard to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants