From b4f83b22fbaafbe66b9f01852268b8de867d9008 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 1 Mar 2022 11:42:47 -0500 Subject: [PATCH] Switch handling of spell check errors (#486) * 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" --- .github/workflows/pull_request.yml | 4 ++-- scripts/spell-check.R | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c71bdc73..783bd519 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -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 @@ -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" diff --git a/scripts/spell-check.R b/scripts/spell-check.R index b484dac1..d3596a8d 100644 --- a/scripts/spell-check.R +++ b/scripts/spell-check.R @@ -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()) @@ -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')) +}