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

Basic infrastructure: Add Dockerfile and basic testing for this repository #8

Merged
merged 19 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
.github
93 changes: 93 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on:
push:
branches:
- main
pull_request:
branches:
- main

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Restore R package cache
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), check_dir = "check")
shell: Rscript {0}

- name: Check testthat
if: runner.os != 'Windows'
id: check_check
run: |
error_num=$(Rscript --vanilla '.github/workflows/check_testthat.R')
echo "error_num=$error_num" >> $GITHUB_OUTPUT

- name: Stop if there are errors!
if: ${{ steps.check_check.outputs.error_num != '0' }}
run: exit 1

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
31 changes: 31 additions & 0 deletions .github/workflows/check_testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Check up on the testthat results
# C. Savonen
# Nov 2023

library(magrittr)


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

out_file <- list.files(pattern = "testthat.Rout$|Rout.fail$", file.path(root_dir, "check"),
recursive = TRUE, full.names = TRUE)

check_content <- readLines(out_file)
test_result <- grep("\\[ FAIL", check_content, value = TRUE)[1]
test_result <- unlist(strsplit(test_result, "\\||\\[|\\]"))

# Format the data into a dataframe
test_result_df <- data.frame(result = trimws(test_result)) %>%
dplyr::filter(result != "") %>%
tidyr::separate(result, sep = " ", into = c("test_name", "num")) %>%
dplyr::mutate(num = as.numeric(num))

fail_num <- test_result_df %>%
dplyr::filter(test_name %in% c("FAIL", "WARN")) %>%
dplyr::summarize(total = sum(num))

fail_num <- as.character(fail_num$total)

# Spit the number out
writeLines(fail_num, con = stdout())
74 changes: 74 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Candace Savonen Jan 2024

name: Build Docker

on:
workflow_dispatch:
inputs:
dockerhubpush:
description: 'Push to Dockerhub?'
required: true
default: 'false'
tag:
description: 'What tag to use?'
required: true
default: 'none'
jobs:
build-docker:
name: Build Docker image
runs-on: ubuntu-latest

steps:
- name: checkout repo
uses: actions/checkout@v3

- name: Login as jhudsl-robot
run: |
git config --system --add safe.directory "$GITHUB_WORKSPACE"
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"

# Set up Docker build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

# Setup layer cache
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

# Set up Docker build
- name: Set up Docker Build
uses: docker/setup-buildx-action@v1

- name: Get token
run: echo ${{ secrets.GH_PAT }} > ${{ inputs.directory }}/git_token.txt

# Build docker image
- name: Build Docker image
uses: docker/build-push-action@v2
with:
push: false
load: true
context: docker
file: inst/extdata/Dockerfile
tags: hutch/gimap

# Login to Dockerhub
- name: Login to DockerHub
if: ${{ github.event.inputs.dockerhubpush != 'false' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Push the Docker image if set to true from a manual trigger
- name: Push Docker image if manual trigger set to true
if: ${{ github.event.inputs.dockerhubpush != 'false' }}
run: |
docker tag jhudsl/base_ottr:latest jhudsl/base_ottr:$github.event.inputs.tag
docker push jhudsl/base_ottr:$github.event.inputs.tag
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
49 changes: 49 additions & 0 deletions .github/workflows/render-vignette.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

# Candace Savonen Jan 2024

name: Render vignette with Docker image

on:
workflow_dispatch:
pull_request:
branches: [ main, staging ]
push:
branches: [ main, staging ]
paths:
- R/*
- inst/extdata/*

jobs:

render-vignette:
name: Render test
runs-on: ubuntu-latest
container:
image: cansav09/gimap

steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Login as jhudsl-robot
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.email "itcrtrainingnetwork@gmail.com"
git config --global user.name "jhudsl-robot"

- name: Run vignette
run: Rscript -e "rmarkdown::render('vignettes/getting-started.Rmd')"

# Commit the rendered bookdown files
- name: Commit rendered files
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
git remote set-url origin https://${GH_PAT}@github.com/${GITHUB_REPOSITORY}
git fetch origin
git add --force docs/*
git commit -m 'Render vignette' || echo "No changes to commit"
git pull --allow-unrelated-histories --strategy-option=ours
git push -u origin main || echo "No changes to push"
37 changes: 37 additions & 0 deletions .github/workflows/style-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Candace Savonen 2024

name: Style Code

on:
pull_request:
branches: [ main, staging ]

jobs:

style-code:
name: Style code
runs-on: ubuntu-latest
container:
image: cansav09/gimap

steps:
- name: Checkout files
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Login as jhudsl-robot
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.email "itcrtrainingnetwork@gmail.com"
git config --global user.name "jhudsl-robot"

- name: Run styler
run: Rscript -e "styler::style_file(list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE));warnings()"

- name: Commit styled files
run: |
git config --system --add safe.directory "$GITHUB_WORKSPACE"
git add \*.Rmd
git commit -m 'Style Rmds' || echo "No changes to commit"
git push origin || echo "No changes to commit"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ inst/extdata/cached-secrets/*
testthat-problems.rds
.Renviron
inst/doc
git_token.txt
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CONTRIBUTING

This document describes how to contribute to this R package.

## GitHub Workflow

- File an issue with anything you see that needs to be considered, added or fixed.
- Assign yourself to an issue that you'd like to work on. If you have any questions about how to go about the issue you've been assigned to, communicate your questions on that issue!
- Clone this repository locally and create a new branch to work on this issue from.
- When you feel you have enough to discuss, push the branch and open a pull request. When you do this, you will see a series of checks begin to run:

## Automatic checks

- `R-CMD-checks` - these checks make sure that the R package files are built properly. It will also rebuild the vignette underneath 4 different operating systems:
- windows
- macOS
- ubuntu release
- ubuntu dev
- `docker-build.yml` - handles the docker image associated with this pipeline. Any changes to the docker image will be tested by this GitHub Action by rebuilding it.
- `style-code.yml` - this will style your code and commit any changes to the pull request


## Testing

Whenever appropriate, new functions should be added to:
- the `vignette/getting-started.Rmd` if they are a part of the essential workflow.
- a unit test using testthat. You can create a new test using `usethis::use_test("name")`. then open up that file in the `tests/testthat` folder and write a test there. See this chapter for how to write tests https://r-pkgs.org/testing-basics.html


## Docker image

For reproducibility purposes, this repository has a Docker image. And software requirements should be added to this Docker image as development occurs.
Loading
Loading