diff --git a/action.yml b/action.yml index 26fe4d0..3168cb0 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: required: false default: 'llvm' include-regex: - description: 'A regex to override the C/C++/Protobuf/CUDA filetype regex. that should be checked. Default results in the regex defined in `check.sh`.' + description: 'A regex to override the C/C++/Protobuf/CUDA filetype regex for files that should be checked. Default results in the regex defined in `check.sh`.' required: false default: '' @@ -31,7 +31,7 @@ runs: using: "composite" steps: - run: | - "${{ github.action_path }}/check.sh" "${{ inputs.clang-format-version }}" "${{ inputs.check-path }}" "${{ inputs.fallback-style }}" "${{ inputs.exclude-regex }}" "${{ inputs.include-regex }}" + "${{ github.action_path }}/wrapper.sh" "${{ inputs.clang-format-version }}" "${{ inputs.check-path }}" "${{ inputs.fallback-style }}" "${{ inputs.exclude-regex }}" "${{ inputs.include-regex }}" shell: bash - name: Save PR head commit SHA if: failure() && github.event_name == 'pull_request' diff --git a/check.sh b/check.sh index ba252b3..6271de5 100755 --- a/check.sh +++ b/check.sh @@ -21,20 +21,14 @@ format_diff() { local filepath="$1" # Invoke clang-format with dry run and formatting error output if [[ $CLANG_FORMAT_MAJOR_VERSION -gt "9" ]]; then - local_format="$(docker run \ - --volume "$(pwd)":"$(pwd)" \ - --workdir "$(pwd)" \ - ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \ + local_format="$(clang-format \ --dry-run \ --Werror \ --style=file \ --fallback-style="$FALLBACK_STYLE" \ "${filepath}")" else # Versions below 9 don't have dry run - formatted="$(docker run \ - --volume "$(pwd)":"$(pwd)" \ - --workdir "$(pwd)" \ - ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \ + formatted="$(clang-format \ --style=file \ --fallback-style="$FALLBACK_STYLE" \ "${filepath}")" diff --git a/test/test.sh b/test/test.sh index ac8b7f8..2f7d8fd 100755 --- a/test/test.sh +++ b/test/test.sh @@ -9,7 +9,7 @@ CLANG_FORMAT_VERSION="$1" ############################################################################### # should succeed -"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" +"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" docker_status="$?" if [[ $docker_status != "0" ]]; then echo "files that should succeed have failed!" @@ -17,7 +17,7 @@ if [[ $docker_status != "0" ]]; then fi # should fail -"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" +"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" docker_status="$?" if [[ $docker_status == "0" ]]; then echo "files that should fail have succeeded!" @@ -26,7 +26,7 @@ fi # load test on known_pass/addition.c copies -"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/load_test" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" +"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/load_test" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" docker_status="$?" if [[ $docker_status != "0" ]]; then echo "files that should succeed have failed in the loadtest!" @@ -40,7 +40,7 @@ fi INCLUDE_REGEX='^.*\.(c|C)' # should succeed -"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX" +"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_pass" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX" docker_status="$?" if [[ $docker_status != "0" ]]; then echo "files that should succeed have failed!" @@ -48,7 +48,7 @@ if [[ $docker_status != "0" ]]; then fi # should fail -"$GITHUB_WORKSPACE"/check.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX" +"$GITHUB_WORKSPACE"/wrapper.sh "$CLANG_FORMAT_VERSION" "$GITHUB_WORKSPACE/test/known_fail" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX" docker_status="$?" if [[ $docker_status == "0" ]]; then echo "files that should fail have succeeded!" diff --git a/wrapper.sh b/wrapper.sh new file mode 100755 index 0000000..9cffcc0 --- /dev/null +++ b/wrapper.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +CLANG_FORMAT_MAJOR_VERSION="$1" +CHECK_PATH="$2" +FALLBACK_STYLE="$3" +EXCLUDE_REGEX="$4" +INCLUDE_REGEX="$5" + +docker run \ + --volume "$(pwd)":"$(pwd)" \ + --workdir "$(pwd)" \ + --interactive \ + --tty \ + ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" \ + "/check.sh" "$CLANG_FORMAT_MAJOR_VERSION" "$CHECK_PATH" "$FALLBACK_STYLE" "$EXCLUDE_REGEX" "$INCLUDE_REGEX"