Support relative paths in cache:key:files

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

cache:key:files doesn't calculate the cache key hash if one of the filepaths for the key has a dot prefix (.) to indicate it's in the current directory.

This can be noticeable in more complex CI/CD architectures where a relative directory can be passed as a CI/CD input, and the cache key path is dynamically generated for templates. For example, specifying a build.gradle file at the root, vs specifying in a subdirectory.

Example configuration

  1. Create a project with the following structure, ensuring files and directories are named literally:
project/
├── subdir/
│   ├── lockfile
│   └── gitlab-ci.yml
├── lockfile
└── README.md
  1. Add the following YAML to the .gitlab-ci.yml to create 4 CI/CD jobs with different cache config:
cache-key-root-dot:
  script:
    - echo "hi" > cache-file.txt
    - ls -la ./lockfile
  cache:
    key:
      files:
        - "./lockfile"
    paths:
      - cache-file.txt

cache-key-root:
  script:
    - echo "hi" > cache-file.txt
    - ls -la lockfile
  cache:
    key:
      files:
        - "lockfile"
    paths:
      - cache-file.txt

cache-key-subdir-dot:
  script:
    - echo "hi" > cache-file.txt
    - ls -la ./subdir/lockfile
  cache:
    key:
      files:
        - "./subdir/lockfile"
    paths:
      - cache-file.txt

cache-key-subdir:
  script:
    - echo "hi" > cache-file.txt
    - ls -la subdir/lockfile
  cache:
    key:
      files:
        - "subdir/lockfile"
    paths:
      - cache-file.txt

Example Project

https://gitlab.com/tmike_ultimate_group/zd668038/zd668038-simple-3-notemplate

Suggestion

cache:key:files with filepaths starting with a ./ or other relative path notations should still allow the cache key hash to be calculated

Edited by 🤖 GitLab Bot 🤖