GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support non-lock files for C# cache key computation by mbg · Pull Request #3117 · github/codeql-action

Conversation

@mbg

@mbg mbg commented Sep 17, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR modifies our implementation of dependency caching for C# to allow non-lock files to be used when computing a hash for the cache key.

The hash that's included in the cache key is derived from files which contain information about the project's dependency. The idea being that the hash changes only if the dependencies change. Currently, we only use packages.lock.json and paket.lock files for this. These files contain exact dependency information (including the exact versions that were resolved by the respective package manager). The resulting hashes we compute for the cache keys should therefore only change if the dependencies (including versions) change. This is the desired behaviour.

However, relatively few C# projects use lock files and fewer yet have them checked-in to the repository. This means that most C# projects do not benefit from our implementation of dependency caching at the moment.

This PR modifies the behaviour of our dependency caching implementation for C# as follows:

  • As before, we search for packages.lock.json or paket.lock files. If they exist, we use them to compute a hash for the cache key.
  • If no such files exist, and the new CsharpNewCacheKey feature is enabled (via FF or environment variable), we search for additional files that typically contain dependency information for C# projects. If they exist, we use them to compute the hash for the cache key.

Using the additional files is less precise, because they may not contain exact version information (only version ranges or no versions at all) and they contain information unrelated to dependencies. This means that the hash we compute can change, even if the dependencies don't change. However, dependency caching will benefit more C# projects.

This PR is best reviewed commit-by-commit. The first few commits just add the new Feature and refactor the code a bit to facilitate the changes.

Questions for reviewers:

  • Right now, disabling the Feature wouldn't avoid restoring caches that were produced with the Feature enabled. We likely want to do something similar as for Add feature flag to roll out JAR minimization in the Java extractor #3107 that marks caches produced with this Feature on.
  • Should we use this opportunity to also extend the list of paths that are included in the cache for C#? The setup-dotnet Action considers more paths and computes them dynamically. Now that we have getDependencyPaths as a function, it would be easy to do this.
  • If so, should that be gated behind the same FF?
  • Are there any additional files we should include for C# hashes?

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mbg
mbg requested a review from a team as a code owner September 17, 2025 14:53
@mbg
mbg requested review from Copilot, henrymercer and michaelnebel September 17, 2025 14:53
Copilot AI reviewed Sep 17, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 enhances C# dependency caching support by allowing non-lock files to be used when computing cache keys. Currently, only packages.lock.json and paket.lock files are used for cache key computation, which limits caching benefits to projects that have these lock files checked in. The new implementation maintains backward compatibility while expanding support to more C# projects through an optional feature flag.

