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

Setup the repo #1

Merged
merged 22 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
43 changes: 43 additions & 0 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and push spellcheck image

on:
push:
branches:
- main
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

env:
REGISTRY: ghcr.io
IMAGE_NAME: alexslemonade/spellcheck

jobs:
build_and_push:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
Copy link
Member

Choose a reason for hiding this comment

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

Update to latest version to quiet a warning

Suggested change
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5

with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{raw}}
type=edge,branch=main

- name: Build and push to Docker
uses: docker/build-push-action@v5
with:
push: true
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# A docker file for establishing a spellcheck environment in R
FROM rocker/r-ver:4.3.2

# Labels following the Open Containers Initiative (OCI) recommendations
# For more information, see https://specs.opencontainers.org/image-spec/annotations/?v=v1.0.1
LABEL org.opencontainers.image.authors="CCDL [email protected]"
LABEL org.opencontainers.image.source="https://github.com/AlexsLemonade/spellcheck/tree/main"

# install the spelling and tidyr packages from CRAN
RUN Rscript -e "install.packages(c('spelling', 'tidyr'))"

# add spell check script and make it executable
COPY spelling.R /usr/local/bin/spell-check.R
RUN chmod +x /usr/local/bin/spell-check.R
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# spellcheck
This repository contains a Docker image with the R spelling package

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.

34 changes: 34 additions & 0 deletions spell-check.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env Rscript
#
# Run spell check and save results.
# By default, all R Markdown and markdown files will be checked.
# To modify this behavior, provide a command-line argument with the extensions to check.

arguments <- commandArgs(trailingOnly = TRUE)
file_pattern <- "\\.(Rmd|md|rmd)$"

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

# Find .git root directory
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))

# Read in dictionary
dict_file <- file.path(root_dir, "components", "dictionary.txt")
dictionary <- readLines(dict_file)

# Run spell check
spelling_errors <- spelling::spell_check_files(files, ignore = dictionary_plus) |>
Copy link
Member

Choose a reason for hiding this comment

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

you didn't define dictionary_plus?

Copy link
Member Author

Choose a reason for hiding this comment

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

copy/paste fail 😞

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
readr::write_tsv(spelling_errors, "spell_check_errors.tsv")
sjspielman marked this conversation as resolved.
Show resolved Hide resolved