DEV Community

Jonas Brømsø
Jonas Brømsø

Posted on

Release 0.43.1 of Spellcheck (GitHub) Action - a bug fix release

As mentioned in my previous release announcement of the Spellcheck (GitHub) Action, a bug had surfaced.

I have recently released version 0.43.1 with a fix.

Now let me go into some more details on the fix.

As I introduced using the Spellcheck action in combination with the GitHub Action: tj-actions/changed-files to process on the changed files I introduced a bug.

As pointed out in issue: #213. The source_files parameter does not play nicely with the PySpelling configuration file pattern specification.

An example configuration lifted from: jonasbn/TIL.

sources:
  - '!_site/*.md|!osx/list_available_voices_for_speechsynthesis.md|!clang/diagnostic_flags.md|!.wordlist.txt|!*.yml|!*.yaml|*/*.md|README.md'
Enter fullscreen mode Exit fullscreen mode

Using in combination with an action workflow like the one below. lifted from: jonasbn/TIL.

    - name: Get all changed markdown files
      uses: tj-actions/changed-files@v45
      id: changed_files
      with:
        files: |
           **.md

    - name: Run Spellcheck
      id: spellcheck
      uses: rojopolis/spellcheck-github-actions@v0
      with:
        task_name: Markdown
        source_files: ${{ steps.changed_files.outputs.all_changed_files }}
Enter fullscreen mode Exit fullscreen mode

The files indicated as changed by tj-actions/changed-files would be fed to PySpelling by the Spellcheck action using the command line option: --source indicating each file separately and as mentioned in the PySpelling documentation:

    --source SOURCE, -S SOURCE
    Specify override file pattern. Only applicable when specifying exactly one --name.
Enter fullscreen mode Exit fullscreen mode

And as stated this overrides the file pattern and so the filtering out of files etc. does apply.

After doing some thinking about the problem, I came to the conclusion that I somehow needed to apply the file pattern to the files listed. The author of PySpelling was looking into a possible solution in PySPelling, but in my opinion this problem was very much on the side of the action not in PySpelling (and it was introduced by me).

So I wanted to implement a basic filter. Based on the reading the configuration. PySpelling is using wcmatch and therefor support it's syntax to matching files and handle the patterns, so I decided that I wanted to keep the filter implementation in the same language as PySpelling.

I ended up writing a small Python script pwc.py that is now using in the action and it reads the configuration and applies the file patters to the files being fed by tj-actions/changed-files and files fed in in general.

I am not a Python developer, so there might be a better approach, well there might be a better approach to addressing the issue all together, but this is what I came up with and which is included in 0.43.1.

#!python3

# This little helper script was implemented to extract the sources from the spellcheck configuration file
# The name pwc comes from Python WCMatch, which is used to match the files against the sources

# 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
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')

for changed_file in sys.stdin:
    if 'q' == changed_file.rstrip():
        break
    changed_file = changed_file.rstrip()

    matched = glob.globmatch(changed_file, sources, flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)

    if matched:
        exit(0)
    else:
        exit(1)
Enter fullscreen mode Exit fullscreen mode

REF: pwc.py

The script is used in the entry point of the Docker image, like so:

echo "$FILE" | python3 /pwc.py "$SPELLCHECK_CONFIG_FILE"
Enter fullscreen mode Exit fullscreen mode

REF: entrypoint.sh

And now the configured filter is applied to filed being fed to PySpelling prior to the overwriting, so configuration for leaving out files are now respected instead of just being fed to PySpelling using the --source command line option.

There are a lot of challenges in regard to the implementation so let's see what surfaces in the wake of the release, but my tests and own use work as expected.

The action is available on the GitHub Marketplace.

Top comments (0)