Fixes files: keyword and adds a fallback files_commits

What does this MR do and why?

This fixes the files keyword, which currently uses commit sha as the cache key, when it should be using the file content (checksum).

It also adds a new files_commit cache that uses the commit sha, in case this behavior is still desired.

NOTE: I will be adding instrumentation in a follow-up.

References

#460235 (closed)

How to set up and validate locally

These instructions are for testing in the UI :)

  1. Add a package.json to any project and commit to master.
  2. Add this .gitlab-ci.yml
files_commit_job:
  script: echo "test"
  cache:
    key:
      files_commit:
        - package.json
    paths: 
      - package.json
    
files_job:
  script: echo "test"
  cache:
    key:
      files:
        - package.json
    paths: 
      - package.json
  1. Run a pipeline on master. Check out the the job logs, which will mention Creating cache ....:

    In my example:

    • files_job : 0-8fe3111278da...
    • files_commit_job 0_package-ed0767d8a321b6..
  2. Create another branch. On this branch, cherry-pick the changes from step 1 by going to the commit and selecting cherry-pick:

    Screenshot 2025-09-01 at 6.13.58 PM.png

  3. Run pipeline again on that branch. You should now see that:

    • files_commit_job: has a different cache keys (uses commit SHA) :( <- this is the way files was buggy, but we are providing this just in case
    • files_job: Same cache key (uses file content hash) 0-8fe3111278da... <- this is the fix!

For extra verification - you can do steps 1-5 on master. You will see that files_job will have a different cache key.

Edited by Laura Montemayor

Merge request reports

Loading