From 3e9fccd7f00cab51d93be5236cd4c5e4b8976bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Tue, 20 Sep 2022 22:03:44 +0300 Subject: [PATCH 1/2] Test clang-format project wide in same pipeline --- .gitlab-ci.yml | 13 +++++++++++++ CI/check_clang_format.sh | 31 +++++++++++++++++++++++++++++++ CI/install_debian_deps.sh | 5 +++++ 3 files changed, 49 insertions(+) create mode 100755 CI/check_clang_format.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 54c9251880..0a494c6b7c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ default: # Note: We set `needs` on each job to control the job DAG. # See https://docs.gitlab.com/ee/ci/yaml/#needs stages: + - checks - build - test @@ -118,6 +119,18 @@ Ubuntu_GCC: CCACHE_SIZE: 4G # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks. timeout: 2h + +Clang_Format: + extends: .Ubuntu_Image + stage: checks + cache: + key: Ubuntu_Clang_Format.ubuntu_22.04.v1 + paths: + - apt-cache/ + before_script: + - CI/install_debian_deps.sh openmw-clang-format + script: + - CI/check_clang_format.sh Ubuntu_GCC_Debug: extends: .Ubuntu diff --git a/CI/check_clang_format.sh b/CI/check_clang_format.sh new file mode 100755 index 0000000000..9ae45d48af --- /dev/null +++ b/CI/check_clang_format.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +CLANG_FORMAT="clang-format-14" +HAS_DIFFS=0 + +check_format() { + local path=$1 + local tempfile=$(mktemp) + for item in $(find $path -type f -name "*"); + do + if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then + echo "Checking code formatting on $item" + $CLANG_FORMAT $item > $tempfile + git diff --color=always --no-index $item $tempfile + if [[ $? = 1 ]]; then + HAS_DIFFS=1 + fi + fi; + done; + rm -f $tempfile +} + +check_format "./apps" +check_format "./components" + +if [[ $HAS_DIFFS -eq 1 ]]; then + echo "clang-format differences detected" + exit 1 +fi; + +exit 0 \ No newline at end of file diff --git a/CI/install_debian_deps.sh b/CI/install_debian_deps.sh index ca68326a63..7790c80087 100755 --- a/CI/install_debian_deps.sh +++ b/CI/install_debian_deps.sh @@ -77,6 +77,11 @@ declare -rA GROUPED_DEPS=( " [android]="binutils build-essential cmake ccache curl unzip git pkg-config" + + [openmw-clang-format]=" + clang-format-14 + git-core + " ) if [[ $# -eq 0 ]]; then From 91ed7f73b961027f6e508684ee9ea5d846f7f923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Tue, 20 Sep 2022 23:04:49 +0300 Subject: [PATCH 2/2] Allow the check to fail for the time being --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a494c6b7c..b381d6cb5e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -123,6 +123,8 @@ Ubuntu_GCC: Clang_Format: extends: .Ubuntu_Image stage: checks + # TODO: Remove this once the entire project is formatted. + allow_failure: true cache: key: Ubuntu_Clang_Format.ubuntu_22.04.v1 paths: