CI Lint API - Support for passing multiple files contents

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

Release notes

Using the actual ci/lint API route we can only validate one single file content at a time, including other files from the remote only. Included files must exist on the remote and they are taken in their "state" on concerned branch.

User experience goal

The user should be able to use the ci/lint API route to validate some CI configuration files development, even when including some extra local configuration files and developing them also.

In a few words: users should be able to send multiple files contents to the ci/lint API for validation.

Problem to solve

Some context to describe the use case:

  • let's say I'm working on a CI with the default config file .gitlab-ci.yml
  • I also use another config file included locally, let's say .gitlab/ci/template.yml
  • as I'm ready to commit, I'd like to send all new contents to the ci/lint API to validate everything is good before pushing it
  • since none of these files already exist on the remote, the actual ci/lint API route will return an UN-valid response because included file "does not exist" (which is true)

The actual situation (use case example)

Below are the contents of the two config files:

# .gitlab-ci.yml
---
include:
  - local: ".gitlab/ci/template.yml"
[...]

# .gitlab/ci/template.yml
[...]

When trying to validate the config with the actual CI Lint API (with a single content payload parameter), we got:

BODY_DATA=$(cat <<'EOT'
{
  "content": "---\n\ninclude:\n  - local: \".gitlab/ci/template.yml\"\n\n[...]"
}
EOT
)
curl "https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/ci/lint?include_merged_yaml=true" \
  --header "Authorization: Bearer ${GITLAB_TOKEN}" \
  --header 'Content-Type: application/json' \
  --data "$BODY_DATA"

{
  "valid":false,
  "errors":[
    "Local file `.gitlab/ci/template.yml` does not exist!"
  ],
  "warnings":[],
  "merged_yaml":null,
  "includes":null
}

Proposal

We should be able to send multiple config files contents to validate our whole development. We could imagine accepting a JSON payload with multiple contents, indexed by their paths.

Something like the following:

BODY_DATA=$(cat <<'EOT'
{
  ".gitlab-ci.yml": "---\n\ninclude:\n  - local: \".gitlab/ci/template.yml\"\n\n[...]",
  ".gitlab/ci/template.yml": "[...]"
}
EOT
)
curl "https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/ci/lint?include_merged_yaml=true" \
  --header "Authorization: Bearer ${GITLAB_TOKEN}" \
  --header 'Content-Type: application/json' \
  --data "$BODY_DATA"

{
  "valid":true,
  "errors":[],
  "warnings":[],
  "merged_yaml":"[...]",
  "includes":[ [...] ]
}

Includes from other projects may cause problems using this feature and should probably be considered out of scope.

Links / references

Edited by 🤖 GitLab Bot 🤖