mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-29 06:35:28 -04:00
docker: leverage Git to run formatting checks only on changed files
This commit is contained in:
parent
7c296290a2
commit
b7e6611d7a
6 changed files with 52 additions and 25 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# author: Ole Schuett
|
||||
|
||||
if (( $# < 1 )); then
|
||||
echo "usage: run_test.sh <test_name> [additional-args]"
|
||||
echo "usage: run_test.sh <test_name> [additional-docker-run-args]"
|
||||
echo "example: run_test.sh python"
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
|||
28
tools/docker/run_test_pr.sh
Executable file
28
tools/docker/run_test_pr.sh
Executable file
|
|
@ -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 <test_name> <PR ID or branch name> <Pull-Request ref/SHA> [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}"
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue