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

Use pak instead of remotes #38

Merged
merged 25 commits into from
May 17, 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
2 changes: 1 addition & 1 deletion .github/workflows/test-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 11 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ The following options are available are available for this action:

<!-- BEGIN_ACTION_DOC -->
### Inputs

* `run-system-dependencies`:

_Description_: Check for and install system dependencies

_Required_: `false`

_Default_: `false`
_Default_: `False`

* `git-user-name`:

Expand Down Expand Up @@ -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`:

Expand All @@ -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`
Expand All @@ -162,7 +162,7 @@ The following options are available are available for this action:

_Required_: `false`

_Default_: `false`
_Default_: `False`

* `git-ref`:

Expand All @@ -178,34 +178,25 @@ The following options are available are available for this action:

_Required_: `false`

_Default_: `true`
_Default_: `True`

* `quiet`:

_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`
_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
<!-- END_ACTION_DOC -->

Expand Down
6 changes: 0 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}"
40 changes: 10 additions & 30 deletions staged-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")

Expand All @@ -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)) {
Expand All @@ -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,
)
}

Expand All @@ -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)
}
Expand All @@ -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
)
}
90 changes: 55 additions & 35 deletions system-dependencies.R
Original file line number Diff line number Diff line change
@@ -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"]

Check warning on line 28 in system-dependencies.R

View workflow job for this annotation

GitHub Actions / Lint Code Base

file=/github/workspace/system-dependencies.R,line=28,col=56,[commas_linter] Commas should always have a space after.
)
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:",
Expand Down
Loading