diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml index 82dca3c..6edfb85 100644 --- a/.github/workflows/test-action.yaml +++ b/.github/workflows/test-action.yaml @@ -50,7 +50,7 @@ jobs: uses: ./ with: path: stageddeps.elecinfra - version: v0.2.7 + version: v0.3.1 enable-bioc-repos: true enable-check: false env: diff --git a/README.md b/README.md index bad55da..262e286 100644 --- a/README.md +++ b/README.md @@ -83,14 +83,13 @@ The following options are available are available for this action: ### Inputs - * `run-system-dependencies`: _Description_: Check for and install system dependencies _Required_: `false` - _Default_: `false` + _Default_: `False` * `git-user-name`: @@ -126,11 +125,11 @@ The following options are available are available for this action: * `threads`: - *Description*: Number of threads to use. Set to 'auto' to use max available threads + _Description_: Number of threads to use. Set to 'auto' to use max available threads _Required_: `false` - _Default_: `1` + _Default_: `auto` * `cran-repos`: @@ -146,12 +145,13 @@ The following options are available are available for this action: _Required_: `false` - _Default_: `false` + _Default_: `False` * `token-mapping`: _Description_: Token mapping that is used in `staged.dependencies.token_mapping` delimited by comma. Note that you will need to set these tokens with their respective values as environment variables while using this action. + _Required_: `false` _Default_: `https://github.com=GITHUB_PAT,https://gitlab.com=GITLAB_PAT` @@ -162,7 +162,7 @@ The following options are available are available for this action: _Required_: `false` - _Default_: `false` + _Default_: `False` * `git-ref`: @@ -178,7 +178,7 @@ The following options are available are available for this action: _Required_: `false` - _Default_: `true` + _Default_: `True` * `quiet`: @@ -186,26 +186,17 @@ The following options are available are available for this action: _Required_: `false` - _Default_: `true` - -* `upgrade-remotes`: - - _Description_: If TRUE, upgrades the 'remotes' R package to the edge version - - _Required_: `false` - - _Default_: `false` + _Default_: `True` * `direction`: - _Description_: The direction to use to install dependencies. Choose between 'upstream', 'downstream' and 'all' + _Description_: The direction to use to install dependencies. Choose between 'upstream', 'downstream' and 'all' - _Required_: `false` + _Required_: `false` - _Default_: `all` + _Default_: `all` ### Outputs - None diff --git a/action.yml b/action.yml index 1011c3c..84f3bb2 100644 --- a/action.yml +++ b/action.yml @@ -56,10 +56,6 @@ inputs: description: If TRUE, suppress output required: false default: true - upgrade-remotes: - description: If TRUE, upgrades the 'remotes' R package to the edge version - required: false - default: false direction: description: The direction to use to install dependencies. Choose between 'upstream', 'downstream' and 'all' required: false @@ -81,7 +77,6 @@ runs: shell: bash env: SD_REPO_PATH: "${{ inputs.path }}" - SD_UPGRADE_REMOTES: "${{ inputs.upgrade-remotes }}" - name: Run staged dependencies run: ${GITHUB_ACTION_PATH}/staged-dependencies.R @@ -99,5 +94,4 @@ runs: SD_RENV_RESTORE: "${{ inputs.renv-restore }}" SD_GIT_REF: "${{ inputs.git-ref }}" SD_QUIET: "${{ inputs.quiet }}" - SD_UPGRADE_REMOTES: "${{ inputs.upgrade-remotes }}" SD_DIRECTION: "${{ inputs.direction }}" diff --git a/staged-dependencies.R b/staged-dependencies.R index c082e03..f545f17 100755 --- a/staged-dependencies.R +++ b/staged-dependencies.R @@ -31,7 +31,6 @@ token_mapping <- Sys.getenv( check <- Sys.getenv("SD_ENABLE_CHECK", "false") renv_restore <- Sys.getenv("SD_RENV_RESTORE", "true") sd_quiet <- isTRUE(as.logical(Sys.getenv("SD_QUIET", "true"))) -upgrade_remotes <- isTRUE(as.logical(Sys.getenv("SD_UPGRADE_REMOTES", "false"))) cat("\n==================================\n") cat("Running staged dependencies installer\n") @@ -47,7 +46,6 @@ cat(paste("git_user_name: \"", git_user_name, "\"\n", sep = "")) cat(paste("git_user_email: \"", git_user_email, "\"\n", sep = "")) cat(paste("renv_restore: \"", renv_restore, "\"\n", sep = "")) cat(paste("sd_quiet: \"", sd_quiet, "\"\n", sep = "")) -cat(paste("upgrade_remotes: \"", upgrade_remotes, "\"\n", sep = "")) cat(paste("direction: \"", direction, "\"\n", sep = "")) cat("==================================\n") @@ -68,22 +66,15 @@ options( staged.dependencies.token_mapping = split_to_map(token_mapping) ) -# Install the remotes package -if (!require("remotes", quietly = sd_quiet)) { +# Install the pak package +if (!require("pak", quietly = sd_quiet)) { install.packages( - "remotes", + "pak", upgrade = "never", Ncpus = threads ) } -# Upgrade the remotes package to get the latest bugfixes -if (upgrade_remotes == "true") { - remotes::install_github("r-lib/remotes@main") - # Reload remotes - require(remotes) -} - # Install dependencies from renv if (file.exists("renv.lock") && renv_restore == "true") { if (!require("renv", quietly = sd_quiet)) { @@ -109,13 +100,9 @@ if (file.exists("staged_dependencies.yaml")) { } if (install_sd) { cat("Installing Staged Dependencies\n\n") - remotes::install_github( - "openpharma/staged.dependencies", - ref = sd_version, - Ncpus = threads, - upgrade = "never", - force = TRUE, - quiet = sd_quiet + pak::pkg_install( + paste0("openpharma/staged.dependencies@", sd_version), + upgrade = FALSE, ) } @@ -133,7 +120,10 @@ if (file.exists("staged_dependencies.yaml")) { if (git_ref != "" && !startsWith(git_ref, "refs/pull") && !startsWith(git_ref, "refs/head")) { - x <- staged.dependencies::dependency_table(ref = git_ref, direction = direction) + x <- staged.dependencies::dependency_table( + ref = git_ref, + direction = direction + ) } else { x <- staged.dependencies::dependency_table(direction = direction) } @@ -156,13 +146,3 @@ if (file.exists("staged_dependencies.yaml")) { quiet = sd_quiet ) } - -# Install any remaining dependencies -if (!file.exists("renv.lock") || renv_restore != "true") { - remotes::install_deps( - dependencies = TRUE, - upgrade = "never", - Ncpus = threads, - quiet = sd_quiet - ) -} diff --git a/system-dependencies.R b/system-dependencies.R index 440397e..07152f0 100755 --- a/system-dependencies.R +++ b/system-dependencies.R @@ -1,60 +1,80 @@ #!/usr/bin/env Rscript repo_path <- Sys.getenv("SD_REPO_PATH", ".") -upgrade_remotes <- Sys.getenv("SD_UPGRADE_REMOTES", "") - -# temporary fix for remotes : -Sys.setenv(RSPM_ROOT = "https://packagemanager.posit.co") cat("\n==================================\n") cat("Running system dependencies installer\n") cat(paste("repo_path: \"", repo_path, "\"\n", sep = "")) cat("==================================\n") -# Install the remotes package -if (!require("remotes")) { +# Install the pak package +if (!require("pak")) { install.packages( - "remotes", + "pak", + upgrade = "never", repos = "https://cloud.r-project.org/" ) } -# Upgrade the remotes package to get the latest bugfixes -if (upgrade_remotes == "true") { - remotes::install_github("r-lib/remotes@main") - # Reload remotes - require(remotes) -} - os_info <- read.csv("/etc/os-release", sep = "=", header = FALSE) v_os_info <- setNames(os_info$V2, os_info$V1) if (v_os_info[["NAME"]] == "Ubuntu") { ubuntu_version <- as.character(v_os_info[["VERSION_ID"]]) cat(paste("Ubuntu version: \"", ubuntu_version, "\"\n", sep = "")) - sys_deps_for_pkg <- remotes::system_requirements( - os = "ubuntu", - os_release = ubuntu_version, - path = repo_path - ) - sys_pgks <- gsub("^apt-get install -y ", "", sys_deps_for_pkg) - sys_pgks <- c("libgit2-dev", sys_pgks) # For installing staged.dependencies - has_pkgs <- vapply( - sys_pgks, - function(pkg) { - system2( - "sudo", - c("dpkg", "-l", pkg), - stdout = NULL, - stderr = NULL - ) == 0 + tryCatch( + { + sys_reqs <- pak::pkg_sysreqs( + read.dcf(file.path(repo_path, "DESCRIPTION"))[,"Package"] + ) + sys_pkgs <- c(unlist(strsplit( + gsub("^apt-get -y install ", "", sys_reqs["install_scripts"]), "\\s" + ))) + if (length(sys_pkgs) > 0) { + # For installing staged.dependencies + sys_pkgs <- c("libgit2-dev", sys_pkgs) + } else { + sys_pkgs <- c("libgit2-dev") + } + cat("\nChecking if the following dependencies are installed:\n") + cat(sys_pkgs) + has_pkgs <- vapply( + sys_pkgs, + function(pkg) { + system2( + "sudo", + c("dpkg", "-l", pkg), + stdout = NULL, + stderr = NULL + ) == 0 + }, + logical(1) + ) + if (any(!has_pkgs)) { + cat("\nThe following system dependencies will be installed:\n") + cat(sys_pkgs[!has_pkgs]) + system2("sudo", c("apt-get", "update")) + system2("sudo", c("apt-get", "install", "-y", sys_pkgs[!has_pkgs])) + } else { + cat( + "\nLooks like all the required system dependencies are installed.\n" + ) + } + }, + # This error handling is with pak::pkg_sysreqs() in mind. + # If a package is missing from pak database + # (e.g. because it's not publicly available), + # pak will fail to determine system dependencies. + error = function(x) { + cat("An error occurred while installing system dependencies:\n") + message(conditionMessage(x)) }, - logical(1) + warning = function(x) { + cat("A warning occurred while installing system dependencies:\n") + message(conditionMessage(x)) + } ) - if (any(!has_pkgs)) { - system2("sudo", c("apt-get", "update")) - system2("sudo", c("apt-get", "install", "-y", sys_pgks[!has_pkgs])) - } + } else { cat(paste( "System dependencies not implemented for os:",