#92 Create function to derive reference dates in DM domain #145
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- .github/workflows/r-renv-lock.yml | |
- DESCRIPTION | |
name: Generate renv.lock | |
concurrency: | |
group: r-renv-lock-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
r-renv-lock-gen: | |
if: github.event.pull_request.draft == false | |
runs-on: ${{ matrix.config.os }} | |
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | |
strategy: | |
max-parallel: 1 | |
fail-fast: false | |
matrix: | |
config: | |
- {os: ubuntu-20.04, r: '4.2', repos: 'https://packagemanager.posit.co/cran/2023-03-15/'} | |
- {os: ubuntu-20.04, r: '4.3', repos: 'https://packagemanager.posit.co/cran/2023-04-20/'} | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
R_KEEP_PKG_SOURCE: true | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
R_CRAN_REPO: ${{ matrix.config.repos }} | |
RENV_PROFILE_NAME: ${{ matrix.config.r }} | |
R_RELEASE_LAGACY: ${{ matrix.config.legacy || false }} | |
steps: | |
- name: Get branch names | |
id: branch-name | |
uses: tj-actions/branch-names@v8 | |
- name: Checkout repo (PR) 🛎 | |
uses: actions/checkout@v3 | |
if: github.event_name == 'pull_request' | |
with: | |
ref: ${{ steps.branch-name.outputs.head_ref_branch }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: ${{ matrix.config.r }} | |
http-user-agent: ${{ matrix.config.http-user-agent }} | |
use-public-rspm: true | |
- name: Install system dependencies | |
run: sudo apt update && sudo apt install libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev libgit2-dev -y | |
- name: Collect dependencies | |
run: | | |
Sys.setenv("RENV_CONFIG_SANDBOX_ENABLED" = FALSE) | |
Sys.setenv("RENV_CONFIG_AUTO_SNAPSHOT" = FALSE) | |
source("renv/activate.R") | |
lock_gen_version <- "0.1.0" | |
legacy <- identical(Sys.getenv("R_RELEASE_LAGACY"), "true") | |
renv_profile <- Sys.getenv("RENV_PROFILE_NAME", "dev") | |
if (legacy) renv_profile <- paste0(renv_profile, "_legacy") | |
cran_r_release <- Sys.getenv("R_CRAN_REPO", "https://packagemanager.posit.co/cran/2023-03-15/") | |
cran_latest <- Sys.getenv("CRAN_R_LATEST", "https://packagemanager.posit.co/cran/latest") | |
unlink(file.path("renv", "profiles", renv_profile), recursive = TRUE) | |
cat("\n==================================\n") | |
cat("Create renv.lock files\n") | |
cat(paste("renv_profile: \"", renv_profile, "\"\n", sep = "")) | |
cat(paste("cran_r_release: \"", cran_r_release, "\"\n", sep = "")) | |
cat(paste("cran_latest: \"", cran_latest, "\"\n", sep = "")) | |
cat("==================================\n") | |
renv::activate(profile = renv_profile) | |
renv::settings$snapshot.type("custom") | |
.get_dependencies <- function(project_dir) { | |
dependencies <- renv::dependencies("DESCRIPTION", dev = TRUE)$Package | |
c( | |
project_dir, | |
dependencies, | |
"devtools", | |
"staged.dependencies", | |
"styler" | |
) |> | |
unique() |> | |
renv:::renv_package_dependencies() |> | |
names() | |
} | |
options(renv.snapshot.filter = .get_dependencies) | |
# CRAN repo from R release | |
options("repos" = c("RSPM" = cran_r_release)) | |
renv::install("openpharma/staged.dependencies", repos = options("repos")) | |
renv::install("devtools", repos = options("repos")) | |
# Packages from stage dependencies to ignore | |
renv::settings$ignored.packages(c("admiraldev")) | |
# Install dependencies | |
renv::settings$snapshot.type("explicit") | |
renv::install(repos = options("repos")) | |
# Set newest CRAN for few packages upgrade | |
options("repos" = c( | |
"CRAN" = cran_latest, | |
"RSPM" = cran_r_release | |
)) | |
# Install latest remotes version | |
renv::install("remotes", repos = cran_latest) | |
install_min_version <- function(pkg, version) { | |
upgrade <- try(packageVersion(pkg) >= version, silent = TRUE) | |
if (!isTRUE(upgrade)) { | |
message("Upgrade `", pkg, "` to `", version, "`") | |
renv::install(paste0(pkg, "@", version), dependencies = "none") | |
} | |
} | |
renv::install("R.cache", dependencies = "Imports") | |
install_min_version("vctrs", "0.4.1") | |
install_min_version("rlang", "1.0.6") | |
renv::install("styler@1.10.2", dependencies = "none") | |
renv::install("roxygen2@7.3.2", dependencies = "none") | |
renv::settings$snapshot.type("custom") | |
renv::snapshot(force = TRUE, prompt = FALSE) | |
if (identical(renv_profile, "4.3")) { | |
file.copy(renv::paths$lockfile(), "renv.lock", overwrite = TRUE) | |
} | |
shell: Rscript --vanilla {0} | |
- name: Commit and push changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: Automatic renv profile update. | |
file_pattern: 'renv.lock renv/profiles/*' | |
commit_user_name: pharmaverse-bot | |
commit_user_email: 113703390+pharmaverse-bot@users.noreply.github.com | |
create_branch: true |