Skip to content

Commit

Permalink
Switch handling of spell check errors (#486)
Browse files Browse the repository at this point in the history
* Switch handling of spell check errors

* Add extra empty line

* Fix data.frame handling in spell-check.R

* Rearrange some files for spell check

* Add a || echo "No changes to commit"
  • Loading branch information
cansavvy authored Mar 1, 2022
1 parent 54654d5 commit b4f83b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ jobs:
run: |
results=$(Rscript "scripts/spell-check.R")
echo "::set-output name=sp_chk_results::$results"
cat resources/spell_check_results.tsv
- name: Archive spelling errors
if: ${{ steps.spell_check_run.outputs.sp_chk_results > 0 }}
uses: actions/upload-artifact@v2
with:
name: spell-check-results
Expand All @@ -98,7 +98,7 @@ jobs:
- name: Commit spell check errors
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git add --force resources/spell_check_results.tsv
git add --force resources/spell_check_results.tsv || echo "No changes to commit"
git commit -m 'Add spell check file' || echo "No changes to commit"
git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
git push --force origin $branch_name || echo "No changes to commit"
Expand Down
14 changes: 10 additions & 4 deletions scripts/spell-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ files <- grep("About.Rmd", files, ignore.case = TRUE, invert = TRUE, value = TRU
files <- grep("style-sets", files, ignore.case = TRUE, invert = TRUE, value = TRUE)

# Run spell check
sp_errors <- spelling::spell_check_files(files, ignore = dictionary) %>%
data.frame() %>%
tidyr::unnest(cols = found) %>%
tidyr::separate(found, into = c("file", "lines"), sep = ":")
sp_errors <- spelling::spell_check_files(files, ignore = dictionary)

if (nrow(sp_errors) > 0) {
sp_errors <- sp_errors %>%
data.frame() %>%
tidyr::unnest(cols = found) %>%
tidyr::separate(found, into = c("file", "lines"), sep = ":")
}

# Print out how many spell check errors
write(nrow(sp_errors), stdout())
Expand All @@ -45,5 +49,7 @@ if (!dir.exists("resources")) {
dir.create("resources")
}

if (nrow(sp_errors) > 0) {
# Save spell errors to file temporarily
readr::write_tsv(sp_errors, file.path('resources', 'spell_check_results.tsv'))
}

0 comments on commit b4f83b2

Please sign in to comment.