From 6a2185a0aef1c8f132b026804b66eac35a231ff4 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Tue, 17 Oct 2023 23:07:16 -0500 Subject: [PATCH] Only add excludes to find command if it's defined If excludes is not set in the yaml, or set to "", then the following error occurs: /entrypoint.sh: line 44: local: `': not a valid identifier When excludes is empty, it causes handling of the for loop over its contents to fail. To prevent this, check that the variable is non-empty prior to looping over its contents. In addition to this fix, document this feature in the readme and fix some typos there. Fixes #7 --- ReadMe.md | 7 ++++++- entrypoint.sh | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 631047d..468377e 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -12,7 +12,7 @@ An action that check code format using `clang-format` tool. Suitable for project ## Inputs ### `sources` -Sources to check by this action. It can be a single file, regex of a folder or multiple selecteor seprated by comma (`,`). +Sources to check by this action. It can be a single file, regex of a folder or multiple selectors separated by comma (`,`). Default: `"**/*"`. That means all files in this repository. @@ -24,6 +24,11 @@ or, for all nested folder `"src/**/*.h,src/**/*.c"` +### `excludes` +Sources to exclude from this action. It can be a single file, regex of a folder or multiple selectors separated by comma (`,`). + +Default: `""`. + ### `style` The style for `clang-format`. Possible value are: `LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit`. If your repository has a `.clang-format` file in the root directory then you can use `file` option here. diff --git a/entrypoint.sh b/entrypoint.sh index d037e4f..60e5a68 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -44,9 +44,11 @@ function find_cmd() { local -n cmd="$3" cmd+="find . -type f " - for exclude in $excludes; do - cmd+="! -wholename \"./$exclude\" " - done + if [ -n "$excludes" ]; then + for exclude in $excludes; do + cmd+="! -wholename \"./$exclude\" " + done + fi cmd+="\( " local is_first=1