CI: Run clang format on linux and osx CI and fail if changes are made

master
Colin Edwards 2019-07-08 20:50:59 -05:00
parent 4ec072075d
commit 28243dbc94
6 changed files with 67 additions and 4 deletions

View File

@ -1,6 +1,11 @@
#!/bin/sh
set -ex
#!/bin/bash
./formatcode.sh
if ! ./CI/check-format.sh; then
exit 1
fi
set -ex
ccache -s || echo "CCache is not available."
mkdir build && cd build
cmake ..

View File

@ -3,6 +3,11 @@ export PATH=/usr/local/opt/ccache/libexec:$PATH
git fetch --tags
./formatcode.sh
if ! ./CI/check-format.sh; then
exit 1
fi
mkdir build
cd build
cmake -DENABLE_SPARKLE_UPDATER=ON \

11
CI/check-format.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
dirty=$(git ls-files --modified)
set +x
if [[ $dirty ]]; then
echo "================================="
echo "Files were not formatted properly"
echo "$dirty"
echo "================================="
exit 1
fi

View File

@ -3,6 +3,16 @@ set -ex
sudo add-apt-repository ppa:jonathonf/ffmpeg-3 -y
curl -L https://packagecloud.io/github/git-lfs/gpgkey | sudo apt-key add -
# gets us newer clang
sudo bash -c "cat >> /etc/apt/sources.list" << LLVMAPT
# 3.8
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
LLVMAPT
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get -qq update
sudo apt-get install -y \
build-essential \
@ -42,4 +52,5 @@ sudo apt-get install -y \
python3-dev \
qtbase5-dev \
libqt5svg5-dev \
swig
swig \
clang-format-8

View File

@ -26,7 +26,7 @@ sudo installer -pkg ./Packages.pkg -target /
brew update
#Base OBS Deps and ccache
brew install jack speexdsp ccache mbedtls
brew install jack speexdsp ccache mbedtls clang-format
brew install https://gist.githubusercontent.com/DDRBoxman/b3956fab6073335a4bf151db0dcbd4ad/raw/ed1342a8a86793ea8c10d8b4d712a654da121ace/qt.rb
brew install https://gist.githubusercontent.com/DDRBoxman/4cada55c51803a2f963fa40ce55c9d3e/raw/572c67e908bfbc1bcb8c476ea77ea3935133f5b5/swig.rb

31
formatcode.sh Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Original source https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/format.sh
set +x
set -o errexit
set -o pipefail
set -o nounset
# Runs the Clang Formatter in parallel on the code base.
# Return codes:
# - 1 there are files to be formatted
# - 0 everything looks fine
# Get CPU count
OS=$(uname)
NPROC=1
if [[ $OS = "Linux" ]] ; then
NPROC=$(nproc)
elif [[ ${OS} = "Darwin" ]] ; then
NPROC=$(sysctl -n hw.physicalcpu)
fi
# Discover clang-format
if type clang-format-8 2> /dev/null ; then
CLANG_FORMAT=clang-format-8
else
CLANG_FORMAT=clang-format
fi
find . -type d \( -path ./deps -o -path ./cmake -o -path ./plugins/decklink/win -o -path ./plugins/decklink/mac -o -path ./plugins/decklink/linux \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
| xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none {}