Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the config file option and tests #80

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -10,16 +14,12 @@ inputs:
description: 'If set, check hidden files (those starting with ".") as well'
required: false
default: ''
exclude_file:
description: 'File with lines that should not be checked for spelling mistakes'
config:
description: 'Path to a codespell config file'
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'
exclude_file:
description: 'File with lines that should not be checked for spelling mistakes'
required: false
default: ''
ignore_words_file:
Expand All @@ -38,6 +38,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
Expand Down
20 changes: 12 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,18 +24,14 @@ 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}"
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}"
Expand All @@ -44,6 +44,10 @@ 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}"
fi
echo "Resulting CLI options ${command_args}"
exec 5>&1
res=`{ { codespell --count ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; } 4>&1`
Expand Down
45 changes: 45 additions & 0 deletions test/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down Expand Up @@ -94,6 +95,50 @@ 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 "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 "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
Expand Down
1 change: 1 addition & 0 deletions test/testdata/.badcfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar =
1 change: 1 addition & 0 deletions test/testdata/.goodcfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[codespell]