Backend: Support relative include with `include:local` or include: component
Problem
Forking a CI is a pain since it requires changing all URLs. If one file includes other files, it's even worse. git sed
is my way of handling this as best as possible.
There should be a way to reference a file relative to the one doing the inclusion.
Proposal
Currently we consider all paths as absolute to the repository.
A relative path will start with ./
and optionally ../
.
To support relative paths, in the include
context we need to track the location of the current file that is using include
. Then we expand the requested path using the current file path as reference before asking Gitaly for its content.
For example:
# current file: .gitlab/ci/main_pipeline.yml
include:
- local: ./template.yml # file in same dir - expanded as .gitlab/ci/template.yml
- local: ./../common.yml # file in upper dir - expanded as .gitlab/common.yml
- local: ../template.yml # (optional) file in upper dir - same as above
- local: ./../../../../../test.yml # (optional) expanded as test.yml - nesting capped based on the absolute path of the current file
I think there should not be a problem of breaking changes because the path format ./path/to/file.yml
is not supported today and it fails even for a file in the root directory: https://gitlab.com/fabiopitino/test/-/pipelines/1149493872.