diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 387976b..e89f677 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -1,42 +1,47 @@ +name: Spell check R Markdown and Markdown files -name: Spell check Markdown files - -# Controls when the action will run. -# Pull requests to main only. on: pull_request: branches: - main +concurrency: + # only one run per branch at a time + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - # This workflow contains a single job called "spell check" - spell-check: + spellcheck: runs-on: ubuntu-latest - container: - image: rocker/tidyverse:4.2.3 + name: Spell check files + permissions: + contents: read + issues: write - # Steps represent a sequence of tasks that will be executed as part of the job steps: - - uses: actions/checkout@v3 - - - name: Install packages - run: Rscript --vanilla -e "install.packages(c('spelling'), repos = c(CRAN = '$CRAN'))" + - name: Checkout + uses: actions/checkout@v4 - - name: Run spell check - id: spell_check_run + - name: Remove files that do not need to be spellchecked run: | - results=$(Rscript --vanilla "scripts/spell-check.R") - echo "sp_chk_results=$results" >> $GITHUB_OUTPUT - cat spell_check_errors.tsv + rm ./LICENSE.md - - name: Archive spelling errors - uses: actions/upload-artifact@v3 - if: ${{ steps.spell_check_run.outputs.sp_chk_results > 0 }} + - name: Spell check action + uses: alexslemonade/spellcheck@v0 + id: spell with: - name: spell-check-results + dictionary: components/dictionary.txt + + - name: Upload spell check errors + uses: actions/upload-artifact@v4 + id: artifact-upload-step + with: + name: spell_check_errors path: spell_check_errors.tsv - # If there are too many spelling errors, this will stop the workflow - - name: Check spell check results - fail if too many errors - if: ${{ steps.spell_check_run.outputs.sp_chk_results > 0 }} - run: exit 1 + - name: Fail if there are spelling errors + if: steps.spell.outputs.error_count > 0 + run: | + echo "There were ${{ steps.spell.outputs.error_count }} errors" + column -t spell_check_errors.tsv + exit 1 diff --git a/components/dictionary.txt b/components/dictionary.txt index eb6a68c..52b922a 100644 --- a/components/dictionary.txt +++ b/components/dictionary.txt @@ -1,3 +1,4 @@ +⚠️ ableist al Alevin diff --git a/scripts/spell-check.R b/scripts/spell-check.R deleted file mode 100644 index 789728e..0000000 --- a/scripts/spell-check.R +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env Rscript -# -# Run spell check and save results -# Adapted from: https://github.com/AlexsLemonade/training-modules/blob/72621ada8ecffc524e7fbbee78172dca9d0f5c85/scripts/spell-check.R - -# Find .git root directory -root_dir <- rprojroot::find_root(rprojroot::has_dir(".git")) - -# Read in dictionary -dictionary <- readLines(file.path(root_dir, 'components', 'dictionary.txt')) - -# Add emoji to dictionary -dictionary <- c(dictionary, - spelling::spell_check_text("⚠️")$word, - spelling::spell_check_text("🎉")$word -) - -# The only files we want to check are Markdown files -files <- list.files(pattern = '\\.md$', recursive = TRUE, full.names = TRUE) - -# Remove the LICENSE from the spell check -files <- grep('LICENSE.md', files, invert = TRUE, value = TRUE) - -# Run spell check -spelling_errors <- spelling::spell_check_files(files, ignore = dictionary) |> - data.frame() |> - tidyr::unnest(cols = found) |> - tidyr::separate(found, into = c("file", "lines"), sep = ":") - -# Print out how many spell check errors -write(nrow(spelling_errors), stdout()) - -# Save spell errors to file temporarily -readr::write_tsv(spelling_errors, 'spell_check_errors.tsv')