Use commit sha for a given file in cache key
What does this MR do?
Adds an option for the caching key to be determined by some files in the repository (ie Gemfile.lock for Ruby, package.json for NPM, etc) instead of by static variables. This speeds up pipelines significantly as dependencies can be shared between branches and cache invalidation is less frequent.
cache:
key:
files:
- Gemfile.lock
prefix: gemfile-lock-at
paths:
- vendor/ruby
build:
stage: build
script:
- ruby -v
- bundle install -j $(nproc) --path vendor
With the definition from above, the cache key would be something like: gemfile-lock-at-feef9576d21ee9b6a32e30c5c79d0a0ceb68d1e5
, where feef9576d21ee9b6a32e30c5c79d0a0ceb68d1e5
is the SHA for the latest commit that changed Gemfile.lock
in the current branch.
We can add maximum two files when defining the cache key.
Related issue: #18986 (closed)
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team