From 99983a3c1db3966222f8a47c45ca3c90ec7d2991 Mon Sep 17 00:00:00 2001 From: Norihiro Watanabe Date: Fri, 11 Mar 2016 14:22:27 +0100 Subject: [PATCH] check coding style in travis --- .travis.yml | 14 ++++++++++++-- scripts/ci/check_code_format.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 scripts/ci/check_code_format.sh diff --git a/.travis.yml b/.travis.yml index 25f493385..b2d1b7aec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,15 @@ matrix: - env: TRAVIS_EMPTY_JOB_WORKAROUND=true include: + # check coding style + - env: CASE=codingstyle + addons: + apt: + sources: + - llvm-toolchain-precise-3.7 + - ubuntu-toolchain-r-test + packages: + - clang-format-3.7 # check typical OGS builds - env: CASE=FEM - env: CASE=IPQC @@ -44,8 +53,9 @@ install: - if [[ "$CASE" == "PETSC" ]]; then travis_retry sudo apt-get install -qq libpetsc3.4.2-dev; fi script: - - mkdir build && cd build && cmake -DOGS_CONFIG=${CASE} $CMAKE_ARGS -DOGS_CPU_ARCHITECTURE=generic .. && cmake .. - - make + - if [[ "$CASE" != "codingstyle" ]]; then mkdir build && cd build && cmake -DOGS_CONFIG=${CASE} $CMAKE_ARGS -DOGS_CPU_ARCHITECTURE=generic .. && cmake ..; fi + - if [[ "$CASE" != "codingstyle" ]]; then make; fi + - if [[ "$CASE" == "codingstyle" ]]; then chmod +x ./scripts/ci/check_code_format.sh && ./scripts/ci/check_code_format.sh; fi notifications: email: diff --git a/scripts/ci/check_code_format.sh b/scripts/ci/check_code_format.sh new file mode 100755 index 000000000..fb053c18f --- /dev/null +++ b/scripts/ci/check_code_format.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Modified from https://github.com/google/closure-library/tree/master/scripts/ci +# +# Script to determine if files in Pull Request are properly formatted. +# Exits with non 0 exit code if formatting is needed. + +CLANG_FORMAT_DIFF=clang-format-diff-3.7 + +FILES_TO_CHECK=$(git diff --name-only master | grep -E "\.h|\.cpp$") + +if [ -z "${FILES_TO_CHECK}" ]; then + echo "No files to check for formatting." + exit 0 +fi + +FORMAT_DIFF=$(git diff -U0 master -- ${FILES_TO_CHECK} | + ${CLANG_FORMAT_DIFF} -p1 -style=file) + +if [ -z "${FORMAT_DIFF}" ]; then + # No formatting necessary. + echo "All files in PR properly formatted." + exit 0 +else + # Found diffs. + echo "ERROR: Found formatting errors!" + echo "${FORMAT_DIFF}" + echo "See https://goo.gl/wUEkW9 for instructions to format your PR." + exit 1 +fi