diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 54c9251880..b381d6cb5e 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,20 @@ 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 + # TODO: Remove this once the entire project is formatted. + allow_failure: true + 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