diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 362b1d8..c9c8d5a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,4 +40,4 @@ jobs: fail_ci_if_error: true # optional (default = false) verbose: true # optional (default = false) - name: Test cpp-linter-hooks - run: sh testing/run.sh + run: bash testing/run.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4562e09..708d486 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: check-toml - id: requirements-txt-fixer - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.13.1 + rev: v0.14.2 hooks: # Run the linter. - id: ruff-check diff --git a/testing/pre-commit-config-style.yaml b/testing/pre-commit-config-style.yaml new file mode 100644 index 0000000..568e275 --- /dev/null +++ b/testing/pre-commit-config-style.yaml @@ -0,0 +1,43 @@ +repos: + - repo: . + rev: HEAD + hooks: + - id: clang-format + args: [--style=LLVM, --version=16] # to load .clang-format + - id: clang-tidy + args: [--checks=.clang-tidy, --version=16] # path/to/.clang-tidy + - repo: . + rev: HEAD + hooks: + - id: clang-format + args: [--style=Google, --version=17] + - id: clang-tidy + args: [--checks=.clang-tidy, --version=17] + - repo: . + rev: HEAD + hooks: + - id: clang-format + args: [--style=Microsoft, --version=18] + - id: clang-tidy + args: [--checks=.clang-tidy, --version=18] + - repo: . + rev: HEAD + hooks: + - id: clang-format + args: [--style=WebKit, --version=19] + - id: clang-tidy + args: [--checks=.clang-tidy, --version=19] + - repo: . + rev: HEAD + hooks: + - id: clang-format + args: [--style=Mozilla, --version=20] + - id: clang-tidy + args: [--checks=.clang-tidy, --version=20] + - repo: . + rev: HEAD + hooks: + - id: clang-format + args: [--style=Chromium, --version=21] + - id: clang-tidy + args: [--checks=.clang-tidy, --version=21] diff --git a/testing/run.sh b/testing/run.sh old mode 100644 new mode 100755 index b176b06..549c524 --- a/testing/run.sh +++ b/testing/run.sh @@ -1,43 +1,54 @@ #!/bin/bash -echo "===========================" -echo "Test pre-commit-config.yaml" -echo "===========================" -pre-commit clean -pre-commit run -c testing/pre-commit-config.yaml --files testing/main.c | tee -a result.txt || true -git restore testing/main.c - -echo "====================================" -echo "Test pre-commit-config-version.yaml" -echo "====================================" -pre-commit clean -pre-commit run -c testing/pre-commit-config-version.yaml --files testing/main.c | tee -a result.txt || true -git restore testing/main.c - -echo "====================================" -echo "Test pre-commit-config-verbose.yaml" -echo "====================================" -pre-commit clean -pre-commit run -c testing/pre-commit-config-verbose.yaml --files testing/main.c | tee -a result.txt || true -git restore testing/main.c + +configs=( + "pre-commit-config.yaml" + "pre-commit-config-version.yaml" + "pre-commit-config-verbose.yaml" + "pre-commit-config-style.yaml" +) + +for config in "${configs[@]}"; do + echo "====================================" + echo "Test $config" + echo "====================================" + pre-commit clean + pre-commit run -c testing/$config --files testing/main.c | tee -a result.txt || true + git restore testing/main.c +done echo "==================================================================================" -echo "print result.txt" +echo "Print result.txt" cat result.txt echo "==================================================================================" -failed_cases=`grep -c "Failed" result.txt` +failed_cases=$(grep -c "Failed" result.txt) -echo $failed_cases " cases failed." +echo "$failed_cases cases failed." -if [ $failed_cases -eq 10 ]; then +if [[ $failed_cases -eq 21 ]]; then echo "==============================" echo "Test cpp-linter-hooks success." echo "==============================" + result="success" rm result.txt - exit 0 + exit_code=0 else echo "=============================" echo "Test cpp-linter-hooks failed." echo "=============================" - exit 1 + result="failure" + exit_code=1 fi + +# Add result to GitHub summary if running in GitHub Actions +if [[ -n "$GITHUB_STEP_SUMMARY" ]]; then + { + echo "### cpp-linter-hooks Test Result" + echo "" + echo "**Result:** $result" + echo "" + echo "**Failed cases:** $failed_cases" + } >> "$GITHUB_STEP_SUMMARY" +fi + +exit $exit_code