Skip to content

Commit

Permalink
fix: Explicitly use major version (#135)
Browse files Browse the repository at this point in the history
Resolves: #134
  • Loading branch information
jidicula authored Feb 4, 2023
1 parent 523c716 commit 062f366
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ GitHub Action for `clang-format` checks. Note that this Action does **NOT** form

You can define your own formatting rules in a `.clang-format` file at your repository root, or you can provide a fallback style (see [`fallback-style`](#inputs)). You can also provide a path to check. If you want to run checks against multiple paths in your repository, you can use this Action in a [matrix run](#multiple-paths).

## Versions supported
* `clang-format-3.9`
* `clang-format-4.0`
* `clang-format-5.0`
* `clang-format-6.0`
* `clang-format-7`
* `clang-format-8`
* `clang-format-9`
* `clang-format-10`
* `clang-format-11`
* `clang-format-12`
* `clang-format-13`
* `clang-format-14`
* `clang-format-15`
## Major versions supported
* 3: `clang-format-3.9`
* 4: `clang-format-4.0`
* 5: `clang-format-5.0`
* 6: `clang-format-6.0`
* 7: `clang-format-7`
* 8: `clang-format-8`
* 9: `clang-format-9`
* 10: `clang-format-10`
* 11: `clang-format-11`
* 12: `clang-format-12`
* 13: `clang-format-13`
* 14: `clang-format-14`
* 15: `clang-format-15`

## Do you find this useful?

You can sponsor me [here](https://github.com/sponsors/jidicula)!

## Inputs
* `clang-format-version` [optional]: The version of `clang-format` that you want to run on your codebase.
* `clang-format-version` [optional]: The major version of `clang-format` that you want to run on your codebase.
* Default: `13`
* Available versions: see [Versions supported](#versions-supported)
* `check-path` [optional]: The path to the directory in the repo that should be checked for C/C++/Protobuf formatting.
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:

inputs:
clang-format-version:
description: 'The version of clang-format that you want to use.'
description: 'The major version of clang-format that you want to use.'
required: false
default: '13'
check-path:
Expand Down
16 changes: 8 additions & 8 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
###############################################################################
# USAGE: ./entrypoint.sh [<path>] [<fallback style>]
#
# Checks all C/C++/Protobuf/CUDA files (.h, .H, .hpp, .hh, .h++, .hxx and .c, .C,
# .cpp, .cc, .c++, .cxx, .proto, .cu) in the provided GitHub repository path
# Checks all C/C++/Protobuf/CUDA files (.h, .H, .hpp, .hh, .h++, .hxx and .c,
# .C, .cpp, .cc, .c++, .cxx, .proto, .cu) in the provided GitHub repository path
# (arg1) for conforming to clang-format. If no path is provided or provided path
# is not a directory, all C/C++/Protobuf/CUDA files are checked. If any files are
# incorrectly formatted, the script lists them and exits with 1.
# is not a directory, all C/C++/Protobuf/CUDA files are checked. If any files
# are incorrectly formatted, the script lists them and exits with 1.
#
# Define your own formatting rules in a .clang-format file at your repository
# root. Otherwise, the provided style guide (arg2) is used as a fallback.
Expand All @@ -20,10 +20,10 @@
format_diff() {
local filepath="$1"
# Invoke clang-format with dry run and formatting error output
if [[ $CLANG_FORMAT_VERSION -gt "9" ]]; then
local_format="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" -n --Werror --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"
if [[ $CLANG_FORMAT_MAJOR_VERSION -gt "9" ]]; then
local_format="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" -n --Werror --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"
else # Versions below 9 don't have dry run
formatted="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"
formatted="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"
local_format="$(diff -q <(cat "${filepath}") <(echo "${formatted}"))"
fi

Expand All @@ -41,7 +41,7 @@ format_diff() {
return 0
}

CLANG_FORMAT_VERSION="$1"
CLANG_FORMAT_MAJOR_VERSION="$1"
CHECK_PATH="$2"
FALLBACK_STYLE="$3"
EXCLUDE_REGEX="$4"
Expand Down

0 comments on commit 062f366

Please sign in to comment.