Skip to content

Commit d5aba66

Browse files
authored
Merge pull request #219 from rojopolis/issue213
Addressing issue 213
2 parents 7ff888c + a2bc6f1 commit d5aba66

File tree

5 files changed

+128
-8
lines changed

5 files changed

+128
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log for spellcheck-github-actions
22

3+
## 0.43.1, 2024-10-17, bug fix release, update recommended
4+
5+
- 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.
6+
7+
- Issue [#213](https://github.com/rojopolis/spellcheck-github-actions/issues/213)
8+
39
## 0.43.0, 2024-10-08, maintenance release, update not required
410

511
- 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)

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ LABEL "com.github.actions.description"="Check spelling of files in repository"
66
LABEL "com.github.actions.icon"="clipboard"
77
LABEL "com.github.actions.color"="green"
88
LABEL "repository"="http://github.com/rojopolis/spellcheck-github-actions"
9-
LABEL "homepage"="http://github.com/actions"
9+
LABEL "homepage"="https://github.com/marketplace/actions/github-spellcheck-action"
1010
LABEL "maintainer"="rojopolis <[email protected]>"
1111

1212
COPY entrypoint.sh /entrypoint.sh
1313
COPY requirements.txt /requirements.txt
1414
COPY constraint.txt /constraint.txt
1515
COPY spellcheck.yaml /spellcheck.yaml
16+
COPY pwc.py /pwc.py
1617

1718
ENV PIP_CONSTRAINT=/constraint.txt
1819
RUN pip3 install -r /requirements.txt

entrypoint.sh

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ SPLIT=false
3131

3232
if [ -n "$INPUT_SOURCE_FILES" ]; then
3333

34+
echo "Source files to check: >$INPUT_SOURCE_FILES<"
35+
3436
if grep -q $SINGLE <<< "$INPUT_SOURCE_FILES"; then
3537
OIFS=$IFS
3638
IFS=$SINGLE
@@ -58,6 +60,15 @@ if [ -n "$INPUT_SOURCE_FILES" ]; then
5860

5961
for FILE in "${arr[@]}"; do
6062

63+
echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE"
64+
65+
PATTERN_MATCH_EXITCODE=$?
66+
67+
if [ $PATTERN_MATCH_EXITCODE -eq 1 ]; then
68+
echo "Skipping file >$FILE<"
69+
continue
70+
fi
71+
6172
# Skip null items
6273
if [ -z "$FILE" ]; then
6374
continue
@@ -79,34 +90,59 @@ if [ -n "$INPUT_SOURCE_FILES" ]; then
7990
read -r -a arr <<< "$INPUT_SOURCE_FILES"
8091

8192
for FILE in "${arr[@]}"; do
93+
echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE"
94+
95+
PATTERN_MATCH_EXITCODE=$?
96+
97+
if [ $PATTERN_MATCH_EXITCODE -eq 1 ]; then
98+
echo "Skipping file >$FILE<"
99+
continue
100+
fi
82101
SOURCES_LIST="$SOURCES_LIST --source $FILE"
83102
echo "Checking file >$FILE<"
84103
done
85104
fi
86105

106+
echo "Checking files specification in sources_list as: >$SOURCES_LIST<"
107+
87108
else
88-
echo "Checking files matching specified outlined in >$SPELLCHECK_CONFIG_FILE<"
109+
echo "Checking files matching specification outlined in: >$SPELLCHECK_CONFIG_FILE<"
89110
fi
90111

91112
if [ -n "$INPUT_TASK_NAME" ]; then
92113
TASK_NAME="--name $INPUT_TASK_NAME"
93114
fi
94115

95-
echo "----------------------------------------------------------------"
96-
97116
EXITCODE=0
98117

99118
# shellcheck disable=SC2086
100-
if [ -n "$INPUT_OUTPUT_FILE" ]; then
119+
if [ -n "$INPUT_OUTPUT_FILE" ] && [ -n "$SOURCES_LIST" ]; then
101120
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME $SOURCES_LIST | tee "$INPUT_OUTPUT_FILE"
102121
EXITCODE=${PIPESTATUS[0]}
103-
else
122+
elif [ -n "$INPUT_OUTPUT_FILE" ]; then
123+
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME | tee "$INPUT_OUTPUT_FILE"
124+
EXITCODE=${PIPESTATUS[0]}
125+
elif [ -n "$SOURCES_LIST" ]; then
104126
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME $SOURCES_LIST
105127
EXITCODE=$?
128+
elif [ -z "$INPUT_SOURCE_FILES" ]; then
129+
pyspelling --verbose --config "$SPELLCHECK_CONFIG_FILE" $TASK_NAME
130+
EXITCODE=$?
131+
else
132+
echo "No files to check, exiting"
133+
EXITCODE=0
106134
fi
107135

