diff --git a/tools/docker/run_test.sh b/tools/docker/run_test.sh index 3d994dcf1e..5ed92efa5c 100755 --- a/tools/docker/run_test.sh +++ b/tools/docker/run_test.sh @@ -3,7 +3,7 @@ # author: Ole Schuett if (( $# < 1 )); then - echo "usage: run_test.sh [additional-args]" + echo "usage: run_test.sh [additional-docker-run-args]" echo "example: run_test.sh python" exit 1 fi diff --git a/tools/docker/run_test_pr.sh b/tools/docker/run_test_pr.sh new file mode 100755 index 0000000000..1daae50962 --- /dev/null +++ b/tools/docker/run_test_pr.sh @@ -0,0 +1,28 @@ +#!/bin/bash -l +# -*- coding: utf-8 -*- +# author: Tiziano Müller + +set -o errexit +set -o nounset +set -o pipefail + +if [[ $# -lt 3 ]]; then + echo "usage: $0 [optional-docker-run-arguments]" + echo "example: $0 python 506 d3b9e46d0f2a0588c23fcb00f20e134f3fc302e8" + exit 1 +fi + +TESTNAME=$1 +[[ $2 =~ ^[0-9]+$ ]] && GIT_BRANCH="pull/$2/head" || GIT_BRANCH="$2" +GIT_REF=$3 + +shift 3 + +echo "Running ${TESTNAME} on Branch ${GIT_BRANCH} (ref: ${GIT_REF})..." + +set -o xtrace + +# SYS_PTRACE needed by LeakSanitizer. +docker run -i --init --rm --cap-add=SYS_PTRACE \ + -e "GIT_BRANCH=${GIT_BRANCH}" -e "GIT_REF=${GIT_REF}" \ + "$@" "img_cp2k_test_${TESTNAME}" diff --git a/tools/docker/scripts/install_basics.sh b/tools/docker/scripts/install_basics.sh index 47c641ff92..70fd5f9936 100755 --- a/tools/docker/scripts/install_basics.sh +++ b/tools/docker/scripts/install_basics.sh @@ -15,6 +15,4 @@ apt-get install -qq --no-install-recommends \ rm -rf /var/lib/apt/lists/* # clone cp2k repository -git clone --quiet --recursive --depth=1 --single-branch -b master https://github.com/cp2k/cp2k.git /workspace/cp2k - -#EOF +git clone --quiet --recursive --single-branch -b master https://github.com/cp2k/cp2k.git /workspace/cp2k diff --git a/tools/docker/scripts/install_formatting.sh b/tools/docker/scripts/install_formatting.sh index babee2851f..00f88ba12e 100755 --- a/tools/docker/scripts/install_formatting.sh +++ b/tools/docker/scripts/install_formatting.sh @@ -8,17 +8,14 @@ apt-get install -qq --no-install-recommends \ libfindbin-libs-perl \ make \ perl \ - python + python \ + python3-{pip,setuptools,wheel} rm -rf /var/lib/apt/lists/* -# pre-run prettify -cd /workspace/cp2k -echo -n "Warming cache by trying to run make pretty... " -if make -j 16 pretty &> /dev/null ; then - echo "done." -else - echo "failed." -fi +# install python packages +pip3 install pre-commit -#EOF +# register the pre-commit hooks +cd /workspace/cp2k +pre-commit install --install-hooks diff --git a/tools/docker/scripts/install_python.sh b/tools/docker/scripts/install_python.sh index 355467aaa2..9913bb8e54 100755 --- a/tools/docker/scripts/install_python.sh +++ b/tools/docker/scripts/install_python.sh @@ -24,12 +24,6 @@ rm -rf /var/lib/apt/lists/* pip install --quiet numpy matplotlib requests pip3 install --quiet numpy matplotlib requests pre-commit +# register the pre-commit hooks cd /workspace/cp2k -echo -n "Warming cache by trying to run pre-commit hooks... " -if pre-commit run --all-files --hook-stage manual check-ast &> /dev/null ; then - echo "done." -else - echo "failed." -fi - -#EOF +pre-commit install --install-hooks diff --git a/tools/docker/scripts/test_formatting.sh b/tools/docker/scripts/test_formatting.sh index 43f96d5e59..4112daea63 100755 --- a/tools/docker/scripts/test_formatting.sh +++ b/tools/docker/scripts/test_formatting.sh @@ -1,9 +1,19 @@ #!/bin/bash -e +# -*- coding: utf-8 -*- +# author: Ole Schuett, Tiziano Müller -# author: Ole Schuett +set -o pipefail echo -e "\n========== Running Formatting Test ==========" cd /workspace/cp2k -./tools/formatting/test_formatting.sh -#EOF +if [ -n "${GIT_REF}" ]; then + # get the list of changed files with their status from git between this HEAD and the origin/master + # filter out deleted files and get the last field (in case of renames the second one is the newly added) + # run the `pre-commit` on them which will fail IF files get modified by it + git diff --name-status origin/master... | awk '/^[MCRAU]/ {print $NF}' | xargs pre-commit run --files + echo "Summary: checked $(git diff --name-status origin/master... | awk '/^[MCRAU]/ {print $NF}' | wc -l) files, no violations found" + echo "Status: OK" # if not, we don't get here and the ci_entrypoint reports the FAILED status +else + ./tools/formatting/test_formatting.sh +fi