docs: add GitLab CI / Code Climate example

Signed-off-by: gardar <gardar@users.noreply.github.com>
This commit is contained in:
gardar 2024-01-05 20:00:51 +00:00 committed by Adrien Vergé
parent fd8ddeef8b
commit 06581793b3

View File

@ -65,3 +65,44 @@ You can configure yamllint to run on ``arc lint``. Here is an example
}
}
}
Intergration with GitLab
------------------------
You can use the following gitlab-ci stage to do run yamllint and get the results as a
`Code quality (Code Climate) <https://docs.gitlab.com/ee/ci/testing/code_quality.html>` report.
.. code:: yaml
---
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