Skip to content

Commit

Permalink
Merge pull request #2599 from bilke/hooks
Browse files Browse the repository at this point in the history
Git hooks with pre-commit
  • Loading branch information
bilke committed Aug 12, 2019
2 parents da34261 + f95ce87 commit 8a7b703
Show file tree
Hide file tree
Showing 42 changed files with 287 additions and 115 deletions.
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md, --markdown-linebreak-ext=pandoc]
- id: check-added-large-files
args: [--maxkb 1024]
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- repo: local
hooks:
- id: git-diff-check
name: Run git diff --check
entry: git diff --check --cached -- ':!*.md' ':!*.pandoc' ':!*.asc' ':!*.dat' ':!*.ts'
language: system
stages: [commit, manual]
- id: file-extensions
name: Check file extensions
entry: scripts/hooks/pre-commit-file-extensions.sh
language: system
files: '.*\.cpp'
stages: [commit, manual]
- id: file-names
name: Check file names
entry: scripts/hooks/pre-commit-file-names.sh
language: system
stages: [commit, manual]
- id: git-lfs
name: Check git lfs files
entry: scripts/hooks/pre-commit-git-lfs.sh
language: system
stages: [commit, manual]

exclude: 'ThirdParty/*|Tests/Data/*|web/static/images/xsd'
Expand Up @@ -7,5 +7,5 @@ are calculated by the symmetry property as \f$\nu_{ji} E_i = \nu_{ij} E_j\f$ (no
They also must fulfil following two properties:
\f[|\nu_{ij}| < \sqrt({E_i \over E_j}),\f]
and
\f[1 - \nu_{12}\nu_{21} - \nu_{23}\nu_{32} - \nu_{13}\nu_{31}
\f[1 - \nu_{12}\nu_{21} - \nu_{23}\nu_{32} - \nu_{13}\nu_{31}
- \nu_{12}\nu_{23}\nu{31} - \nu_{32}\nu_{21}\nu{13} > 0.\f]
4 changes: 3 additions & 1 deletion Jenkinsfile
Expand Up @@ -25,9 +25,11 @@ pipeline {
}
stages {
// *************************** Git Check **********************************
stage('Git Check') {
stage('Pre-checks') {
agent { label "master"}
steps {
sh "pre-commit install"
sh "pre-commit run --all-files"
sh "git config core.whitespace -blank-at-eof"
sh "git diff --check `git merge-base origin/master HEAD` HEAD -- . ':!*.md' ':!*.pandoc' ':!*.asc' ':!*.dat' ':!*.ts'"
dir('scripts/jenkins') { stash(name: 'known_hosts', includes: 'known_hosts') }
Expand Down
6 changes: 3 additions & 3 deletions Tests/MathLib/TestGlobalVectorInterface.cpp
Expand Up @@ -208,7 +208,7 @@ void checkGlobalVectorInterfacePETSc()
/*
Assume there is a vector distributed over three processes as
-- rank0 -- --- rank1 --- -- rank2 --
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11
where the numbers are the global entry indices.
In each trunk of entries of a rank, there are ghost entries in
other ranks attached and their global entry indices are:
Expand All @@ -224,7 +224,7 @@ void checkGlobalVectorInterfacePETSc()
The above ghost entry embedded vector is realized by the following
test.
*/
*/
std::size_t local_vec_size = 4;
if (mrank == 1)
local_vec_size = 5;
Expand All @@ -234,7 +234,7 @@ void checkGlobalVectorInterfacePETSc()
std::vector<double> non_ghost_vals(local_vec_size);
std::size_t nghosts = 3;
if (mrank)
nghosts = 2;
nghosts = 2;
std::vector<GlobalIndexType> ghost_ids(nghosts);
std::vector<double> expected;
switch (mrank)
Expand Down
31 changes: 18 additions & 13 deletions scripts/docker/Dockerfile.clang.full
Expand Up @@ -39,15 +39,15 @@ RUN apt-get update -y && \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install virtualenv
# CMake version 3.13.4
RUN pip3 install virtualenv pre-commit
# CMake version 3.12.4
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
wget && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.sh && \
/bin/sh /var/tmp/cmake-3.13.4-Linux-x86_64.sh --prefix=/usr/local --skip-license && \
rm -rf /var/tmp/cmake-3.13.4-Linux-x86_64.sh
RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh && \
/bin/sh /var/tmp/cmake-3.12.4-Linux-x86_64.sh --prefix=/usr/local --skip-license && \
rm -rf /var/tmp/cmake-3.12.4-Linux-x86_64.sh
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:git-core/ppa -y && \
Expand All @@ -66,19 +66,28 @@ RUN apt-get update && \
mkdir -p /apps /scratch /lustre /work /projects /data

# Package manager Conan building block
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
pkg-config && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
autoconf-archive \
libtool && \
rm -rf /var/lib/apt/lists/*
# pip
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
python3-pip \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install conan==1.17.0
RUN pip3 install conan==1.18.0
RUN mkdir -p /opt/conan && \
chmod 777 /opt/conan
ENV CONAN_USER_HOME=/opt/conan
LABEL org.opengeosys.pm=conan \
org.opengeosys.pm.conan.version=1.17.0
org.opengeosys.pm.conan.version=1.18.0
LABEL org.opengeosys.pm.conan.user_home=/opt/conan

# Include-what-you-use for clang version 7
Expand Down Expand Up @@ -108,16 +117,12 @@ ENV CCACHE_DIR=/opt/cache \
LABEL ccache.dir=/opt/cache \
ccache.size=15G

RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
sudo && \
rm -rf /var/lib/apt/lists/*

# Jenkins node
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
openssh-client \
rsync && \
rsync \
sudo && \
rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 1001 jenkins || true && \
adduser --uid 500 --gid 1001 --disabled-password --gecos "" jenkins && \
Expand Down
31 changes: 18 additions & 13 deletions scripts/docker/Dockerfile.gcc.full
Expand Up @@ -32,15 +32,15 @@ RUN apt-get update -y && \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install virtualenv
# CMake version 3.13.4
RUN pip3 install virtualenv pre-commit
# CMake version 3.12.4
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
wget && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.sh && \
/bin/sh /var/tmp/cmake-3.13.4-Linux-x86_64.sh --prefix=/usr/local --skip-license && \
rm -rf /var/tmp/cmake-3.13.4-Linux-x86_64.sh
RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh && \
/bin/sh /var/tmp/cmake-3.12.4-Linux-x86_64.sh --prefix=/usr/local --skip-license && \
rm -rf /var/tmp/cmake-3.12.4-Linux-x86_64.sh
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:git-core/ppa -y && \
Expand All @@ -59,19 +59,28 @@ RUN apt-get update && \
mkdir -p /apps /scratch /lustre /work /projects /data

# Package manager Conan building block
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
pkg-config && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
autoconf-archive \
libtool && \
rm -rf /var/lib/apt/lists/*
# pip
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
python3-pip \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install conan==1.17.0
RUN pip3 install conan==1.18.0
RUN mkdir -p /opt/conan && \
chmod 777 /opt/conan
ENV CONAN_USER_HOME=/opt/conan
LABEL org.opengeosys.pm=conan \
org.opengeosys.pm.conan.version=1.17.0
org.opengeosys.pm.conan.version=1.18.0
LABEL org.opengeosys.pm.conan.user_home=/opt/conan

# cppcheck version 1.87
Expand Down Expand Up @@ -111,16 +120,12 @@ ENV CCACHE_DIR=/opt/cache \
LABEL ccache.dir=/opt/cache \
ccache.size=15G

RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
sudo && \
rm -rf /var/lib/apt/lists/*

# Jenkins node
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
openssh-client \
rsync && \
rsync \
sudo && \
rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 1001 jenkins || true && \
adduser --uid 500 --gid 1001 --disabled-password --gecos "" jenkins && \
Expand Down
31 changes: 18 additions & 13 deletions scripts/docker/Dockerfile.gcc.gui
Expand Up @@ -32,15 +32,15 @@ RUN apt-get update -y && \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install virtualenv
# CMake version 3.13.4
RUN pip3 install virtualenv pre-commit
# CMake version 3.12.4
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
wget && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.sh && \
/bin/sh /var/tmp/cmake-3.13.4-Linux-x86_64.sh --prefix=/usr/local --skip-license && \
rm -rf /var/tmp/cmake-3.13.4-Linux-x86_64.sh
RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh && \
/bin/sh /var/tmp/cmake-3.12.4-Linux-x86_64.sh --prefix=/usr/local --skip-license && \
rm -rf /var/tmp/cmake-3.12.4-Linux-x86_64.sh
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common && \
apt-add-repository ppa:git-core/ppa -y && \
Expand All @@ -67,19 +67,28 @@ RUN apt-get update -y && \
rm -rf /var/lib/apt/lists/*

# Package manager Conan building block
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
pkg-config && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
autoconf-archive \
libtool && \
rm -rf /var/lib/apt/lists/*
# pip
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
python3-pip \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install conan==1.17.0
RUN pip3 install conan==1.18.0
RUN mkdir -p /opt/conan && \
chmod 777 /opt/conan
ENV CONAN_USER_HOME=/opt/conan
LABEL org.opengeosys.pm=conan \
org.opengeosys.pm.conan.version=1.17.0
org.opengeosys.pm.conan.version=1.18.0
LABEL org.opengeosys.pm.conan.user_home=/opt/conan

# cppcheck version 1.87
Expand Down Expand Up @@ -112,16 +121,12 @@ ENV CCACHE_DIR=/opt/cache \
LABEL ccache.dir=/opt/cache \
ccache.size=15G

RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
sudo pkg-config && \
rm -rf /var/lib/apt/lists/*

# Jenkins node
RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
openssh-client \
rsync && \
rsync \
sudo && \
rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 1001 jenkins || true && \
adduser --uid 500 --gid 1001 --disabled-password --gecos "" jenkins && \
Expand Down
23 changes: 23 additions & 0 deletions scripts/hooks/pre-commit-file-extensions.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# set -e

# Check for uppercase letters in filename extensions
pattern=".*\.\w*([A-Z]+)\w*$"
files=$(echo $@ | grep -E "$pattern")

if [[ -n $files ]];
then
echo "Attention!"
echo "----------"
echo "Found files that contain capital letters in the file extension."
echo "Please rename the following files and commit again:"

while read -r file; do
echo -e '\E[0;32m'"$file"'\033[0m'
done <<< "$files"
# Abort commit
exit 1
fi

exit 0
39 changes: 39 additions & 0 deletions scripts/hooks/pre-commit-file-names.sh
@@ -0,0 +1,39 @@
#!/bin/bash

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $($@ |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi

0 comments on commit 8a7b703

Please sign in to comment.