From f9782238a525072f88a413fab6d7a61a6bf7d538 Mon Sep 17 00:00:00 2001 From: Zachary Susswein Date: Wed, 1 May 2024 14:46:26 -0400 Subject: [PATCH] Add CI Adds an initial Github Actions setup. Mainly based on `usethis::use_tidy_github_actions()` with some changes: - The R CMD CHECK runs are pared back to only Ubuntu/OSX/Windows latest versions - The codecov check is dropped because it had some setup with a token required. Not totally sure what the deal is there, so I replaced it with a simple unit test run for now. - I added a check that NEWS.md is modified with each PR into main, so we remember to update it with the changes - I added in a check that fixup commits are blocked, so we remember to autosquash before merging I also added in a placeholder R script and test file to run on the actions. These will be replaced with real functionality in future PRs. --- .Rbuildignore | 5 ++ .github/workflows/R-CMD-check.yaml | 49 ++++++++++++++++ .github/workflows/block-fixup.yaml | 12 ++++ .github/workflows/check-news-md.yaml | 35 ++++++++++++ .github/workflows/pkgdown.yaml | 48 ++++++++++++++++ .github/workflows/pr-commands.yaml | 79 ++++++++++++++++++++++++++ .github/workflows/pre-commit.yaml | 51 ++++++++++++++--- .github/workflows/test-coverage.yaml | 51 +++++++++++++++++ .gitignore | 1 + .pre-commit-config.yaml | 61 +++++++++++++------- DESCRIPTION | 20 +++++-- NAMESPACE | 2 + NEWS.md | 3 + R/.gitkeep | 0 R/placeholder.R | 9 +++ _pkgdown.yml | 3 + codecov.yml | 16 ++++++ man/add.Rd | 19 +++++++ tests/testthat.R | 12 ++++ tests/testthat/test-test-placeholder.R | 3 + 20 files changed, 448 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/block-fixup.yaml create mode 100644 .github/workflows/check-news-md.yaml create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 .github/workflows/pr-commands.yaml create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 NEWS.md delete mode 100644 R/.gitkeep create mode 100644 R/placeholder.R create mode 100644 _pkgdown.yml create mode 100644 codecov.yml create mode 100644 man/add.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-test-placeholder.R diff --git a/.Rbuildignore b/.Rbuildignore index 1d0a2c1..3e5b2c8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,7 @@ ^LICENSE$ ^\.github$ +^\.pre-commit-config\.yaml$ +^_pkgdown\.yml$ +^codecov\.yml$ +^docs$ +^pkgdown$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..e8f99b6 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# 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: + pull_request: + branches: [main] + push: + 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: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'release'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/block-fixup.yaml b/.github/workflows/block-fixup.yaml new file mode 100644 index 0000000..b42aeb4 --- /dev/null +++ b/.github/workflows/block-fixup.yaml @@ -0,0 +1,12 @@ +name: Git Checks + +on: [pull_request] + +jobs: + block-fixup: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2.0.0 + - name: Block Fixup Commit Merge + uses: 13rac1/block-fixup-merge-action@v2.0.0 diff --git a/.github/workflows/check-news-md.yaml b/.github/workflows/check-news-md.yaml new file mode 100644 index 0000000..07ae7de --- /dev/null +++ b/.github/workflows/check-news-md.yaml @@ -0,0 +1,35 @@ +name: Check NEWS.md Update + +on: + pull_request: + branches: + - main + +jobs: + check-news-md-modification: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all history for all tags and branches + + - name: Check for NEWS.md changes + run: | + echo "Current SHA: $GITHUB_SHA" + echo "Base SHA: ${{ github.event.pull_request.base.sha }}" + + git fetch origin ${{ github.event.pull_request.base.ref }} + + CHANGED_FILES=$(git diff --name-only $GITHUB_SHA $(git merge-base $GITHUB_SHA origin/${{ github.event.pull_request.base.ref }})) + echo "Changed files:" + echo "$CHANGED_FILES" + + if echo "$CHANGED_FILES" | grep -q "NEWS.md"; then + echo "NEWS.md has been modified." + else + echo "::error file=NEWS.md,line=1,col=5::NEWS.md must be updated with each PR." >&2 + exit 1 + fi + shell: /usr/bin/bash -e {0} diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..a7276e8 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -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@v4 + + - 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.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml new file mode 100644 index 0000000..eea58c5 --- /dev/null +++ b/.github/workflows/pr-commands.yaml @@ -0,0 +1,79 @@ +# 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: + issue_comment: + types: [created] + +name: Commands + +jobs: + document: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} + name: document + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::roxygen2 + needs: pr-document + + - name: Document + run: roxygen2::roxygenise() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add man/\* NAMESPACE + git commit -m 'Document' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + style: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} + name: style + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + + - name: Install dependencies + run: install.packages("styler") + shell: Rscript {0} + + - name: Style + run: styler::style_pkg() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add \*.R + git commit -m 'Style' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index fc0c5c0..4ba2b98 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -1,14 +1,51 @@ name: pre-commit -on: - pull_request: - push: - branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + + +on: [push] jobs: pre-commit: runs-on: ubuntu-latest + if: >- + !contains(github.event.head_commit.message, 'ci skip') && + ( + startsWith(github.ref, 'refs/heads') || + github.event.pull_request.draft == false + ) steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: ./.github/actions/pre-commit + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Install system dependencies + if: runner.os == 'Linux' + run: | + sudo apt-get install -y libcurl4-openssl-dev + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.8" + architecture: "x64" + - name: Run pre-commit + uses: pre-commit/action@v2.0.3 + - name: Commit files + if: failure() && startsWith(github.ref, 'refs/heads') + run: | + if [[ `git status --porcelain --untracked-files=no` ]]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git checkout -- .github/workflows + git commit -m "pre-commit" -a + fi + - name: Push changes + if: failure() && startsWith(github.ref, 'refs/heads') + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} + env: + RENV_CONFIG_CACHE_ENABLED: FALSE diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..e8a8471 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,51 @@ +# 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] + pull_request: + branches: [main] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package"), + token = "${{ secrets.CODECOV_TOKEN }}" + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/.gitignore b/.gitignore index ad2d843..2998db1 100644 --- a/.gitignore +++ b/.gitignore @@ -379,3 +379,4 @@ docs/site/ # such, it should not be committed for packages, but should be committed for # applications that require a static environment. #Manifest.toml +docs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e37ab4a..237d474 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,45 +1,66 @@ +# All available hooks: https://pre-commit.com/hooks.html +# R specific hooks: https://github.com/lorenzwalthert/precommit repos: -##### -# Basic file cleanliness -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 +# R +- repo: https://github.com/lorenzwalthert/precommit + rev: v0.4.2 hooks: + - id: style-files + args: [--style_pkg=styler, --style_fun=tidyverse_style] + - id: roxygenize + - id: use-tidy-description + - id: lintr + - id: readme-rmd-rendered + - id: parsable-R + - id: no-browser-statement + - id: no-print-statement + - id: no-debug-statement + - id: deps-in-desc +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: - id: check-added-large-files - - id: check-yaml - - id: check-toml + args: ['--maxkb=200'] + - id: file-contents-sorter + files: '^\.Rbuildignore$' - id: end-of-file-fixer - - id: mixed-line-ending - - id: trailing-whitespace + exclude: '\.Rd' +- repo: https://github.com/pre-commit-ci/pre-commit-ci-config + rev: v1.6.1 + hooks: + # Only required when https://pre-commit.ci is used for config validation + - id: check-pre-commit-ci-config +- repo: local + hooks: + - id: forbid-to-commit + name: Don't commit common R artifacts + entry: Cannot commit .Rhistory, .RData, .Rds or .rds. + language: fail + files: '\.(Rhistory|RData|Rds|rds)$' + # `exclude: ` to allow committing specific files ##### # Python - repo: https://github.com/psf/black - rev: 23.10.0 + rev: 24.4.2 hooks: # if you have ipython notebooks, consider using # `black-jupyter` hook instead - id: black args: ['--line-length', '79'] - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: ['--profile', 'black', '--line-length', '79'] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.0 + rev: v0.4.2 hooks: - id: ruff ##### -# R -- repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9023 - hooks: - - id: style-files - - id: lintr -##### # Java - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.11.0 + rev: v2.13.0 hooks: - id: pretty-format-java args: [--aosp,--autofix] @@ -59,3 +80,5 @@ repos: - id: detect-secrets args: ['--baseline', '.secrets.baseline'] exclude: package.lock.json +ci: + autoupdate_schedule: monthly diff --git a/DESCRIPTION b/DESCRIPTION index 6d7aa3d..07fcdcd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,14 @@ Package: RtGam Title: Estimating Rt with Generalized Additive Models Version: 0.0.0.9000 -Authors@R:c( - . - ) +Authors@R: c( + person("Zachary", "Susswein", , "utb2@cdc.gov", role = c("aut", "cre"), + comment = c(ORCID = "0000-0002-4329-4833")), + person("Katelyn", "Gostic", , "uep6@cdc.gov", role = "aut", + comment = c(ORCID = "0000-0002-9369-6371")), + person("Sam", "Abbott", , "azw1@cdc.gov", role = "aut", + comment = c(ORCID = "0000-0001-8057-8037")) + ) Description: An opinionated implementation of a generalized additive modeling (GAMs) approach to estimate epidemic dynamics. This flexible semi-parametric method allows fitting to arbitrary incidence @@ -14,8 +19,13 @@ Description: An opinionated implementation of a generalized additive _real-time_ use cases. The package is meant for drop-in use in an emerging outbreak, complementing MCMC-based inference methods. License: Apache License (>= 2) -URL: https://github.com/cdcgov/cfa-gam-rt +URL: https://github.com/cdcgov/cfa-gam-rt, + https://cdcgov.github.io/cfa-gam-rt/ BugReports: https://github.com/cdcgov/cfa-gam-rt/issues +Suggests: + testthat (>= 3.0.0), + pkgdown +Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index e651b94..3ac6f23 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1 +1,3 @@ # Generated by roxygen2: do not edit by hand + +export(add) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..bd91ed8 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# RtGam (development version) + +* Initial CI setup diff --git a/R/.gitkeep b/R/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/R/placeholder.R b/R/placeholder.R new file mode 100644 index 0000000..dfd9722 --- /dev/null +++ b/R/placeholder.R @@ -0,0 +1,9 @@ +#' Testing testing 123 +#' @param num1 A number +#' @param num2 Another number +#' @return The sum +#' +#' @export +add <- function(num1, num2) { + sum(num1, num2) +} diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..43a4823 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,3 @@ +url: https://cdcgov.github.io/cfa-gam-rt/ +template: + bootstrap: 5 diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..4862256 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,16 @@ +comment: + layout: "condensed_header, condensed_files, condensed_footer" # add "condensed_" to "header", "files" and "footer" + hide_project_coverage: TRUE # set to true + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/man/add.Rd b/man/add.Rd new file mode 100644 index 0000000..4287c15 --- /dev/null +++ b/man/add.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/placeholder.R +\name{add} +\alias{add} +\title{Testing testing 123} +\usage{ +add(num1, num2) +} +\arguments{ +\item{num1}{A number} + +\item{num2}{Another number} +} +\value{ +The sum +} +\description{ +Testing testing 123 +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..b9bbd4d --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(RtGam) + +test_check("RtGam") diff --git a/tests/testthat/test-test-placeholder.R b/tests/testthat/test-test-placeholder.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-test-placeholder.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +})