aboutsummaryrefslogtreecommitdiff
path: root/containers/cargo-fmt
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2020-05-01 11:18:32 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2020-05-13 17:15:12 +0100
commit24cf5796f376fffb21dd3106da54222ffa3dbea1 (patch)
tree4dcf729612b7bc5637aab97c452848521b7f581d /containers/cargo-fmt
parentad6f6fa7963b472ae037504c6e8e32fbd465db2c (diff)
downloadlibvirt-ci-24cf5796f376fffb21dd3106da54222ffa3dbea1.zip
libvirt-ci-24cf5796f376fffb21dd3106da54222ffa3dbea1.tar.gz
libvirt-ci-24cf5796f376fffb21dd3106da54222ffa3dbea1.tar.bz2
containers: add a standard container for running cargo fmt
The "cargo fmt" code style checking tool is something we wish to run on all Rust code, so it is useful to have a common container that can be used by all relevant projects. Reviewed-by: Andrea Bolognani <abologna@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'containers/cargo-fmt')
-rw-r--r--containers/cargo-fmt/Dockerfile10
-rw-r--r--containers/cargo-fmt/README.rst20
-rwxr-xr-xcontainers/cargo-fmt/cargo-fmt.sh22
3 files changed, 52 insertions, 0 deletions
diff --git a/containers/cargo-fmt/Dockerfile b/containers/cargo-fmt/Dockerfile
new file mode 100644
index 0000000..66621eb
--- /dev/null
+++ b/containers/cargo-fmt/Dockerfile
@@ -0,0 +1,10 @@
+FROM rust:1.43
+
+RUN export DEBIAN_FRONTEND=noninteractive && \
+ apt-get update && \
+ apt-get install --no-install-recommends -y \
+ diffstat && \
+ apt-get autoclean -y && \
+ rustup component add rustfmt
+
+COPY cargo-fmt.sh /cargo-fmt
diff --git a/containers/cargo-fmt/README.rst b/containers/cargo-fmt/README.rst
new file mode 100644
index 0000000..00f50a2
--- /dev/null
+++ b/containers/cargo-fmt/README.rst
@@ -0,0 +1,20 @@
+================================================
+Container for running cargo fmt code style check
+================================================
+
+This container provides a simple way to invoke ``cargo fmt`` to validate code
+style across a Rust codebase. It should be integrated into CI by adding
+the following snippet to ``.gitlab-ci.yml``
+
+::
+
+ cargo-fmt:
+ stage: prebuild
+ image: registry.gitlab.com/libvirt/libvirt-ci/cargo-fmt:master
+ script:
+ - /cargo-fmt
+ artifacts:
+ paths:
+ - cargo-fmt.patch
+ expire_in: 1 week
+ when: on_failure
diff --git a/containers/cargo-fmt/cargo-fmt.sh b/containers/cargo-fmt/cargo-fmt.sh
new file mode 100755
index 0000000..53fb0df
--- /dev/null
+++ b/containers/cargo-fmt/cargo-fmt.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+cargo fmt -v -- --check > cargo-fmt.patch
+
+if test -s cargo-fmt.patch
+then
+ echo
+ echo "❌ ERROR: some files failed cargo fmt code style check"
+ echo
+ diffstat cargo-fmt.patch
+ echo
+ echo "See the cargo-fmt patch artifact for full details of mistakes."
+ echo
+ echo "For guidance on how to configure Emacs or Vim to automatically"
+ echo "run cargo fmt when saving files read"
+ echo
+ echo " https://github.com/rust-lang/rustfmt"
+ echo
+ exit 1
+fi
+
+echo "✔ OK: all files passed cargo fmt code style check"