2017-07-19 05:08:04 -05:00
|
|
|
Integration with other software
|
|
|
|
===============================
|
|
|
|
|
|
|
|
Integration with pre-commit
|
|
|
|
---------------------------
|
|
|
|
|
2023-03-22 04:31:20 -05:00
|
|
|
You can integrate yamllint in the `pre-commit <https://pre-commit.com/>`_ tool.
|
2017-07-19 05:08:04 -05:00
|
|
|
Here is an example, to add in your .pre-commit-config.yaml
|
|
|
|
|
|
|
|
.. code:: yaml
|
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
---
|
|
|
|
# Update the rev variable with the release version that you want, from the yamllint repo
|
|
|
|
# You can pass your custom .yamllint with args attribute.
|
|
|
|
repos:
|
|
|
|
- repo: https://github.com/adrienverge/yamllint.git
|
|
|
|
rev: v1.29.0
|
|
|
|
hooks:
|
|
|
|
- id: yamllint
|
|
|
|
args: [--strict, -c=/path/to/.yamllint]
|
2023-03-22 04:31:20 -05:00
|
|
|
|
2020-09-22 22:23:24 -05:00
|
|
|
|
|
|
|
Integration with GitHub Actions
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
yamllint auto-detects when it's running inside of `GitHub
|
2022-06-14 20:53:05 -05:00
|
|
|
Actions <https://github.com/features/actions>`_ and automatically uses the
|
|
|
|
suited output format to decorate code with linting errors. You can also force
|
|
|
|
the GitHub Actions output with ``yamllint --format github``.
|
2020-09-22 22:23:24 -05:00
|
|
|
|
2022-12-12 12:08:31 -06:00
|
|
|
A minimal example workflow using GitHub Actions:
|
2020-09-22 22:23:24 -05:00
|
|
|
|
|
|
|
.. code:: yaml
|
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
---
|
|
|
|
on: push # yamllint disable-line rule:truthy
|
2020-09-22 22:23:24 -05:00
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
jobs:
|
|
|
|
lint:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
2020-09-22 22:23:24 -05:00
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
- name: Install yamllint
|
|
|
|
run: pip install yamllint
|
2020-09-22 22:23:24 -05:00
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
- name: Lint YAML files
|
|
|
|
run: yamllint .
|
2020-10-24 06:24:55 -05:00
|
|
|
|
2024-01-08 07:00:17 -06:00
|
|
|
Integration with GitLab
|
2024-01-09 17:35:39 -06:00
|
|
|
-----------------------
|
2024-01-05 14:00:51 -06:00
|
|
|
|
2024-01-08 07:04:19 -06:00
|
|
|
You can use the following GitLab CI/CD stage to run yamllint and get the
|
2024-01-09 17:34:03 -06:00
|
|
|
results as a `Code quality (Code Climate)
|
|
|
|
<https://docs.gitlab.com/ee/ci/testing/code_quality.html>` report.
|
2024-01-05 14:00:51 -06:00
|
|
|
|
|
|
|
.. code:: yaml
|
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
---
|
|
|
|
lint:
|
|
|
|
stage: lint
|
|
|
|
script:
|
|
|
|
- pip install yamllint
|
|
|
|
- mkdir reports
|
|
|
|
- >
|
|
|
|
yamllint -f parsable . | tee >(awk '
|
|
|
|
BEGIN {FS = ":"; ORS="\n"; first=1}
|
|
|
|
{
|
|
|
|
gsub(/^[ \t]+|[ \t]+$|"/, "", $4);
|
|
|
|
match($4, /^\[(warning|error)\](.*)\((.*)\)$/, a);
|
|
|
|
sev = (a[1] == "error" ? "major" : "minor");
|
|
|
|
if (first) {
|
|
|
|
first=0;
|
|
|
|
printf("[");
|
|
|
|
} else {
|
|
|
|
printf(",");
|
|
|
|
}
|
|
|
|
printf("{\"location\":{\"path\":\"%s\",\"lines\":{\"begin\":%s",\
|
|
|
|
"\"end\":%s}},\"severity\":\"%s\",\"check_name\":\"%s\","\
|
|
|
|
"\"categories\":[\"Style\"],\"type\":\"issue\","\
|
|
|
|
"\"description\":\"%s\"}", $1, $2, $3, sev, a[3], a[2]);
|
|
|
|
}
|
|
|
|
END { if (!first) printf("]\n"); }' > reports/codequality.json)
|
|
|
|
artifacts:
|
|
|
|
when: always
|
|
|
|
paths:
|
|
|
|
- reports
|
|
|
|
expire_in: 1 week
|
|
|
|
reports:
|
|
|
|
codequality: reports/codequality.json
|
2024-01-08 07:00:17 -06:00
|
|
|
|
|
|
|
Integration with Arcanist
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
You can configure yamllint to run on ``arc lint``. Here is an example
|
|
|
|
``.arclint`` file that makes use of this configuration.
|
|
|
|
|
|
|
|
.. code:: json
|
|
|
|
|
2024-01-08 07:07:37 -06:00
|
|
|
{
|
|
|
|
"linters": {
|
|
|
|
"yamllint": {
|
|
|
|
"type": "script-and-regex",
|
|
|
|
"script-and-regex.script": "yamllint",
|
|
|
|
"script-and-regex.regex": "/^(?P<line>\\d+):(?P<offset>\\d+) +(?P<severity>warning|error) +(?P<message>.*) +\\((?P<name>.*)\\)$/m",
|
|
|
|
"include": "(\\.(yml|yaml)$)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|