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 20 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
46 changes: 46 additions & 0 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and push spellcheck image

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

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: ${{ github.event.action == 'push' }
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on: [push]

jobs:
spell-check:
runs-on: ubuntu-latest
name: Test the spell check action
steps:
# To use this repository's private action,
# you must check out the repository
- name: Checkout
uses: actions/checkout@v4
- name: Spell check action
uses: ./ # Uses an action in the root directory
id: spell
# Use the output from the `spell check` step
- name: Get the number of errors
run: |
echo "There were ${{ steps.spell.outputs.error_count }} errors"
cat spell_check_errors.tsv
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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('readr', 'spelling', 'tidyr'))"

# add spell check script and make it executable
COPY spell-check.R /spell-check.R
RUN chmod +x /spell-check.R

ENTRYPOINT ["/spell-check.R"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# 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.

speeling
20 changes: 20 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# action.yml
name: 'R spell check'
description: 'Spell check R, Rmd and md files'
inputs:
dictionary: # id of input
description: 'Dictionary file path'
required: true
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'
args:
- ${{ inputs.dictionary }}
- ${{ inputs.files }}
39 changes: 39 additions & 0 deletions spell-check.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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)$"

# dictionary is required first argument
dict_file <- arguments[1]

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

if (file.exists(dict_file)) {
dictionary <- readLines(dict_file)
} else {
warning("Dictionary file not found")
dictionary <- ""
}

# 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 = ":")


# Save spelling errors to file
readr::write_tsv(spelling_errors, "spell_check_errors.tsv")
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

# Save error count to GITHUB_OUTPUT
system(paste0("echo 'error_count=", nrow(spelling_errors), "'>> $GITHUB_OUTPUT"))