Search RU
Tasks / CI/CD / CI pipeline linter
Statement easy

CI pipeline linter

Implement `lint_pipeline(config)` — a CI pipeline linter. On a bad config the
function does not raise; it returns a list of errors with paths.

Config:

```python
{
"version": 1,
"stages": ["build", "test", "deploy"],
"jobs": [
{"name": "build", "stage": "build"},
{"name": "test", "stage": "test", "needs": ["build"]},
{"name": "deploy", "stage": "deploy", "needs": ["test"]},
],
}
```

Rules:

- `version` is required and must be `1`;
- `stages` is a non-empty list of unique non-empty strings;
- `jobs` is a non-empty list of objects;
- every job requires `name` and `stage`;
- `name` is unique and matches `[a-z][a-z0-9_-]*`;
- a job's `stage` must be one of `stages`;
- `needs` is an optional list of job names; every dependency must exist and a
job cannot need itself;
- a cycle in `needs` is an error;
- a repeated dependency inside one `needs` is not an error;
- an unknown key inside a job is an error;
- error order: `version`, `stages`, then jobs in input order, then the cycle;
- if `stages` is invalid, jobs are not checked: their `stage` cannot be
validated;
- if jobs already have errors, the cycle is not searched for.

Error format — a string with a path:

```
version: required
stages: must be a non-empty list
jobs[1].name: duplicate job 'build'
jobs[1].needs[0]: unknown job 'lint'
jobs: dependency cycle: build -> test -> build
```

An empty config `{}` gives `["version: required", "stages: required"]`.

Hidden tests cover a valid config, missing `stages`, a duplicate name, a cycle,
an empty pipeline, an unknown stage and dependency, and a self-dependency.

Python
ci-cdyamllintvalidationdag
solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

What should a linter return for a bad config: an exception or a list of errors? Which parts of the config can be checked independently?

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts