diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2021-02-15 17:30:37 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2021-03-08 13:07:49 +0000 |
commit | d64582bfce0b83ab079d95a11d3dcc5938ead907 (patch) | |
tree | dd27ba957de854c2ad345a3c90951fc68b9e6f9e /containers | |
parent | 3d45ab0546e5f82b496cb2dd3b6e9f6326d39a3e (diff) | |
download | libvirt-ci-d64582bfce0b83ab079d95a11d3dcc5938ead907.zip libvirt-ci-d64582bfce0b83ab079d95a11d3dcc5938ead907.tar.gz libvirt-ci-d64582bfce0b83ab079d95a11d3dcc5938ead907.tar.bz2 |
containers: introduce an image for clang-format
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'containers')
-rw-r--r-- | containers/clang-format/Dockerfile | 8 | ||||
-rw-r--r-- | containers/clang-format/README.rst | 20 | ||||
-rwxr-xr-x | containers/clang-format/clang-format.sh | 23 |
3 files changed, 51 insertions, 0 deletions
diff --git a/containers/clang-format/Dockerfile b/containers/clang-format/Dockerfile new file mode 100644 index 0000000..50a614f --- /dev/null +++ b/containers/clang-format/Dockerfile @@ -0,0 +1,8 @@ +FROM docker.io/library/alpine:3 + +RUN apk update && \ + apk upgrade && \ + apk add clang git && \ + apk list | sort > /packages.txt + +COPY clang-format.sh /clang-format diff --git a/containers/clang-format/README.rst b/containers/clang-format/README.rst new file mode 100644 index 0000000..38df1b3 --- /dev/null +++ b/containers/clang-format/README.rst @@ -0,0 +1,20 @@ +=================================================== +Container for running clang-format code style check +=================================================== + +This container provides a simple way to invoke ``clang-format`` to validate +code style across a C codebase. It should be integrated into a CI by adding +the following snippet to ``.gitlab-ci.yml`` + +:: + + clang-format: + stage: prebuild + image: registry.gitlab.com/libvirt/libvirt-ci/clang-format:master + script: + - /clang-format + artifacts: + paths: + - clang-format.patch + expire_in: 1 week + when: on_failure diff --git a/containers/clang-format/clang-format.sh b/containers/clang-format/clang-format.sh new file mode 100755 index 0000000..e1b0eda --- /dev/null +++ b/containers/clang-format/clang-format.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +git ls-tree --name-only -r HEAD | grep '\.[ch]$' | xargs clang-format -i + +git diff > clang-format.patch +if test -s clang-format.patch +then + echo + echo "❌ ERROR: some files failed clang-format code style check" + echo + git diff --stat + echo + echo "See the clang-format patch artifact for full details of mistakes." + echo + echo "For guidance on how to configure Emacs or Vim to automatically" + echo "run clang-format when saving files read" + echo + echo " https://clang.llvm.org/docs/ClangFormat.html" + echo + exit 1 +fi + +echo "✔ OK: all files passed go fmt code style check" |