From 27ad6a7d287e4788a78e159b3e4f51bd96dc99d5 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 1 Sep 2020 21:34:11 +0100 Subject: [PATCH 1/9] Sort the options --- action.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 59e4372..0d17f5d 100644 --- a/action.yml +++ b/action.yml @@ -2,6 +2,10 @@ name: 'Codespell with annotations' author: 'Peter Newman' description: 'Codespell with annotations for Pull Request' inputs: + builtin: + description: 'Comma-separated list of builtin dictionaries to include' + required: false + default: '' check_filenames: description: 'If set, check file names as well' required: false @@ -14,14 +18,6 @@ inputs: description: 'File with lines that should not be checked for spelling mistakes' required: false default: '' - skip: - description: 'Comma-separated list of files to skip (it accepts globs as well)' - required: false - default: './.git' - builtin: - description: 'Comma-separated list of builtin dictionaries to include' - required: false - default: '' ignore_words_file: description: 'File with a list of words to be ignored. Words are case sensitive based on how they are written in the dictionary file' required: false @@ -38,6 +34,10 @@ inputs: description: 'Path to run codespell in' required: false default: '' + skip: + description: 'Comma-separated list of files to skip (it accepts globs as well)' + required: false + default: './.git' only_warn: description: 'If set, only warn, never error' required: false From 26eb385182c54ca96410858e1ca19945e9f00da6 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 1 Sep 2020 21:35:30 +0100 Subject: [PATCH 2/9] Add codespell config --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 0d17f5d..8d6b7b5 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: description: 'If set, check hidden files (those starting with ".") as well' required: false default: '' + config: + description: 'Path to a codespell config file' + required: false + default: '' exclude_file: description: 'File with lines that should not be checked for spelling mistakes' required: false From 8b763a9cfbc15887ba882dc1715e45157daf3d43 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 1 Sep 2020 21:38:17 +0100 Subject: [PATCH 3/9] Sort the options in the entrypoint script --- entrypoint.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7c3d4ed..7423945 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,10 @@ echo "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" # e.g. PIPESTATUS and pipestatus only work in bash/zsh respectively. echo "Running codespell on '${INPUT_PATH}' with the following options..." command_args="" +echo "Builtin dictionaries '${INPUT_BUILTIN}'" +if [ "x${INPUT_BUILTIN}" != "x" ]; then + command_args="${command_args} --builtin ${INPUT_BUILTIN}" +fi echo "Check filenames? '${INPUT_CHECK_FILENAMES}'" if [ -n "${INPUT_CHECK_FILENAMES}" ]; then echo "Checking filenames" @@ -24,14 +28,6 @@ echo "Exclude file '${INPUT_EXCLUDE_FILE}'" if [ "x${INPUT_EXCLUDE_FILE}" != "x" ]; then command_args="${command_args} --exclude-file ${INPUT_EXCLUDE_FILE}" fi -echo "Skipping '${INPUT_SKIP}'" -if [ "x${INPUT_SKIP}" != "x" ]; then - command_args="${command_args} --skip ${INPUT_SKIP}" -fi -echo "Builtin dictionaries '${INPUT_BUILTIN}'" -if [ "x${INPUT_BUILTIN}" != "x" ]; then - command_args="${command_args} --builtin ${INPUT_BUILTIN}" -fi echo "Ignore words file '${INPUT_IGNORE_WORDS_FILE}'" if [ "x${INPUT_IGNORE_WORDS_FILE}" != "x" ]; then command_args="${command_args} --ignore-words ${INPUT_IGNORE_WORDS_FILE}" @@ -43,6 +39,9 @@ fi echo "Ignore URI words list '${INPUT_URI_IGNORE_WORDS_LIST}'" if [ "x${INPUT_URI_IGNORE_WORDS_LIST}" != "x" ]; then command_args="${command_args} --uri-ignore-words-list ${INPUT_URI_IGNORE_WORDS_LIST}" +echo "Skipping '${INPUT_SKIP}'" +if [ "x${INPUT_SKIP}" != "x" ]; then + command_args="${command_args} --skip ${INPUT_SKIP}" fi echo "Resulting CLI options ${command_args}" exec 5>&1 From e85fb8ff45b0862db0301ec653526597e72ba34a Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 1 Sep 2020 21:38:34 +0100 Subject: [PATCH 4/9] Add the config option --- entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 7423945..7bc77f9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -24,6 +24,10 @@ if [ -n "${INPUT_CHECK_HIDDEN}" ]; then echo "Checking hidden" command_args="${command_args} --check-hidden" fi +echo "Config '${INPUT_CONFIG}'" +if [ "x${INPUT_CONFIG}" != "x" ]; then + command_args="${command_args} --config ${INPUT_CONFIG}" +fi echo "Exclude file '${INPUT_EXCLUDE_FILE}'" if [ "x${INPUT_EXCLUDE_FILE}" != "x" ]; then command_args="${command_args} --exclude-file ${INPUT_EXCLUDE_FILE}" From 32acd6a68c34a6c11fb7fd65283f651b1e5b8ba9 Mon Sep 17 00:00:00 2001 From: rdimaio Date: Fri, 20 Dec 2024 21:36:51 +0100 Subject: [PATCH 5/9] Add test with ill-formed cfg --- test/test.bats | 9 +++++++++ test/testdata/.badcfg | 1 + 2 files changed, 10 insertions(+) create mode 100644 test/testdata/.badcfg diff --git a/test/test.bats b/test/test.bats index 119bc5b..a4f05c8 100644 --- a/test/test.bats +++ b/test/test.bats @@ -94,6 +94,15 @@ function setup() { [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } +@test "Pass an ill-formed file to INPUT_CONFIG" { + # codespell's exit status is 78 for a configparser.Error exception + expectedExitStatus=78 + INPUT_CONFIG="./test/testdata/.badcfg" + run "./entrypoint.sh" + [ $status -eq $expectedExitStatus ] +} +} + @test "Use an exclude file" { errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT)) # codespell's exit status is 0, or 65 if there are errors found diff --git a/test/testdata/.badcfg b/test/testdata/.badcfg new file mode 100644 index 0000000..e810594 --- /dev/null +++ b/test/testdata/.badcfg @@ -0,0 +1 @@ +foobar = From 71e9c0635b74bcf8cbcf59cb9b5d7fe3403c13cd Mon Sep 17 00:00:00 2001 From: rdimaio Date: Fri, 20 Dec 2024 21:41:59 +0100 Subject: [PATCH 6/9] Add INPUT_CONFIG test with non-existing file --- test/test.bats | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test.bats b/test/test.bats index a4f05c8..e133f00 100644 --- a/test/test.bats +++ b/test/test.bats @@ -101,6 +101,23 @@ function setup() { run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] } + +@test "Pass a non-existing file to INPUT_CONFIG" { + errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) + # codespell's exit status is 0, or 65 if there are errors found + if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi + INPUT_CONFIG="./foo" + run "./entrypoint.sh" + [ $status -eq $expectedExitStatus ] + + # Check output + [ "${lines[0]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] + outputRegex="^Running codespell on '${INPUT_PATH}'" + [[ "${lines[1]}" =~ $outputRegex ]] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] + [ "${lines[-3]}" == "Codespell found one or more problems" ] + [ "${lines[-2]}" == "::remove-matcher owner=codespell-matcher-default::" ] + [ "${lines[-1]}" == "::remove-matcher owner=codespell-matcher-specified::" ] } @test "Use an exclude file" { From 680ddca8eda39020a660c1964b35687fa85700d8 Mon Sep 17 00:00:00 2001 From: rdimaio Date: Fri, 20 Dec 2024 21:42:23 +0100 Subject: [PATCH 7/9] Add INPUT_CONFIG test with valid file --- test/test.bats | 18 ++++++++++++++++++ test/testdata/.goodcfg | 1 + 2 files changed, 19 insertions(+) create mode 100644 test/testdata/.goodcfg diff --git a/test/test.bats b/test/test.bats index e133f00..4e91b8a 100644 --- a/test/test.bats +++ b/test/test.bats @@ -120,6 +120,24 @@ function setup() { [ "${lines[-1]}" == "::remove-matcher owner=codespell-matcher-specified::" ] } +@test "Pass a valid file to INPUT_CONFIG" { + errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) + # codespell's exit status is 0, or 65 if there are errors found + if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi + INPUT_CONFIG="./test/testdata/.goodcfg" + run "./entrypoint.sh" + [ $status -eq $expectedExitStatus ] + + # Check output + [ "${lines[0]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] + outputRegex="^Running codespell on '${INPUT_PATH}'" + [[ "${lines[1]}" =~ $outputRegex ]] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] + [ "${lines[-3]}" == "Codespell found one or more problems" ] + [ "${lines[-2]}" == "::remove-matcher owner=codespell-matcher-default::" ] + [ "${lines[-1]}" == "::remove-matcher owner=codespell-matcher-specified::" ] +} + @test "Use an exclude file" { errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT)) # codespell's exit status is 0, or 65 if there are errors found diff --git a/test/testdata/.goodcfg b/test/testdata/.goodcfg new file mode 100644 index 0000000..60bbe06 --- /dev/null +++ b/test/testdata/.goodcfg @@ -0,0 +1 @@ +[codespell] From c34a8d7c5c2e7f4198a04cd7375d9ecc544ec894 Mon Sep 17 00:00:00 2001 From: rdimaio Date: Fri, 20 Dec 2024 21:43:50 +0100 Subject: [PATCH 8/9] Fix entrypoint --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 7bc77f9..10b5a43 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -43,6 +43,7 @@ fi echo "Ignore URI words list '${INPUT_URI_IGNORE_WORDS_LIST}'" if [ "x${INPUT_URI_IGNORE_WORDS_LIST}" != "x" ]; then command_args="${command_args} --uri-ignore-words-list ${INPUT_URI_IGNORE_WORDS_LIST}" +fi echo "Skipping '${INPUT_SKIP}'" if [ "x${INPUT_SKIP}" != "x" ]; then command_args="${command_args} --skip ${INPUT_SKIP}" From 577be562098e6f3ddb44948097b04a4674c0a264 Mon Sep 17 00:00:00 2001 From: rdimaio Date: Fri, 20 Dec 2024 21:53:16 +0100 Subject: [PATCH 9/9] Initialize INPUT_CONFIG before each test --- test/test.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test.bats b/test/test.bats index 4e91b8a..80536a4 100644 --- a/test/test.bats +++ b/test/test.bats @@ -39,6 +39,7 @@ function setup() { export INPUT_EXCLUDE_FILE="" export INPUT_SKIP="" export INPUT_BUILTIN="" + export INPUT_CONFIG="" export INPUT_IGNORE_WORDS_FILE="" export INPUT_IGNORE_WORDS_LIST="" export INPUT_URI_IGNORE_WORDS_LIST=""