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

New CI flow: Check package against specific CRAN snapshot(s). #25

Merged
merged 31 commits into from
Apr 18, 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
220 changes: 220 additions & 0 deletions .github/actions/setup-r-dependencies/action.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 13 additions & 4 deletions .github/workflows/Check-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
workflow_dispatch:
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

name: Check Package 📦

jobs:
Expand All @@ -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:
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/R-CMD-check-versions.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/Release-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
workflow_dispatch:
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

name: Release Package 🚀

jobs:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Suggests:
usethis,
rmarkdown,
testthat (>= 3.0.0),
kableExtra (>= 1.4),
kableExtra,
testr,
tidyr,
pharmaverseadam
Expand Down
9 changes: 9 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
always_allow_html: true
---

<!-- Add badges here -->

[![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))
<!-- Until here -->

# ramnog <a href="https://hta-pharma.github.io/ramnog/"><img src="man/figures/logo.png" align="right" height="138" alt="ramnog website" /></a>

# R packages for AMNOG analyses <a href="https://hta-pharma.github.io/ramnog/"><img src="man/figures/logo.png" align="right" height="138" alt="ramnog website" /></a>
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

<!-- Add badges here -->

[![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))
<!-- Until here -->

# ramnog <a href="https://hta-pharma.github.io/ramnog/"><img src="man/figures/logo.png" align="right" height="138" alt="ramnog website" /></a>

# R packages for AMNOG analyses <a href="https://hta-pharma.github.io/ramnog/"><img src="man/figures/logo.png" align="right" height="138" alt="ramnog website" /></a>
Expand All @@ -13,7 +22,7 @@ To get started, check out the [Quick Start](articles/ramnog.html) guide

# Packages

<table class="table table-bordered table table-hover table-condensed table-responsive" style="color: black; margin-left: auto; margin-right: auto;">
<table class="table table-bordered table table-hover table-condensed table-responsive" style="margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;color: white !important;background-color: rgba(44, 62, 80, 255) !important;">
Expand Down
Loading