diff --git a/tests/lint/git-black.sh b/tests/lint/git-black.sh index 48029a43a5b0..647aba9540f8 100755 --- a/tests/lint/git-black.sh +++ b/tests/lint/git-black.sh @@ -17,7 +17,7 @@ # under the License. set -euo pipefail -INPLACE_FORMAT=false +INPLACE_FORMAT=${INPLACE_FORMAT:=false} LINT_ALL_FILES=true REVISION= diff --git a/tests/lint/git-clang-format.sh b/tests/lint/git-clang-format.sh index c75eb754a676..a9788437b3b2 100755 --- a/tests/lint/git-clang-format.sh +++ b/tests/lint/git-clang-format.sh @@ -20,9 +20,9 @@ set -u set -o pipefail -INPLACE_FORMAT=false +INPLACE_FORMAT=${INPLACE_FORMAT:=false} LINT_ALL_FILES=true -REVISION= +REVISION=$(git rev-list --max-parents=0 HEAD) while (( $# )); do case "$1" in @@ -48,6 +48,7 @@ while (( $# )); do esac done + cleanup() { rm -rf /tmp/$$.clang-format.txt @@ -78,8 +79,7 @@ fi if [[ "$LINT_ALL_FILES" == "true" ]]; then echo "Running git-clang-format against all C++ files" FILES=$(git ls-files | grep -E '\.(c|cc|cpp|mm|h|hpp)$') - BASE_COMMIT=$(git rev-list --max-parents=0 HEAD) - git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$BASE_COMMIT" ${FILES[@]} 1> /tmp/$$.clang-format.txt + git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION" ${FILES[@]} 1> /tmp/$$.clang-format.txt else echo "Running git-clang-format against $REVISION" git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION" 1> /tmp/$$.clang-format.txt diff --git a/tests/scripts/ci.py b/tests/scripts/ci.py index 5f2034b190ee..c0ce085ff215 100755 --- a/tests/scripts/ci.py +++ b/tests/scripts/ci.py @@ -319,18 +319,24 @@ def serve_docs(directory: str = "_docs") -> None: cmd([sys.executable, "-m", "http.server"], cwd=directory_path) -def lint(interactive: bool = False) -> None: +def lint(interactive: bool = False, fix: bool = False) -> None: """ Run CI's Sanity Check step arguments: interactive -- start a shell after running build / test scripts + fix -- where possible (currently black and clang-format) edit files in place with formatting fixes """ + env = {} + if fix: + env["IS_LOCAL"] = "true" + env["INPLACE_FORMAT"] = "true" + docker( name=gen_name(f"ci-lint"), image="ci_lint", scripts=["./tests/scripts/task_lint.sh"], - env={}, + env=env, interactive=interactive, ) diff --git a/tests/scripts/task_lint.sh b/tests/scripts/task_lint.sh index c0f1311dbb06..11ba773fbf31 100755 --- a/tests/scripts/task_lint.sh +++ b/tests/scripts/task_lint.sh @@ -47,7 +47,7 @@ echo "Linting the C++ code..." tests/lint/cpplint.sh echo "clang-format check..." -./tests/lint/git-clang-format.sh +tests/lint/git-clang-format.sh echo "Rust check..." tests/lint/rust_format.sh