Skip to content

Commit

Permalink
- Use {pak} for pkg installation and binaries on Linux (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-s authored Aug 28, 2022
1 parent 136a2b5 commit ab39338
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 157 deletions.
60 changes: 17 additions & 43 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- main
- master
- pak2
pull_request:
branches:
- main
Expand All @@ -30,12 +31,12 @@ jobs:
# use a different tic template type if you do not want to build on all listed platforms
- { os: windows-latest, r: "release" }
- { os: macOS-latest, r: "release", pkgdown: "true", latex: "true" }
- { os: ubuntu-latest, r: "devel" }
# - { os: macOS-latest, r: "devel" }
- { os: ubuntu-latest, r: "devel", pkgdown: "true" }
- { os: ubuntu-latest, r: "release" }

env:
# otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}
# make sure to run `tic::use_ghactions_deploy()` to set up deployment
TIC_DEPLOY_KEY: ${{ secrets.TIC_DEPLOY_KEY }}
Expand All @@ -44,8 +45,6 @@ jobs:
# if you use bookdown or blogdown, replace "PKGDOWN" by the respective
# capitalized term. This also might need to be done in tic.R
BUILD_PKGDOWN: ${{ matrix.config.pkgdown }}
# macOS >= 10.15.4 linking
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
# use GITHUB_TOKEN from GitHub to workaround rate limits in {remotes}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -56,8 +55,13 @@ jobs:
with:
r-version: ${{ matrix.config.r }}
Ncpus: 4
use-public-rspm: true

- uses: r-lib/actions/setup-tinytex@v2
# LaTeX. Installation time:
# Linux: ~ 1 min
# macOS: ~ 1 min 30s
# Windows: never finishes
- uses: r-lib/actions/setup-tinytex@master
if: matrix.config.latex == 'true'

- uses: r-lib/actions/setup-pandoc@v2
Expand All @@ -72,59 +76,29 @@ jobs:

- name: "[Cache] Cache R packages"
if: runner.os != 'Windows'
uses: pat-s/always-upload-cache@v2
uses: pat-s/always-upload-cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}-1
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}-1

- name: "[Stage] [Linux] Install required system libs"
if: runner.os == 'Linux'
run: sudo apt install libcurl4-openssl-dev libgit2-dev

- name: "[Stage] [macOS] Install libgit2"
if: runner.os == 'macOS'
run: brew install libgit2

- name: "[Stage] [macOS] Install system libs for pkgdown"
if: runner.os == 'macOS' && matrix.config.pkgdown != ''
run: brew install harfbuzz fribidi

- name: "[Stage] [Linux] Install system libs for pkgdown"
if: runner.os == 'Linux' && matrix.config.pkgdown != ''
run: sudo apt install libharfbuzz-dev libfribidi-dev

# Try to automatically check for system dependencies and install them
# Note: this might not catch all required system libs and manual action might be needed
- name: "[Stage] [Linux] Install linux system dependencies"
if: runner.os == 'Linux'
# for some strange Windows reason this step and the next one need to be decoupled
- name: "[Stage] Install pak"
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
Rscript -e "install.packages('pak', repos = 'https://r-lib.github.io/p/pak/stable')"
- name: "[Stage] Install"
if: matrix.config.os != 'macOS-latest' || matrix.config.r != 'devel'
run: Rscript -e "install.packages('tic', repos = structure(c(ropensci = 'https://ropensci.r-universe.dev', CRAN = 'https://cloud.r-project.org')))" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()"

# macOS devel needs its own stage because we need to work with an option to suppress the usage of binaries
- name: "[Stage] Prepare & Install (macOS-devel)"
if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'devel'
run: |
echo -e 'options(Ncpus = 4, pkgType = "source", repos = structure(c(CRAN = "https://cloud.r-project.org/")))' > $HOME/.Rprofile
Rscript -e "install.packages('tic', repos = structure(c(ropensci = 'https://ropensci.r-universe.dev', CRAN = 'https://cloud.r-project.org')))" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()"
run: Rscript -e "pak::pkg_install('ropensci/tic@pak2')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()"

- name: "[Stage] Script"
run: Rscript -e 'tic::script()'

- name: "[Stage] After Success"
if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release'
run: Rscript -e "tic::after_success()"