108-
test "$EXITCODE" -gt 1 && echo "::error title=Spelling check::Spelling check action failed, please check diagnostics";
136+
echo "----------------------------------------------------------------"
137+
138+
if [ -n "$GITHUB_ACTIONS" ]; then
139+
test "$EXITCODE" -gt 1 && echo "::error title=Spelling check::Spelling check action failed, please check diagnostics";
109140

110-
test "$EXITCODE" -eq 1 && echo "::error title=Spelling errors::Files in repository contain spelling errors";
141+
test "$EXITCODE" -eq 1 && echo "::error title=Spelling errors::Files in repository contain spelling errors";
142+
else
143+
test "$EXITCODE" -gt 1 && echo "Spelling check action failed, please check diagnostics";
144+
145+
test "$EXITCODE" -eq 1 && echo "Files in repository contain spelling errors";
146+
fi
111147

112148
exit "$EXITCODE"

pwc.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!python3
2+
3+
# This little helper script was implemented to extract the sources from the spellcheck configuration file
4+
# The name pwc comes from Python WCMatch, which is used to match the files against the sources
5+
# That is the short name I call it PriceWaterhouseCoopers, since it revises the file listing
6+
7+
# read file and interpret it as yaml
8+
def read_yaml(file):
9+
10+
with open(file) as f:
11+
data = yaml.safe_load(f)
12+
return data
13+
14+
import sys
15+
import yaml
16+
from wcmatch import glob
17+
18+
# read filename from command line as first argument
19+
spellcheck_configuration_file = sys.argv[1]
20+
21+
data = read_yaml(spellcheck_configuration_file)
22+
23+
# fetch the sources from the YAML data
24+
sources = data.get('matrix')[0].get('sources')
25+
26+
for changed_file in sys.stdin:
27+
if 'q' == changed_file.rstrip():
28+
break
29+
changed_file = changed_file.rstrip()
30+
31+
matched = glob.globmatch(changed_file, sources, flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)
32+
33+
if matched:
34+
exit(0)
35+
else:
36+
exit(1)

test/test.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@test "can do basic run using Docker image with two input files" {
2+
docker run -e INPUT_SOURCE_FILES="README.md CHANGELOG.md" \
3+
-e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \
4+
jonasbn/github-action-spellcheck:local
5+
}
6+
7+
@test "can do basic run using Docker image with unignored and ignored input files" {
8+
docker run -e INPUT_SOURCE_FILES="README.md venv/lib/python3.13/site-packages/pyspelling-2.10.dist-info/licenses/LICENSE.md" \
9+
-e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \
10+
jonasbn/github-action-spellcheck:local
11+
}
12+
13+
@test "can do basic run using Docker image with just ignored input file" {
14+
docker run -e INPUT_SOURCE_FILES="venv/lib/python3.13/site-packages/pyspelling-2.10.dist-info/licenses/LICENSE.md" \
15+
-e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \
16+
jonasbn/github-action-spellcheck:local
17+
}
18+
19+
@test "can do basic run using Docker image without any input files" {
20+
docker run \
21+
-e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \
22+
jonasbn/github-action-spellcheck:local
23+
}
24+
25+
@test "can do basic run using Docker image without task parameter" {
26+
docker run \
27+
-it -v $PWD:/tmp \
28+
jonasbn/github-action-spellcheck:local
29+
}
30+
31+
@test "can do basic run using Docker image with two input files but not task parameter" {
32+
! docker run -e INPUT_SOURCE_FILES="README.md CHANGELOG.md" \
33+
-it -v $PWD:/tmp \
34+
jonasbn/github-action-spellcheck:local
35+
}
36+
37+
@test "can do basic run using Docker image with two non-existing input files" {
38+
! docker run -e INPUT_SOURCE_FILES="DONOTREADME.md LOGCHANGE.md" \
39+
-e INPUT_TASK_NAME=Markdown -it -v $PWD:/tmp \
40+
jonasbn/github-action-spellcheck:local
41+
}

0 commit comments

Comments
 (0)