diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3b005e6..e804e68 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,9 +9,9 @@ clang-format-check: tags: - linux - docker - image: manu343726/tinyrefl:clang40-x86 + image: manu343726/tinyrefl:clang-format-ci script: - - ./ci/ci_clang_format_check.sh + - CLANG_FORMAT=clang-format ./ci/ci_clang_format_check.sh - echo clang-format was applied ok test-clang40-x86-llvm4.0.0: stage: test diff --git a/ci/ci_clang_format_check.sh b/ci/ci_clang_format_check.sh index d707eb8..536f07d 100755 --- a/ci/ci_clang_format_check.sh +++ b/ci/ci_clang_format_check.sh @@ -37,6 +37,8 @@ CLANG_FORMAT_SCRIPT=$(pwd)/run-clang-format.sh if [ ! -e $CLANG_FORMAT_SCRIPT ]; then echo clang-format script not found exit 3 +else + echo using clang-format script $CLANG_FORMAT_SCRIPT fi if bash $CLANG_FORMAT_SCRIPT; then diff --git a/ci/docker/build.sh b/ci/docker/build.sh index 8767e75..a84867a 100755 --- a/ci/docker/build.sh +++ b/ci/docker/build.sh @@ -59,3 +59,6 @@ build lasote/conangcc7-armv7 gcc7-armv7 gcc g++ CROSS_BUILDING build lasote/conangcc7 gcc7-x86 gcc g++ build lasote/conangcc8-armv7 gcc8-armv7 gcc g++ CROSS_BUILDING build lasote/conangcc8 gcc8-x86 gcc g++ + +docker build clang-format -t manu343726/tinyrefl:clang-format && docker push manu343726/tinyrefl:clang-format +docker build clang-format-ci -t manu343726/tinyrefl:clang-format-ci && docker push manu343726/tinyrefl:clang-format-ci diff --git a/ci/docker/clang-format-ci/Dockerfile b/ci/docker/clang-format-ci/Dockerfile new file mode 100644 index 0000000..6207033 --- /dev/null +++ b/ci/docker/clang-format-ci/Dockerfile @@ -0,0 +1,4 @@ +FROM manu343726/tinyrefl:clang-format +MAINTAINER Manu Sanchez + +ENTRYPOINT /bin/bash diff --git a/ci/docker/clang-format/Dockerfile b/ci/docker/clang-format/Dockerfile new file mode 100644 index 0000000..f1c0ba9 --- /dev/null +++ b/ci/docker/clang-format/Dockerfile @@ -0,0 +1,22 @@ +# Image based on https://hub.docker.com/r/unibeautify/clang-format +# but adds git so we can diff the clang-format result on CI + +FROM debian:sid-slim +MAINTAINER Manu Sanchez + +ARG CLANG_FORMAT_VERSION_ARG=6.0 +ENV CLANG_FORMAT_VERSION=$CLANG_FORMAT_VERSION_ARG + +RUN apt-get update && \ +apt-get install -y clang-format-${CLANG_FORMAT_VERSION} git && \ +apt-get clean + +RUN update-alternatives \ + --install /usr/bin/clang-format clang-format /usr/bin/clang-format-${CLANG_FORMAT_VERSION} 50 + +# switch to uid/gid identical to host uid/gid (forks/users), if not doing this, files that +# clang-format written will change user and group all to root. +USER 1000:100 + +ENTRYPOINT ["clang-format"] +CMD ["--help"] diff --git a/run-clang-format.sh b/run-clang-format.sh index 1d57378..d227284 100755 --- a/run-clang-format.sh +++ b/run-clang-format.sh @@ -1,12 +1,15 @@ #!/bin/bash -CLANG_FORMAT=$1 +if [[ -z "$CLANG_FORMAT" ]]; then + CLANG_FORMAT=$1 +fi + DIRECTORIES=(include src tests examples) root_dir=$(pwd) if [[ -z "$CLANG_FORMAT" ]]; then - CLANG_FORMAT="docker run --rm -v ${root_dir}:${root_dir} unibeautify/clang-format" + CLANG_FORMAT="docker run --rm -v ${root_dir}:${root_dir} manu343726/tinyrefl:clang-format" fi echo CLANG_FORMAT=$CLANG_FORMAT