From 9a68f32108b68a20ee06bffeddc37ca396ece944 Mon Sep 17 00:00:00 2001 From: jonasbn Date: Sun, 13 Oct 2024 18:41:01 +0200 Subject: [PATCH 1/6] Initial version, need some cleaning --- pwc.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 pwc.py diff --git a/pwc.py b/pwc.py new file mode 100755 index 00000000..e3622595 --- /dev/null +++ b/pwc.py @@ -0,0 +1,41 @@ +#!python3 + +# read file and interpret it as yaml +def read_yaml(file): + + with open(file) as f: + data = yaml.safe_load(f) + return data + +import sys +import yaml +#import pprint +from wcmatch import glob + +# read filename from command line as first argument +spellcheck_configuration_file = sys.argv[1] + +data = read_yaml(spellcheck_configuration_file) + +# fetch the sources from the YAML data +sources = data.get('matrix')[0].get('sources') + +# print the sources from the YAML data +#pprint.pprint(sources) + +for changed_file in sys.stdin: + if 'q' == changed_file.rstrip(): + break + changed_file = changed_file.rstrip() + #print(f'Input : {changed_file}') + + matched = glob.globmatch(changed_file, sources, flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT) + + if matched: + #print("Matched file:", changed_file) + exit(0) + else: + #print("No match for file:", changed_file) + exit(1) + +#pprint.pprint(files) From da58a22070e3bf0030b32bc9f936f3ab3c3a4abc Mon Sep 17 00:00:00 2001 From: jonasbn Date: Sun, 13 Oct 2024 18:41:35 +0200 Subject: [PATCH 2/6] Changed the homepage, so the marketplace --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c6cdf5e4..5da81630 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,13 +6,14 @@ LABEL "com.github.actions.description"="Check spelling of files in repository" LABEL "com.github.actions.icon"="clipboard" LABEL "com.github.actions.color"="green" LABEL "repository"="http://github.com/rojopolis/spellcheck-github-actions" -LABEL "homepage"="http://github.com/actions" +LABEL "homepage"="https://github.com/marketplace/actions/github-spellcheck-action" LABEL "maintainer"="rojopolis " COPY entrypoint.sh /entrypoint.sh COPY requirements.txt /requirements.txt COPY constraint.txt /constraint.txt COPY spellcheck.yaml /spellcheck.yaml +COPY pwc.py /pwc.py ENV PIP_CONSTRAINT=/constraint.txt RUN pip3 install -r /requirements.txt From d0488b282d57387947edfe54ef177e65a96ff475 Mon Sep 17 00:00:00 2001 From: jonasbn Date: Sun, 13 Oct 2024 18:42:40 +0200 Subject: [PATCH 3/6] Adopted use of pwc.py and cleaned up in processing to handle this new use case, see #213 --- entrypoint.sh | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8d23f641..5a047d9c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -31,6 +31,8 @@ SPLIT=false if [ -n "$INPUT_SOURCE_FILES" ]; then + echo "Source files to check: >$INPUT_SOURCE_FILES<" + if grep -q $SINGLE <<< "$INPUT_SOURCE_FILES"; then OIFS=$IFS IFS=$SINGLE @@ -58,6 +60,15 @@ if [ -n "$INPUT_SOURCE_FILES" ]; then for FILE in "${arr[@]}"; do + echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE" + + PATTERN_MATCH_EXITCODE=$? + + if [ $PATTERN_MATCH_EXITCODE -eq 1 ]; then + echo "Skipping file >$FILE<" + continue + fi + # Skip null items if [ -z "$FILE" ]; then continue @@ -79,34 +90,59 @@ if [ -n "$INPUT_SOURCE_FILES" ]; then read -r -a arr <<< "$INPUT_SOURCE_FILES" for FILE in "${arr[@]}"; do + echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE" + + PATTERN_MATCH_EXITCODE=$? + + if [ $PATTERN_MATCH_EXITCODE -eq 1 ]; then + echo "Skipping file >$FILE<" + continue + fi SOURCES_LIST="$SOURCES_LIST --source $FILE" echo "Checking file >$FILE<" done fi + echo "Checking files specification in sources_list as: >$SOURCES_LIST<" + else - echo "Checking files matching specified outlined in >$SPELLCHECK_CONFIG_FILE<" + echo "Checking files matching specification outlined in: >$SPELLCHECK_CONFIG_FILE<" fi if [ -n "$INPUT_TASK_NAME" ]; then TASK_NAME="--name $INPUT_TASK_NAME" fi -echo "----------------------------------------------------------------" - EXITCODE=0 # shellcheck disable=SC2086 -if [ -n "$INPUT_OUTPUT_FILE" ]; then +if [ -n "$INPUT_OUTPUT_FILE" ] && [ -n "$SOURCES_LIST" ]; then pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME $SOURCES_LIST | tee "$INPUT_OUTPUT_FILE" EXITCODE=${PIPESTATUS[0]} -else +elif [ -n "$INPUT_OUTPUT_FILE" ]; then + pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME | tee "$INPUT_OUTPUT_FILE" + EXITCODE=${PIPESTATUS[0]} +elif [ -n "$SOURCES_LIST" ]; then pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME $SOURCES_LIST EXITCODE=$? +elif [ -z "$INPUT_SOURCE_FILES" ]; then + pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME + EXITCODE=$? +else + echo "No files to check, exiting" + EXITCODE=0 fi -test "$EXITCODE" -gt 1 && echo "::error title=Spelling check::Spelling check action failed, please check diagnostics"; +echo "----------------------------------------------------------------" + +if [ -n "$GITHUB_ACTIONS" ]; then + test "$EXITCODE" -gt 1 && echo "::error title=Spelling check::Spelling check action failed, please check diagnostics"; -test "$EXITCODE" -eq 1 && echo "::error title=Spelling errors::Files in repository contain spelling errors"; + test "$EXITCODE" -eq 1 && echo "::error title=Spelling errors::Files in repository contain spelling errors"; +else + test "$EXITCODE" -gt 1 && echo "Spelling check action failed, please check diagnostics"; + + test "$EXITCODE" -eq 1 && echo "Files in repository contain spelling errors"; +fi exit "$EXITCODE" From 3aaf2627e00aae00c86d13ee4067a706ec69b274 Mon Sep 17 00:00:00 2001 From: jonasbn Date: Sun, 13 Oct 2024 18:45:07 +0200 Subject: [PATCH 4/6] Cleaned and added documentation --- pwc.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pwc.py b/pwc.py index e3622595..a9892866 100755 --- a/pwc.py +++ b/pwc.py @@ -1,5 +1,9 @@ #!python3 +# This little helper script was implemented to extract the sources from the spellcheck configuration file +# The name comes from Python WCMatch, which is used to match the files against the sources +# That is the short name I call it PriceWaterhouseCoopers, since it revises the file listing + # read file and interpret it as yaml def read_yaml(file): @@ -9,7 +13,6 @@ def read_yaml(file): import sys import yaml -#import pprint from wcmatch import glob # read filename from command line as first argument @@ -20,22 +23,14 @@ def read_yaml(file): # fetch the sources from the YAML data sources = data.get('matrix')[0].get('sources') -# print the sources from the YAML data -#pprint.pprint(sources) - for changed_file in sys.stdin: if 'q' == changed_file.rstrip(): break changed_file = changed_file.rstrip() - #print(f'Input : {changed_file}') matched = glob.globmatch(changed_file, sources, flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT) if matched: - #print("Matched file:", changed_file) exit(0) else: - #print("No match for file:", changed_file) exit(1) - -#pprint.pprint(files) From 7d3537ec63c79423e3073f6e01079a9bfec1d908 Mon Sep 17 00:00:00 2001 From: jonasbn Date: Thu, 17 Oct 2024 21:23:56 +0200 Subject: [PATCH 5/6] Minor addition to the documentation --- pwc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwc.py b/pwc.py index a9892866..65bd85ae 100755 --- a/pwc.py +++ b/pwc.py @@ -1,7 +1,7 @@ #!python3 # This little helper script was implemented to extract the sources from the spellcheck configuration file -# The name comes from Python WCMatch, which is used to match the files against the sources +# The name pwc comes from Python WCMatch, which is used to match the files against the sources # That is the short name I call it PriceWaterhouseCoopers, since it revises the file listing # read file and interpret it as yaml From a2bc6f17ca7cc25c0e8a0bbf1ec8441908e0235c Mon Sep 17 00:00:00 2001 From: jonasbn Date: Thu, 17 Oct 2024 22:09:16 +0200 Subject: [PATCH 6/6] Added some basic tests, more work to be done and preparing a bug fix release --- CHANGELOG.md | 6 ++++++ test/test.bats | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/test.bats diff --git a/CHANGELOG.md b/CHANGELOG.md index fe34eb20..63002c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log for spellcheck-github-actions +## 0.43.1, 2024-10-17, bug fix release, update recommended + +- This is an attempt at addressing the conflict between using the PySpelling `--source` parameter and the `sources` parameter in the PySpelling configuration file introduced by this action. With the recommendation of using the GitHub Action: [tj-actions/changed-files](https://github.com/marketplace/actions/changed-files), the use of the `--source` flag was adopted, but this bypasses the filtering mechanism, which can be enabled in the configuration file. The update recommendation is due to the fact that you might experience unwanted behaviour if your `sources` contain negated file patterns. The patch enables application of the configured filter to the source parameters, so the action can be used with the `--source` parameter and the `sources` configuration parameter in combination. + + - Issue [#213](https://github.com/rojopolis/spellcheck-github-actions/issues/213) + ## 0.43.0, 2024-10-08, maintenance release, update not required - Docker image updated to Python 3.12.7 slim via PR [#215](https://github.com/rojopolis/spellcheck-github-actions/pull/215) from Dependabot. [Release notes for Python 3.12.7](https://docs.python.org/release/3.12.7/whatsnew/changelog.html) diff --git a/test/test.bats b/test/test.bats new file mode 100644 index 00000000..dc4ddd30 --- /dev/null +++ b/test/test.bats @@ -0,0 +1,41 @@ +@test "can do basic run using Docker image with two input files" { + docker run -e INPUT_SOURCE_FILES="README.md CHANGELOG.md" \ + -e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +} + +@test "can do basic run using Docker image with unignored and ignored input files" { + docker run -e INPUT_SOURCE_FILES="README.md venv/lib/python3.13/site-packages/pyspelling-2.10.dist-info/licenses/LICENSE.md" \ + -e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +} + +@test "can do basic run using Docker image with just ignored input file" { + docker run -e INPUT_SOURCE_FILES="venv/lib/python3.13/site-packages/pyspelling-2.10.dist-info/licenses/LICENSE.md" \ + -e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +} + +@test "can do basic run using Docker image without any input files" { + docker run \ + -e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +} + +@test "can do basic run using Docker image without task parameter" { + docker run \ + -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +} + +@test "can do basic run using Docker image with two input files but not task parameter" { + ! docker run -e INPUT_SOURCE_FILES="README.md CHANGELOG.md" \ + -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +} + +@test "can do basic run using Docker image with two non-existing input files" { + ! docker run -e INPUT_SOURCE_FILES="DONOTREADME.md LOGCHANGE.md" \ + -e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \ + jonasbn/github-action-spellcheck:local +}