- name: "[Stage] Upload R CMD check artifacts"
if: failure()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Imports:
magrittr,
memoise,
methods,
pak,
R6,
remotes,
rlang (>= 1.0.0),
Expand All @@ -56,6 +57,7 @@ Suggests:
gh (>= 1.1.0),
knitr,
openssl,
pkgdepends,
pkgdown,
purrr,
rcmdcheck,
Expand All @@ -75,7 +77,7 @@ Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
SystemRequirements: sodium harfbuzz fribidi libgit2
Collate:
'base64.R'
Expand Down
2 changes: 1 addition & 1 deletion R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ verify_install <- function(pkg_names) { # nolint
}

verify_install_one <- function(pkg_name) { # nolint
remotes::install_cran(pkg_name, upgrade = TRUE, quiet = TRUE)
pak::pkg_install(pkg_name, upgrade = TRUE)
if (!package_installed(pkg_name)) {
stopc(
"Error installing package ", pkg_name, " or one of its dependencies."
Expand Down
6 changes: 1 addition & 5 deletions R/macro-package-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ do_package_checks <- function(...,
build_args = NULL,
error_on = "warning",
repos = repo_default(),
type = getOption("pkgType"),
dependencies = TRUE,
timeout = Inf,
check_dir = "check") {
Expand All @@ -49,8 +48,7 @@ do_package_checks <- function(...,
get_stage("install") %>%
add_step(
step_install_deps(
repos = {{ repos }}, type = {{ type }},
dependencies = {{ dependencies }}
repos = {{ repos }}, dependencies = {{ dependencies }}
)
) %>%
add_step(
Expand Down Expand Up @@ -78,8 +76,6 @@ do_package_checks <- function(...,
#' 1. A call to [covr::codecov()] in the `"after_success"` stage
#' (only if the `codecov` flag is set)
get_stage("after_success") %>%
# FIXME: Temporarily enforcing covr dev, see https://github.com/r-lib/covr/issues/435 # nolint
add_step(step_install_github("r-lib/covr")) %>%
add_code_step(covr::codecov(quiet = FALSE))
}

Expand Down
2 changes: 1 addition & 1 deletion R/steps-blogdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BuildBlogdown <- R6Class(
},

prepare = function() {
verify_install(c("blogdown", "remotes"))
verify_install(c("blogdown"))
super$prepare()
}
),
Expand Down
2 changes: 1 addition & 1 deletion R/steps-bookdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BuildBookdown <- R6Class(
do.call(bookdown::render_book, private$bookdown_args)
},
prepare = function() {
verify_install(c("bookdown", "remotes"))
verify_install(c("bookdown"))
super$prepare()
}
),
Expand Down
57 changes: 18 additions & 39 deletions R/steps-install.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,21 @@
InstallDeps <- R6Class(
"InstallDeps",
inherit = TicStep,

public = list(
initialize = function(repos = repo_default(),
type = getOption("pkgType"),
dependencies = TRUE) {
private$repos <- repos
private$type <- type
private$dependencies <- dependencies
},

prepare = function() {
verify_install("remotes")
# FIXME: for some reason pak 0.3.0 missed knitr in the DESCRIPTION
# test if this is resolved in later versions
verify_install("knitr")
},

run = function() {
remotes::install_deps(
dependencies = private$dependencies,
repos = private$repos,
type = private$type,
build = FALSE,
INSTALL_OPTS = "--no-multiarch"
)
pak::local_install_dev_deps()
}
),

private = list(
repos = NULL,
type = NULL,
dependencies = NULL
)
)
Expand All @@ -45,18 +32,15 @@ InstallDeps <- R6Class(
#' even if the CRAN version is ahead.
#'
#' A `step_install_deps()` step installs all package dependencies declared in
#' `DESCRIPTION`, using [remotes::install_deps()].
#' `DESCRIPTION`, using [pak::local_install_dev_deps()].
#' This includes upgrading outdated packages.
#'
#' This step can only be used if a DESCRIPTION file is present in the repository
#' root.
#'
#' @param repos CRAN-like repositories to install from, defaults to
#' [repo_default()].
#' @param type Passed on to [install.packages()]. The default avoids
#' installation from source on Windows and macOS by passing
#' \code{\link{.Platform}$pkgType}.
#' @inheritParams remotes::install_deps
#' @inheritParams pak::local_install_dev_deps
#' @family steps
#' @export
#' @name step_install_pkg
Expand All @@ -68,27 +52,25 @@ InstallDeps <- R6Class(
#'
#' dsl_get()
step_install_deps <- function(repos = repo_default(),
type = getOption("pkgType"),
dependencies = TRUE) {
InstallDeps$new(repos = repos, type = type, dependencies = dependencies)
InstallDeps$new(repos = repos, dependencies = dependencies)
}

# InstallCRAN ------------------------------------------------------------------

InstallCRAN <- R6Class(
"InstallCRAN",
inherit = TicStep,

public = list(
initialize = function(package, ...) {
stopifnot(length(package) == 1)
private$package <- package
private$install_args <- list(...)
},
run = function() {
if (length(find.package(private$package, quiet = TRUE)) == 0) {
if (length(find.package(private$package)) == 0) {
rlang::exec(
install.packages,
pak::pkg_install,
pkg = private$package,
!!!private$install_args
)
Expand All @@ -108,7 +90,7 @@ InstallCRAN <- R6Class(
#' [install.packages()], but only if it's not already installed.
#'
#' @param package Package(s) to install
#' @param ... Passed on to `install.packages()` or `remotes::install_github()`.
#' @param ... Passed on to `pak::pkg_install()`.
#' @export
#' @rdname step_install_pkg
#' @examples
Expand All @@ -119,32 +101,30 @@ InstallCRAN <- R6Class(
#'
#' dsl_get()
step_install_cran <- function(package = NULL, ...,
repos = repo_default(),
type = getOption("pkgType")) {
InstallCRAN$new(package = package, repos = repos, ..., type = type)
repos = repo_default()) {
InstallCRAN$new(package = package, repos = repos, ...)
}

# InstallGithub ----------------------------------------------------------------

InstallGitHub <- R6Class(
"InstallGitHub",
inherit = TicStep,

public = list(
initialize = function(repo, ...) {
private$repo <- repo
private$install_args <- list(...)
},
run = function() {
do.call(
remotes::install_github, c(
list(repo = private$repo),
pak::pkg_install, c(
list(pkg = private$repo),
private$install_args
)
)
},
prepare = function() {
verify_install("remotes")
TRUE
}
),
private = list(
Expand All @@ -155,7 +135,7 @@ InstallGitHub <- R6Class(

#' @description
#' A `step_install_github()` step installs one or more packages from GitHub
#' via [remotes::install_github()], the packages are only installed if their
#' via [pak::pkg_install()], the packages are only installed if their
#' GitHub version is different from the locally installed version.
#'
#' @param repo Package to install in the "user/repo" format.
Expand All @@ -168,7 +148,6 @@ InstallGitHub <- R6Class(
#' add_step(step_install_github("rstudio/gt"))
#'
#' dsl_get()
step_install_github <- function(repo = NULL, ...,
type = getOption("pkgType")) {
InstallGitHub$new(repo = repo, ..., type = type)
step_install_github <- function(repo = NULL, ...) {
InstallGitHub$new(repo = repo, ...)
}
8 changes: 2 additions & 6 deletions R/steps-pkgdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,31 @@
BuildPkgdown <- R6Class(
"BuildPkgdown",
inherit = TicStep,

public = list(
initialize = function(...) {
private$pkgdown_args <- list(...)
super$initialize()
},

run = function() {
remotes::install_local(".")
# pak::local_install(".")
if (dir.exists("docs")) {
pkgdown::clean_site()
}
do.call(
pkgdown::build_site, c(list(preview = FALSE), private$pkgdown_args)
)
},

prepare = function() {
if (!file.exists("DESCRIPTION")) {
cli::cli_alert_danger("The {.code step_build_pkgdown()} step and the
{.code do_pkgdown()} macro are only available
for packages.", wrap = TRUE)
stopc("No DESCRIPTION file found.")
}
verify_install(c("pkgdown", "remotes"))
verify_install("pkgdown")
super$prepare()
}
),

private = list(
pkgdown_args = NULL
)
Expand Down
Loading

0 comments on commit ab39338

Please sign in to comment.