From f654bbc4ac64e90cdce0668de36ff15ebb26a4f3 Mon Sep 17 00:00:00 2001 From: cicdguy <26552821+cicdguy@users.noreply.github.com> Date: Tue, 5 Dec 2023 18:48:24 -0600 Subject: [PATCH 1/4] Initialize starter actions --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 29 ++++++++++++++++ .github/workflows/pkgdown.yaml | 48 ++++++++++++++++++++++++++ .github/workflows/test-coverage.yaml | 50 ++++++++++++++++++++++++++++ .github/workflows/urlchecker.yaml | 37 ++++++++++++++++++++ DESCRIPTION | 12 +++++++ NAMESPACE | 2 ++ 8 files changed, 180 insertions(+) create mode 100644 .Rbuildignore create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 .github/workflows/urlchecker.yaml create mode 100644 DESCRIPTION create mode 100644 NAMESPACE diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..c503c4f --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1 @@ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..b8ce383 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,29 @@ +# 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: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + 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::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..f5e15fa --- /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@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 \ No newline at end of file diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..cf9fa24 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# 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] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v3 + + - 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") + ) + 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@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package \ No newline at end of file diff --git a/.github/workflows/urlchecker.yaml b/.github/workflows/urlchecker.yaml new file mode 100644 index 0000000..117febe --- /dev/null +++ b/.github/workflows/urlchecker.yaml @@ -0,0 +1,37 @@ +# A custom workflow that checks the validity of +# URLs in source code as well as documentation. +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::urlchecker + + - name: Test coverage + run: | + urlchecker::url_check( + path = ".", + db = NULL, + parallel = TRUE, + pool = curl::new_pool(), + progress = TRUE + ) + shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..bc43f8a --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,12 @@ +Package: devops.toolkit +Title: What the Package Does (One Line, Title Case) +Version: 0.0.0.9000 +Authors@R: + person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), + comment = c(ORCID = "YOUR-ORCID-ID")) +Description: What the package does (one paragraph). +License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a + license +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..6ae9268 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,2 @@ +# Generated by roxygen2: do not edit by hand + From 27ada626f51160063b77579c7c5e10eda78db4f3 Mon Sep 17 00:00:00 2001 From: cicdguy <26552821+cicdguy@users.noreply.github.com> Date: Tue, 5 Dec 2023 18:56:11 -0600 Subject: [PATCH 2/4] Add license info and urlchecker --- .Rbuildignore | 1 + .github/workflows/R-CMD-check.yaml | 2 ++ .github/workflows/urlchecker.yaml | 4 ++-- DESCRIPTION | 3 +-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index c503c4f..87b476d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1 +1,2 @@ ^\.github$ +^LICENSE\.md$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b8ce383..e10bb38 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -21,6 +21,8 @@ jobs: with: use-public-rspm: true + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::rcmdcheck diff --git a/.github/workflows/urlchecker.yaml b/.github/workflows/urlchecker.yaml index 117febe..7d5b988 100644 --- a/.github/workflows/urlchecker.yaml +++ b/.github/workflows/urlchecker.yaml @@ -6,10 +6,10 @@ on: pull_request: branches: [main, master] -name: R-CMD-check +name: urlchecker jobs: - R-CMD-check: + urlchecker: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/DESCRIPTION b/DESCRIPTION index bc43f8a..71b4af1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,8 +5,7 @@ Authors@R: person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), comment = c(ORCID = "YOUR-ORCID-ID")) Description: What the package does (one paragraph). -License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a - license +License: Apache License (>= 2) Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 From ee94e5808cc62ad842cb4c4868dc15e52afc4bc4 Mon Sep 17 00:00:00 2001 From: cicdguy <26552821+cicdguy@users.noreply.github.com> Date: Tue, 5 Dec 2023 19:07:11 -0600 Subject: [PATCH 3/4] Add man pages and tests --- .github/workflows/urlchecker.yaml | 4 +++- R/hello.R | 9 +++++++++ man/hello.Rd | 20 ++++++++++++++++++++ tests/testthat.R | 3 +++ tests/testthat/test-hello.R | 5 +++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 R/hello.R create mode 100644 man/hello.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-hello.R diff --git a/.github/workflows/urlchecker.yaml b/.github/workflows/urlchecker.yaml index 7d5b988..2537d21 100644 --- a/.github/workflows/urlchecker.yaml +++ b/.github/workflows/urlchecker.yaml @@ -21,11 +21,13 @@ jobs: with: use-public-rspm: true + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::urlchecker - - name: Test coverage + - name: Check for valid URLs run: | urlchecker::url_check( path = ".", diff --git a/R/hello.R b/R/hello.R new file mode 100644 index 0000000..79b554d --- /dev/null +++ b/R/hello.R @@ -0,0 +1,9 @@ +#' Greet an entity. Could be a person, an animal, or an alien. +#' +#' @param name The name of the entity to greet. +#' @return A greeting as a string. +#' @examples +#' hello("E.T.") +hello <- function(name) { + paste("Hello", name) +} diff --git a/man/hello.Rd b/man/hello.Rd new file mode 100644 index 0000000..e0151dd --- /dev/null +++ b/man/hello.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hello.R +\name{hello} +\alias{hello} +\title{Greet an entity. Could be a person, an animal, or an alien.} +\usage{ +hello(name) +} +\arguments{ +\item{name}{The name of the entity to greet.} +} +\value{ +A greeting as a string. +} +\description{ +Greet an entity. Could be a person, an animal, or an alien. +} +\examples{ +hello("E.T.") +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..f3647c2 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,3 @@ +pkg_name <- "devops.toolkit" +library(pkg_name, character.only = TRUE) +testthat::test_check(pkg_name) diff --git a/tests/testthat/test-hello.R b/tests/testthat/test-hello.R new file mode 100644 index 0000000..89713a4 --- /dev/null +++ b/tests/testthat/test-hello.R @@ -0,0 +1,5 @@ +test_that("hello greets the entity", { + result <- hello("foo") + expected <- "Hello foo" + expect_identical(result, expected) +}) From b18bedfe9343b53c0b4613974ab4b6b5d6d1258a Mon Sep 17 00:00:00 2001 From: cicdguy <26552821+cicdguy@users.noreply.github.com> Date: Tue, 5 Dec 2023 19:14:58 -0600 Subject: [PATCH 4/4] Export the core function, add testthat as suggested dep --- DESCRIPTION | 3 +++ NAMESPACE | 1 + R/hello.R | 1 + 3 files changed, 5 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 71b4af1..a5e1a76 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,3 +9,6 @@ License: Apache License (>= 2) Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 +Suggests: testthat (>= 3.2.0) +Config/testthat/edition: 3 +Config/testthat/parallel: true diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..01843dc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,3 @@ # Generated by roxygen2: do not edit by hand +export(hello) diff --git a/R/hello.R b/R/hello.R index 79b554d..cb9dd05 100644 --- a/R/hello.R +++ b/R/hello.R @@ -2,6 +2,7 @@ #' #' @param name The name of the entity to greet. #' @return A greeting as a string. +#' @export #' @examples #' hello("E.T.") hello <- function(name) {