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 usage to readme and test image #5

Merged
merged 8 commits into from
Mar 8, 2024
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
tags:
- "v*"
pull_request:
branches:
- main
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
on: [push]
on:
- workflow_dispatch

jobs:
spell-check:
Expand All @@ -10,7 +11,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Spell check action
uses: ./ # Uses an action in the root directory
uses: ./ # Uses the action in the root directory
id: spell
# Use the output from the `spell check` step
- name: Get the number of errors
Expand Down
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
# spellcheck

This repository contains a Docker image with the [R `spelling` package](https://cran.r-project.org/web/packages/spelling/index.html) installed.
The role of this repository is to facilitate spell checking actions across `AlexsLemonade` repositories.
This repository contains a GitHub action to run the [R `spelling` package](https://cran.r-project.org/web/packages/spelling/index.html).
The role of this action is to facilitate spell checking actions across `AlexsLemonade` repositories.

speeling
Currently the action will only spell check text in Rmd and md files

## Usage

To use this action, create a `.github/workflows/spellcheck.yml` file in your repository with the following contents (modified to fit your exact needs):

```yaml
name: Check Spelling
on:
pull_request:
branches:
- main

jobs:
spell-check:
runs-on: ubuntu-latest
name: Spell check files
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Spell check action
uses: alexslemonade/spellcheck
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is this does not work because it needs a tag, but it does work with alexslemonade/spellcheck@main.

Easy enough to pop in when we decide on the tag, which we can do in this PR or after.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some fixes, so I think the move is going to be to merge this PR, tag a release, then update a couple things in a new PR.

id: spell
with:
dictionary: components/dictionary.txt

- name: Upload spell check errors
uses: actions/upload-artifact@v4
with:
name: spell_check_errors
path: spell_check_errors.tsv

- name: Fail if there are spelling errors
if: steps.spell.outputs.error_count > 0
run: |
echo "There were ${{ steps.spell.outputs.error_count }} errors"
exit 1
```

Note that the `dictionary` input to the spell check step is optional and defaults to `components/dictionary.txt`.
If you want to use a different dictionary, you can specify the path to the dictionary file in your repository.

You can also specify specific files to spell check using the `files` input to the `alexslemonade/spellcheck` step.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but it's b/c of a bug:

if (length(arguments) > 1) {

Should be >0, not >1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you pass in files, you have to pass in dictionary. Otherwise the script as written will interpret the files argument as the dictionary file.

Copy link
Member Author

@jashapiro jashapiro Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to be handled by the fact that the arguments are named in the context of the action. So inputs.dictionary should get a default value if it is not provided. Was that not the case?

I added a fix in case an empty string is given, but if you use

with:
  files: test-file.md

I would expect the dictionary to be populated with the default value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So inputs.dictionary should get a default value if it is not provided. Was that not the case?

I did not test this actually - this is just my sense of looking at the R code directly. Let me check formally..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the dictionary to be populated with the default value

Confirmed, as expected!

Globs should work as expected.
16 changes: 8 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# action.yml
name: 'R spell check'
description: 'Spell check R, Rmd and md files'
name: "R spell check"
description: "Spell check R, Rmd and md files"
inputs:
dictionary: # id of input
description: 'Dictionary file path'
dictionary: # id of input
description: "Dictionary file path"
required: true
default: 'components/dictionary.txt'
default: "components/dictionary.txt"
files:
description: Glob of files to check
required: false
outputs:
error_count:
description: The number of spelling errors
runs:
using: 'docker'
image: 'Dockerfile'
using: "docker"
image: ghcr.io/alexslemonade/spellcheck:edge
args:
- ${{ inputs.dictionary }}
- ${{ inputs.dictionary || '/dev/null' }}
- ${{ inputs.files }}
2 changes: 1 addition & 1 deletion spell-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dict_file <- arguments[1]

arguments <- arguments[-1]
# if there are arguments, check those files, otherwise check all markdown & rmd files
if (length(arguments) > 1) {
if (length(arguments) > 0) {
files <- arguments[grepl(file_pattern, arguments)]
} else {
files <- list.files(pattern = file_pattern, recursive = TRUE, full.names = TRUE)
Expand Down
Loading