Key changes:

  • Adds a new CsharpNewCacheKey feature flag with environment variable support
  • Refactors cache configuration from static data structures to dynamic functions
  • Implements fallback logic to use .csproj, packages.config, and nuget.config files when lock files are unavailable

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/feature-flags.ts Adds the new CsharpNewCacheKey feature flag configuration
src/dependency-caching.ts Core refactoring to support dynamic hash pattern generation and C# fallback logic
src/init-action.ts Updates function calls to pass CodeQL and features parameters
src/analyze-action.ts Updates function calls to pass CodeQL and features parameters
lib/* Generated JavaScript files reflecting the TypeScript changes

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

henrymercer
henrymercer reviewed Sep 17, 2025
View reviewed changes

@henrymercer henrymercer left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks reasonable from an Action perspective

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

michaelnebel
michaelnebel reviewed Sep 18, 2025
View reviewed changes
Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

michaelnebel
michaelnebel reviewed Sep 18, 2025
View reviewed changes

@michaelnebel michaelnebel left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks plausible to me!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jbj jbj mentioned this pull request Nov 5, 2025
C#: Overlay extraction support. github/codeql#20425
Merged
mbg added 9 commits November 5, 2025 15:48
@mbg
Add CsharpNewCacheKey FF
1ca20ab
@mbg
Propagate features into cachePrefix function
2aa1f55
@mbg
Change getDefaultCacheConfig to be a const by turning paths int…
2a7680f
…o a function

Changing `paths` to be a function is necessary to allow `getTemporaryDirectory` to be called
@mbg
Change hash to be a function that can use Features
ab1c842
@mbg
Move check whether there are files for hashing into getHashPatterns
6b48207
@mbg
Use additional files for C# key hashes if Feature.CsharpNewCacheKey…
0324490
… is enabled
@mbg
Move createCacheKeyHash to caching-utils
0cbd930
@mbg
Add and use getFeaturePrefix for dependency caching
03b2dc2
@mbg
Use undefined instead of NoMatchingFilesError
2680455
Add tests for `makePatternCheck` and `checkHashPatterns`
@mbg
mbg force-pushed the mbg/csharp/new-cache-key-calculation branch from 7f81d73 to 2680455 Compare November 5, 2025 17:34
@github-actions github-actions Bot added the size/L May be hard to review label Nov 5, 2025
@mbg
mbg requested review from Copilot, henrymercer and nickrolfe November 5, 2025 17:35
Copilot AI reviewed Nov 5, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

michaelnebel
michaelnebel reviewed Nov 7, 2025
View reviewed changes

@michaelnebel michaelnebel left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The new pattern for deciding which C# files to use in the cache hash LGTM!

Should we use this opportunity to also extend the list of paths that are included in the cache for C#? The setup-dotnet Action considers more paths and computes them dynamically. Now that we have getDependencyPaths as a function, it would be easy to do this.

Does this mean that we are "only" including "{working_dir}/.nuget/packages" in the cache?

The dependency manager for C# use the "scratch dir" for storing downloaded packages.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
nickrolfe
nickrolfe reviewed Nov 7, 2025
View reviewed changes

@nickrolfe nickrolfe left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I only reviewed the parts that generalise the mechanism to add a feature-flag-specific prefix to the cache key, but that looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mbg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
henrymercer
henrymercer reviewed Nov 7, 2025
View reviewed changes

@henrymercer henrymercer left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This generally looks good. The only blocking comment from me is the naming of the cache entries.

For PRs like this in the future, consider splitting up into a core functionality part (e.g. here, handling the addition of feature flags to the cache key), and a language-specific part (e.g. here, changing the cache key for C#).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/caching-utils.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/dependency-caching.ts Outdated
Comment on lines +130 to +133
// If we get to this point, the `basePatterns` didn't find any files,
// and `Feature.CsharpNewCacheKey` is either not enabled or we didn't
// find any files using those patterns either.
return undefined;

@henrymercer henrymercer Nov 7, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The last bit isn't true since we'll return the result of makePatternCheck, even if it's undefined. It might be clearer to have a helper function that checks whether the patterns match anything, and use that here instead.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mbg mbg Nov 9, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For now, I have updated the comment to remove the erroneous part. I think that was leftover from a previous iteration of this function.

I did notice that we could use makePatternCheck for the base patterns check as well though, so I have done that and added test coverage for getCsharpHashPatterns.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/dependency-caching.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/dependency-caching.ts Outdated

return `${prefix}-${CODEQL_DEPENDENCY_CACHE_VERSION}-${runnerOs}-${language}-`;
// Assemble the cache key.
return `${featurePrefix}${prefix}-${CODEQL_DEPENDENCY_CACHE_VERSION}-${runnerOs}-${language}-`;

@henrymercer henrymercer Nov 7, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If users list cache entries using the API, I think it'd be clearer to them what those cache entries are for if we keep codeql-dependencies- at the front.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mbg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@mbg mbg Nov 9, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

As discussed elsewhere, I also thought this would be a good idea. Thanks for confirming!

I have pushed a commit which changes this, except for minify- so that we don't run into problems with that, since it's already rolled out.

Once the JAR minification experiment has concluded, we can remove all of the special handling for that along with that FF.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mbg

mbg commented Nov 9, 2025

Copy link
Copy Markdown
Member Author

Does this mean that we are "only" including "{working_dir}/.nuget/packages" in the cache?

The dependency manager for C# use the "scratch dir" for storing downloaded packages.

@michaelnebel It is $HOME/.nuget/packages, but yes -- that is the only directory we are currently including in C# dependency caches. If you store dependencies elsewhere as well, then it might make sense to include that path (similarly to what we have done for Java as well).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mbg added 2 commits November 9, 2025 10:05
@mbg
Fix JSDoc param name
46e03b4
@mbg
Fix comment in getCsharpHashPatterns
71abac7
mbg added 4 commits November 9, 2025 11:03
@mbg
Add tests for getCsharpHashPatterns
35c91ef
- Make the function more easily testable by allowing `makePatternCheck` to be stubbed.
- Use `makePatternCheck` for base patterns as well.
@mbg
Restore missing status.push resulting from a bad merge
b0e9dfc
@mbg
Restore earlier log messages for checkHashPatterns
a47d550
@mbg
Insert new featurePrefix after general cache key prefix
4885eb2
@mbg
mbg requested review from Copilot and henrymercer November 9, 2025 11:21
Copilot AI reviewed Nov 9, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mbg
Add some tests for downloadDependencyCaches related to feature pref…
48a56f6
…ixes
@github-actions github-actions Bot added size/XL May be very hard to review and removed size/L May be hard to review labels Nov 9, 2025
@michaelnebel

michaelnebel commented Nov 10, 2025

Copy link
Copy Markdown

Does this mean that we are "only" including "{working_dir}/.nuget/packages" in the cache?
The dependency manager for C# use the "scratch dir" for storing downloaded packages.

@michaelnebel It is $HOME/.nuget/packages, but yes -- that is the only directory we are currently including in C# dependency caches. If you store dependencies elsewhere as well, then it might make sense to include that path (similarly to what we have done for Java as well).

We store dependencies in sub directories of the directory in CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR. (which should be set by the CLI). Could this be incorporated as well?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mbg

mbg commented Nov 10, 2025

Copy link
Copy Markdown
Member Author

@michaelnebel Thanks for pointing this out! I have thought about this a little, and I think it may be better to make that a separate change and put it behind a separate FF. That way we can see what impact each change has separately and get this change shipped faster.

michaelnebel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

henrymercer
henrymercer approved these changes Nov 12, 2025
View reviewed changes
@mbg
mbg merged commit 534824e into main Nov 12, 2025
@mbg
mbg deleted the mbg/csharp/new-cache-key-calculation branch November 12, 2025 11:03
@mbg mbg mentioned this pull request Nov 13, 2025
C#: Cache temporary dependency directory for BMN #3286
Merged
This was referenced Nov 13, 2025
Merge main into releases/v4 #3293
Merged
Merge releases/v4 into releases/v3 #3295
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nickrolfe nickrolfe nickrolfe left review comments
@hvitved hvitved hvitved left review comments
@michaelnebel michaelnebel michaelnebel left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@henrymercer henrymercer henrymercer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

size/XL May be very hard to review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@mbg @michaelnebel @nickrolfe @hvitved @henrymercer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.