From b44345638a5fb8b4450c828b1f309cd4752eb22b Mon Sep 17 00:00:00 2001
From: HenrikSpiegel <49019622+HenrikSpiegel@users.noreply.github.com>
Date: Thu, 18 Apr 2024 09:15:54 +0200
Subject: [PATCH] New CI flow: Check package against specific CRAN snapshot(s).
(#25)
* Adds a new subflow which checks the package against specific cran snapshot(s)
* Adds CI-CD badges.
---
.../actions/setup-r-dependencies/action.yaml | 220 ++++++++++++++++++
.github/workflows/Check-package.yaml | 17 +-
.github/workflows/R-CMD-check-versions.yaml | 74 ++++++
.github/workflows/R-CMD-check.yaml | 4 +-
.github/workflows/Release-package.yaml | 4 +
DESCRIPTION | 2 +-
README.Rmd | 9 +
README.md | 9 +
vignettes/ep_overview.Rmd | 4 +-
9 files changed, 333 insertions(+), 10 deletions(-)
create mode 100644 .github/actions/setup-r-dependencies/action.yaml
create mode 100644 .github/workflows/R-CMD-check-versions.yaml
diff --git a/.github/actions/setup-r-dependencies/action.yaml b/.github/actions/setup-r-dependencies/action.yaml
new file mode 100644
index 0000000..30dee9e
--- /dev/null
+++ b/.github/actions/setup-r-dependencies/action.yaml
@@ -0,0 +1,220 @@
+name: 'setup-r-dependencies'
+description: 'Action to setup installation tools and install R dependencies'
+author: 'Jim Hester (modified by Henrik Spiegelhauer)'
+inputs:
+ cache:
+ description: 'A boolean value indicating whether packages should be cached from one to the other'
+ required: true
+ default: true
+ cache-version:
+ description: 'The version of the cache, change this from the default (1) to start over with a fresh cache. Ignored if cache: false'
+ required: true
+ default: 1
+ extra-packages:
+ description: 'Any extra packages to install outside of the packages listed in the dependencies'
+ needs:
+ description: 'Any extra Config/Needs fields which need to be included when installing dependencies'
+ packages:
+ description: 'Which package(s) to install.'
+ default: 'deps::., any::sessioninfo'
+ pak-version:
+ description: 'Which pak version to use. Possible values are "stable", "rc" and "devel".'
+ default: 'stable'
+ working-directory:
+ description: 'Using the working-directory keyword, you can specify the working directory of where "pkg_deps" command searches for dependencies in the "DESCRIPTION" file.'
+ default: '.'
+ dependencies:
+ description: 'Types of dependencies to install. Must be an R expression. Note that it often needs to be quoted in YAML, see the README for details.'
+ default: '"all"'
+ dependency_repo:
+ description: 'Overwrite the default CRAN-like reposity'
+ default: 'NULL'
+ upgrade:
+ description: 'Whether to install the latest available versions of the dependencies. Must be an R expression. See the README for details if you need quoting.'
+ default: 'FALSE'
+ lockfile-create-lib:
+ description: 'The package library to consider when creating the pak lockfile. This is passed to the `lib` argument of `pak::lockfile_create()`. Defaults to an empty library, for reproducibility. Must be an R expression. Note that it often needs to be quoted in YAML, see the README for details.'
+ default: 'NULL'
+ install-pandoc:
+ description: 'Whether to install pandoc. By default it is installed if it is not on the PATH and the local package suggests or depends on the rmarkdown package.'
+ pandoc-version:
+ description: 'Pandoc version to install.'
+ default: '3.1.11'
+runs:
+ using: "composite"
+ steps:
+ - name: Set site library path
+ run: |
+ # Set site library path
+ cat("::group::Set site library path\n")
+ if (Sys.getenv("RENV_PROJECT") != "") {
+ message("renv project detected, no need to set R_LIBS_SITE")
+ cat(sprintf("R_LIB_FOR_PAK=%s\n", .libPaths()[1]), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
+ q("no")
+ }
+ lib <- Sys.getenv("R_LIBS_SITE")
+ if (lib == "") {
+ lib <- file.path(dirname(.Library), "site-library")
+ cat(sprintf("R_LIBS_SITE=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
+ cat(sprintf("R_LIB_FOR_PAK=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
+ message("Setting R_LIBS_SITE to ", lib)
+ } else {
+ message("R_LIBS_SITE is already set to ", lib)
+ cat(sprintf("R_LIB_FOR_PAK=%s\n", strsplit(lib, .Platform$path.sep)[[1]][[1]]), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
+ }
+ cat("::endgroup::\n")
+ shell: Rscript {0}
+
+ - name: Install pak (Windows)
+ if: runner.os == 'Windows'
+ run: |
+ # Install pak
+ cat("::group::Install pak\n")
+ lib <- Sys.getenv("R_LIB_FOR_PAK")
+ dir.create(lib, showWarnings = FALSE, recursive = TRUE)
+ install.packages("pak", lib = lib, repos = sprintf(
+ "https://r-lib.github.io/p/pak/%s/%s/%s/%s",
+ "${{ inputs.pak-version }}",
+ .Platform$pkgType,
+ R.Version()$os,
+ R.Version()$arch
+ ))
+ cat("::endgroup::\n")
+ shell: Rscript {0}
+
+ - name: Install pak (Unix)
+ if: runner.os != 'Windows'
+ run: |
+ # Install pak
+ echo "::group::Install pak"
+ if which sudo >/dev/null; then SUDO="sudo -E --preserve-env=PATH env"; else SUDO=""; fi
+ $SUDO R -q -e 'dir.create(Sys.getenv("R_LIB_FOR_PAK"), recursive = TRUE, showWarnings = FALSE)'
+ $SUDO R -q -e 'install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK"), repos = sprintf("https://r-lib.github.io/p/pak/%s/%s/%s/%s", "${{ inputs.pak-version }}", .Platform$pkgType, R.Version()$os, R.Version()$arch))'
+ echo "::endgroup::"
+ shell: bash
+
+ - name: Query dependencies
+ id: install
+ run: |
+ # Override the default CRAN-like repository
+ if ("${{ inputs.dependency_repo }}" != "NULL") {
+ options(repos = c(CRAN = "${{ inputs.dependency_repo }}"))
+ }
+
+ # Dependency resolution
+ cat("::group::Dependency resolution\n")
+ cat("os-version=", sessionInfo()$running, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
+ r_version <-
+ if (grepl("development", R.version.string)) {
+ pdf(tempfile())
+ ge_ver <- attr(recordPlot(), "engineVersion")
+ dev.off()
+ paste0("R version ", getRversion(), " (ge:", ge_ver, "; iid:", .Internal(internalsID()), ")")
+ } else {
+ R.version.string
+ }
+ cat("r-version=", r_version, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
+ needs <- sprintf("Config/Needs/%s", strsplit("${{ inputs.needs }}", "[[:space:],]+")[[1]])
+ deps <- strsplit("${{ inputs.packages }}", "[[:space:],]+")[[1]]
+ extra_deps <- strsplit("${{ inputs.extra-packages }}", "[[:space:],]+")[[1]]
+ dir.create(".github", showWarnings=FALSE)
+ Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
+ library(pak, lib.loc = Sys.getenv("R_LIB_FOR_PAK"))
+ pak::lockfile_create(
+ c(deps, extra_deps),
+ lockfile = ".github/pkg.lock",
+ upgrade = (${{ inputs.upgrade }}),
+ dependencies = c(needs, (${{ inputs.dependencies }})),
+ lib = ${{ inputs.lockfile-create-lib }}
+ )
+ cat("::endgroup::\n")
+ cat("::group::Show Lockfile\n")
+ writeLines(readLines(".github/pkg.lock"))
+ cat("::endgroup::\n")
+ shell: Rscript {0}
+ working-directory: ${{ inputs.working-directory }}
+
+ - name: Restore R package cache
+ if: inputs.cache == 'true'
+ uses: actions/cache@v4
+ with:
+ path: |
+ ${{ env.R_LIBS_USER }}/*
+ !${{ env.R_LIBS_USER }}/pak
+ key: ${{ format('{0}-{1}-{2}-{3}', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version, inputs.dependency_repo, hashFiles(format('{0}/.github/pkg.lock', inputs.working-directory ))) }}
+ restore-keys: ${{ steps.install.outputs.os-version }}-${{ steps.install.outputs.r-version }}-${{inputs.cache-version }}-${{inputs.dependency_repo }}
+
+ - name: Install dependencies
+ run: |
+ # Override the default CRAN-like repository
+ if ("${{ inputs.dependency_repo }}" != "NULL") {
+ options(repos = c(CRAN = "${{ inputs.dependency_repo }}"))
+ }
+
+ # Install/Update packages
+ cat("::group::Install/update packages\n")
+ Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
+ library(pak, lib.loc = Sys.getenv("R_LIB_FOR_PAK"))
+ pak::lockfile_install(".github/pkg.lock")
+ ## Clean up lock file
+ unlink(".github/pkg.lock")
+ cat("::endgroup::\n")
+ shell: Rscript {0}
+ working-directory: ${{ inputs.working-directory }}
+
+ - name: Check whether pandoc needs to be installed
+ id: check-pandoc
+ run: |
+ cat("::group::Check if package needs pandoc\n")
+ o <- '${{ inputs.install-pandoc }}'
+ if (! o %in% c('true', 'false')) {
+ if (Sys.which("pandoc") != "") {
+ o <- 'false'
+ } else if (file.exists("DESCRIPTION")) {
+ deptypes <- list(direct = "all", indirect = character())
+ deps <- pak::pkg_deps(".", dependencies = deptypes)
+ if ("rmarkdown" %in% deps$package) {
+ o <- 'true'
+ } else {
+ o <- 'false'
+ }
+ } else {
+ o <- 'false'
+ }
+ }
+ cat("install=", o, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
+ cat("::endgroup::\n")
+ shell: Rscript {0}
+ working-directory: ${{ inputs.working-directory }}
+
+ - name: Install pandoc if needed
+ if: ${{ steps.check-pandoc.outputs.install == 'true' }}
+ uses: r-lib/actions/setup-pandoc@v2
+ with:
+ pandoc-version: ${{ inputs.pandoc-version }}
+
+ - name: Session info
+ run: |
+ # Session info
+ cat("::group::Session info\n")
+ if (requireNamespace("sessioninfo", quietly = TRUE)) {
+ if (packageVersion("sessioninfo") >= "1.2.1") {
+ sessioninfo::session_info(pkgs = "installed", include_base = TRUE)
+ } else {
+ options(width = 200)
+ sessioninfo::session_info(rownames(installed.packages()), include_base=TRUE)
+ }
+ } else {
+ sessionInfo()
+ }
+ cat("::endgroup::\n")
+ shell: Rscript {0}
+ working-directory: ${{ inputs.working-directory }}
+
+ - name: Don't use tar 1.30 from Rtools35 to store the cache
+ if: runner.os == 'Windows'
+ shell: bash
+ run: |
+ if command -v /c/Rtools/bin/tar && /c/Rtools/bin/tar --version | grep -q 'tar (GNU tar) 1.30'
+ then echo 'C:/Program Files/Git/usr/bin' >> $GITHUB_PATH
+ fi
diff --git a/.github/workflows/Check-package.yaml b/.github/workflows/Check-package.yaml
index 627d8cf..b6771d2 100644
--- a/.github/workflows/Check-package.yaml
+++ b/.github/workflows/Check-package.yaml
@@ -10,6 +10,10 @@ on:
workflow_dispatch:
workflow_call:
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
name: Check Package 📦
jobs:
@@ -23,10 +27,15 @@ jobs:
name: License Check 🃏
uses: insightsengineering/r.pkg.template/.github/workflows/licenses.yaml@main
- # Runs R CMD check using the local R-CMD-check.yaml workflow
- check:
- name: RMD check 📦
- uses: ./.github/workflows/R-CMD-check.yaml
+ # # Runs R CMD check using the local R-CMD-check.yaml workflow
+ # check:
+ # name: RMD check 📦
+ # uses: ./.github/workflows/R-CMD-check.yaml
+
+ # Runs R CMD check with specific version(s) of R and cran-snapshot
+ check-versions:
+ name: RMD check versions 📜
+ uses: ./.github/workflows/R-CMD-check-versions.yaml
# Runs unittests while capturing code:cov and uploads to Codecov io. See local subflow
test:
diff --git a/.github/workflows/R-CMD-check-versions.yaml b/.github/workflows/R-CMD-check-versions.yaml
new file mode 100644
index 0000000..f89b50d
--- /dev/null
+++ b/.github/workflows/R-CMD-check-versions.yaml
@@ -0,0 +1,74 @@
+---
+# R-CMD check which allows you to lock the R version and date of the CRAN snapshot.
+# This is particularly helpful for ensuring that the package works with internal systems.
+ on:
+ workflow_dispatch:
+ workflow_call:
+
+ name: R-CMD-check-versions
+
+ jobs:
+ R-CMD-check:
+ runs-on: ${{ matrix.os }}
+ name: ${{ matrix.os }} (R ${{ matrix.config.r }}, CRAN ${{ matrix.config.date }})
+ strategy:
+ fail-fast: false
+ matrix:
+ os:
+ - macos-latest
+ - windows-latest
+ - ubuntu-latest
+ config:
+ - date: 'latest'
+ r: 'release'
+ - date: 2023-10-25 # Lock the date of the CRAN snapshot
+ r: 4.3.1
+ 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 }}
+ use-public-rspm: false
+
+ - name: Determine the CRAN image to use
+ id: cran-image
+ run: |
+ if [ "${{ matrix.config.date }}" == "latest" ]; then
+ echo "image=https://cloud.r-project.org" >> $GITHUB_OUTPUT
+ else
+ echo "image=https://packagemanager.posit.co/cran/${{ matrix.config.date }}" >> $GITHUB_OUTPUT
+ fi
+ shell: bash
+
+ - name: Debug image
+ run: |
+ echo ${{ steps.cran-image.outputs.image }}
+ shell: bash
+
+ - name: Install R dependencies (custom)
+ uses: ./.github/actions/setup-r-dependencies
+ with:
+ cache: true
+ dependency_repo: ${{ steps.cran-image.outputs.image }}
+ working-directory: ${{ github.workspace }}
+ extra-packages: any::rcmdcheck
+
+ - name: Session info
+ run: |
+ sessionInfo()
+ installed.packages()[,c("Package", "Version")]
+
+ shell: Rscript {0}
+
+ - uses: r-lib/actions/check-r-package@v2
+ with:
+ args: 'c("--no-manual", "--as-cran")'
+ upload-snapshots: true
+ error-on: '"error"'
+ check-dir: '"check"'
+ upload-results: true
diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml
index 0fdf02d..1a7864b 100644
--- a/.github/workflows/R-CMD-check.yaml
+++ b/.github/workflows/R-CMD-check.yaml
@@ -18,8 +18,8 @@ jobs:
matrix:
config:
- {os: ubuntu-latest, r: 'release'}
- - {os: windows-latest, r: 'release'}
- - {os: macos-latest, r: 'release'}
+ #- {os: windows-latest, r: 'release'}
+ #- {os: macos-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}
# - {os: ubuntu-latest, r: 'oldrel-2'}
# - {os: ubuntu-latest, r: 'oldrel-3'}
diff --git a/.github/workflows/Release-package.yaml b/.github/workflows/Release-package.yaml
index fafaf60..b7518b4 100644
--- a/.github/workflows/Release-package.yaml
+++ b/.github/workflows/Release-package.yaml
@@ -10,6 +10,10 @@
workflow_dispatch:
workflow_call:
+ concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
name: Release Package 🚀
jobs:
diff --git a/DESCRIPTION b/DESCRIPTION
index 279f647..49e1d1f 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -22,7 +22,7 @@ Suggests:
usethis,
rmarkdown,
testthat (>= 3.0.0),
- kableExtra (>= 1.4),
+ kableExtra,
testr,
tidyr,
pharmaverseadam
diff --git a/README.Rmd b/README.Rmd
index 9697f7d..2caa6d3 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -3,6 +3,15 @@
always_allow_html: true
---
+
+
+[![Check Package
+📦](https://github.com/hta-pharma/ramnog/actions/workflows/Check-package.yaml/badge.svg)](https://github.com/hta-pharma/ramnog/actions/workflows/Check-package.yaml)
+[![Release Package
+🚀](https://github.com/hta-pharma/ramnog/actions/workflows/Release-package.yaml/badge.svg)](https://github.com/hta-pharma/ramnog/actions/workflows/Release-package.yaml)
+[![codecov.io](https://img.shields.io/codecov/c/gh/hta-pharma/ramnog?style=plastic&label=codecov.io)]((https://app.codecov.io/github/hta-pharma/ramnog?branch=main))
+
+
# ramnog
# R packages for AMNOG analyses
diff --git a/README.md b/README.md
index fcfb8fb..9785594 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,13 @@
+
+
+[![Check Package
+📦](https://github.com/hta-pharma/ramnog/actions/workflows/Check-package.yaml/badge.svg)](https://github.com/hta-pharma/ramnog/actions/workflows/Check-package.yaml)
+[![Release Package
+🚀](https://github.com/hta-pharma/ramnog/actions/workflows/Release-package.yaml/badge.svg)](https://github.com/hta-pharma/ramnog/actions/workflows/Release-package.yaml)
+[![codecov.io](https://img.shields.io/codecov/c/gh/hta-pharma/ramnog?style=plastic&label=codecov.io)]((https://app.codecov.io/github/hta-pharma/ramnog?branch=main))
+
+
# ramnog
# R packages for AMNOG analyses
diff --git a/vignettes/ep_overview.Rmd b/vignettes/ep_overview.Rmd
index f2e5726..5a46c3c 100644
--- a/vignettes/ep_overview.Rmd
+++ b/vignettes/ep_overview.Rmd
@@ -1,8 +1,6 @@
---
title: "Endpoint Specification"
-output:
- rmarkdown::html_vignette:
- toc: true
+output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Endpoint Specification}
%\VignetteEncoding{UTF-8}