[go: up one dir, main page]

Skip to content

Wildcard cache:key:files no longer calculates file checksum for key

Summary

Seems to have been introduced by #203233

When using a wildcard cache:key:files string, the file hash content is no longer calculated, and the cache key has default instead.

I've tested that this behaviour changed as of v18.4.0. It's reproducible on GitLab.com, the nightly Docker image, and v18.4.0.

Steps to reproduce

  1. Create a project. Add two files:
  • hello/wildcard_file.json
  • non-wildcard_file.json
  1. Create a pipeline YAML based on the YAML below
  2. Run a pipeline
build_project:
  stage: build
  cache:
    - key:
        prefix: wildcard
        files:
          - "**/wildcard_file.json"
      paths:
        - wildcard
    - key:
        prefix: non-wildcard
        files:
          - "non-wildcard_file.json"
      paths:
        - non-wildcard
  script:
    - echo lol

Output shows that wildcard gets default, while non-wildcard gets a file hash

Creating cache wildcard-default-protected...
WARNING: wildcard: no matching files. Ensure that the artifact path is relative to the working directory (/builds/zd659198/zd659198) 
No URL provided, cache will not be uploaded to shared cache server. Cache will be stored only locally. 
Created cache
Creating cache non-wildcard-6af4929e6772c40297994e4036906cefa4c92d01-protected...
WARNING: non-wildcard: no matching files. Ensure that the artifact path is relative to the working directory (/builds/zd659198/zd659198) 

Rails output shows that wildcard doesn't calculate hashes, while non-wildcard does:

# Wildcard
irb(main):055> wildcard_cache = {:key=>{:prefix=>"wildcard", :files=>["**/wildcard_file.json"]}, :paths=>["wildcard"]}
=> {:key=>{:prefix=>"wildcard", :files=>["**/wildcard_file.json"]}, :paths=>["wildcard"]}
irb(main):056> local_cache = wildcard_cache.to_h.deep_dup
=> {:key=>{:prefix=>"wildcard", :files=>["**/wildcard_file.json"]}, :paths=>["wildcard"]}
irb(main):057> key = local_cache.delete(:key)
=> {:prefix=>"wildcard", :files=>["**/wildcard_file.json"]}
irb(main):058> key[:files]
=> ["**/wildcard_file.json"]
irb(main):059> files = key[:files].to_a.select(&:present?).uniq
=> ["**/wildcard_file.json"]
irb(main):061* content_hashes = files.map { |path|
irb(main):062*   pipeline.project.repository.git_content_hash_for_path(pipeline.sha, path)
irb(main):063> }
=> [nil]
# Non-wildcard
irb(main):064> non_wildcard_cache = {:key=>{:prefix=>"nonwildcard", :files=>["non-wildcard_file.json"]}, :paths=>["non-wildcard"]}
=> {:key=>{:prefix=>"nonwildcard", :files=>["non-wildcard_file.json"]}, :paths=>["non-wildcard"]}
irb(main):065> local_cache = non_wildcard_cache.to_h.deep_dup
=> {:key=>{:prefix=>"nonwildcard", :files=>["non-wildcard_file.json"]}, :paths=>["non-wildcard"]}
irb(main):066> key = local_cache.delete(:key)
=> {:prefix=>"nonwildcard", :files=>["non-wildcard_file.json"]}
irb(main):067> key[:files]
=> ["non-wildcard_file.json"]
irb(main):068> files = key[:files].to_a.select(&:present?).uniq
=> ["non-wildcard_file.json"]
irb(main):069* content_hashes = files.map { |path|
irb(main):070*   pipeline.project.repository.git_content_hash_for_path(pipeline.sha, path)
irb(main):071> }
=> ["e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"]

Example Project

What is the current bug behavior?

Wildcard cache:key:files causes file hash to not be calculated

What is the expected correct behavior?

Wildcard cache:key:files have their file hashes calculated

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Patch release information for backports

If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.

Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.

High-severity bug remediation

To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.

Edited by Michael Trainor