diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2022-11-23 10:42:04 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2023-01-17 10:09:40 +0000 |
commit | 348aef1917595cc9343a55d30440e0fced7d4b13 (patch) | |
tree | 46193196d79d6548828fe9a9aea603f51c71d9ec | |
parent | 40589eed1c56f040d0f07fc354c242a0e0d83185 (diff) | |
download | libvirt-ci-348aef1917595cc9343a55d30440e0fced7d4b13.zip libvirt-ci-348aef1917595cc9343a55d30440e0fced7d4b13.tar.gz libvirt-ci-348aef1917595cc9343a55d30440e0fced7d4b13.tar.bz2 |
containers: add a standard container for python 'black' tool
The 'black' tool provides opinionated formatting of python code.
This adds a minimal container for running 'black' as a CI job.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r-- | .gitlab-ci.yml | 5 | ||||
-rw-r--r-- | containers/black/Dockerfile | 5 | ||||
-rw-r--r-- | containers/black/README.rst | 29 | ||||
-rwxr-xr-x | containers/black/black.sh | 15 |
4 files changed, 54 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1c9c8b7..37dac23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -109,6 +109,11 @@ clang-format-container: variables: NAME: clang-format +black-container: + extends: .build_container_template + variables: + NAME: black + cirrus-run-container: extends: .build_container_template variables: diff --git a/containers/black/Dockerfile b/containers/black/Dockerfile new file mode 100644 index 0000000..f7634d4 --- /dev/null +++ b/containers/black/Dockerfile @@ -0,0 +1,5 @@ +FROM docker.io/library/python:3.9-alpine + +RUN pip install black + +COPY black.sh /black diff --git a/containers/black/README.rst b/containers/black/README.rst new file mode 100644 index 0000000..2de2d0d --- /dev/null +++ b/containers/black/README.rst @@ -0,0 +1,29 @@ +================================================= +Container for running black code formatting check +================================================= + +This container provides a simple way to invoke ``black`` to validate code +formatting across a Python codebase. It should be integrated into CI by setting +the following flag in ``ci/manifest.yml`` + +:: + + gitlab: + jobs: + black: true + +or adding the following snippet to ``.gitlab-ci.yml`` + +:: + + black: + stage: sanity_checks + image: registry.gitlab.com/libvirt/libvirt-ci/black:master + needs: [] + script: + - /black + artifacts: + paths: + - black.txt + expire_in: 1 week + when: on_failure diff --git a/containers/black/black.sh b/containers/black/black.sh new file mode 100755 index 0000000..94bc111 --- /dev/null +++ b/containers/black/black.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +black --diff . > black.txt + +if test -s black.txt +then + echo + echo "❌ ERROR: some files failed black code formatting check" + echo + echo "See the black.txt artifact for full details of mistakes." + echo + exit 1 +fi + +echo "✔ OK: all files passed black code formatting check" |