-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
290 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
# Set renv profile base on R version. | ||
.get_dependencies <- function(project_dir) { | ||
dependencies <- renv::dependencies("DESCRIPTION", dev = TRUE)$Package | ||
|
||
c( | ||
project_dir, | ||
dependencies | ||
) |> | ||
unique() |> | ||
renv:::renv_package_dependencies() |> | ||
names() | ||
} | ||
|
||
options(renv.snapshot.filter = .get_dependencies) | ||
|
||
if (Sys.getenv("GITHUB_ACTIONS") != "") { | ||
options(repos = c(CRAN = "https://packagemanager.posit.co/cran/latest")) | ||
Sys.setenv("RENV_AUTOLOADER_ENABLED" = FALSE) | ||
} | ||
Sys.setenv("RENV_CONFIG_SANDBOX_ENABLED" = FALSE) | ||
Sys.setenv("RENV_CONFIG_AUTO_SNAPSHOT" = FALSE) | ||
|
||
# Do not load renv by default | ||
|
||
if (identical(Sys.getenv("RENV_AUTOLOADER_ENABLED"), "")) { | ||
Sys.setenv("RENV_AUTOLOADER_ENABLED" = FALSE) | ||
} | ||
|
||
if (!isFALSE(Sys.getenv("RENV_AUTOLOADER_ENABLED"))) { | ||
.renv_profile <- paste(R.version$major, substr(R.version$minor, 1, 1), sep = ".") | ||
if (!file.exists("./renv/profile")) { | ||
if (.renv_profile %in% c("4.1", "4.2", "4.3")) { | ||
message("Set renv profile to `", .renv_profile, "`") | ||
Sys.setenv("RENV_PROFILE" = .renv_profile) | ||
} else { | ||
message("This repository do not contains the renv profile for your R version.") | ||
} | ||
} else { | ||
message( | ||
"Using renv profile from `renv/profile` file.\n", | ||
"The `", readLines("./renv/profile"), "` profile will be used." | ||
) | ||
} | ||
} | ||
|
||
source("renv/activate.R") |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
name: Deploy Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'renv/profiles/**/renv.lock' | ||
workflow_dispatch: # give possibility to run it manually | ||
|
||
permissions: write-all | ||
env: | ||
REGISTRY: ghcr.io | ||
|
||
concurrency: | ||
group: deploy-docker-image-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
get_renv_list: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.matrix.outputs.renv }} | ||
|
||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 # "2" -> To retrieve the preceding commit. | ||
|
||
- name: Get changed files in renv/profiles | ||
id: changed-files | ||
uses: tj-actions/changed-files@v35 | ||
with: | ||
files: renv/profiles/**/renv.lock | ||
|
||
# TODO: what to do with renv_legacy ? | ||
- name: Get Updated renv # note: for case schedules job, we update every docker images, and for renv.lock files updates we only update modified renv.lock versions | ||
id: matrix | ||
run: | | ||
if [[ "${{github.event_name}}" == "schedule" || "${{github.event_name}}" == "workflow_dispatch" ]] | ||
then | ||
renv_list=$(find renv/profiles | grep renv.lock ) | ||
else | ||
renv_list="${{ steps.changed-files.outputs.all_changed_files }}" | ||
fi | ||
renv_list=$(echo $renv_list | sed 's/ /", "/g') | ||
echo "renv=[\"$renv_list\"]" >> $GITHUB_OUTPUT | ||
deploy-image: | ||
needs: [ get_renv_list ] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false # if one of the job "deploy-image" fails, the other parallel jobs will just continue | ||
matrix: | ||
value: ${{ fromJson(needs.get_renv_list.outputs.matrix) }} | ||
|
||
# Token permissions | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Print message | ||
run: | | ||
echo "updating docker image for renv ${{ matrix.value }}" | ||
- name: Set image specs | ||
id: image_specs | ||
run: | | ||
package_name=$(grep "Package:" DESCRIPTION | awk '{print $NF}') | ||
r_version=$(basename $(dirname ${{ matrix.value }})) # TODO: check here if legacy renv (if yes, delete _legacy suffix and add _legacy suffix to docker im?) | ||
echo "r_version=$r_version" >> $GITHUB_OUTPUT | ||
echo "image_name=$package_name-$r_version" >> $GITHUB_OUTPUT | ||
renv=$(echo "${{ matrix.value }}" | tr -d '"') | ||
echo "renv_lock_path=$renv" >> $GITHUB_OUTPUT | ||
- name: Call deploy docker image action for every renv | ||
uses: insightsengineering/r-image-creator@v1 | ||
with: | ||
image-name: "${{ steps.image_specs.outputs.image_name }}" | ||
tag-latest: true | ||
base-image: "rocker/rstudio:${{ steps.image_specs.outputs.r_version }}" | ||
sysdeps: qpdf,libxt-dev,curl,npm,libicu-dev,libcurl4-openssl-dev,libssl-dev,make,zlib1g-dev,libfontconfig1-dev,libfreetype6-dev,libfribidi-dev,libharfbuzz-dev,libjpeg-dev,libpng-dev,libtiff-dev,pandoc,libxml2-dev,libgit2-dev,libgit2-dev,jq | ||
renv-lock-file: "${{ steps.image_specs.outputs.renv_lock_path }}" | ||
repository-owner: ${{ github.repository_owner }} | ||
repo-user: ${{ github.actor }} | ||
repo-token: "${{ secrets.GITHUB_TOKEN }}" | ||
|
||
# note: in case of 403 error when pushing to ghcr : link current repo to the given package registry - https://github.com/docker/build-push-action/issues/687 | ||
# (got to https://github.com/<user name>?tab=packages to go to packages settings) and there https://github.com/users/<user name>/packages/container/admiralci-4.0/settings |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
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.1', repos: 'https://packagemanager.posit.co/cran/2022-03-10/'} | ||
- {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/[email protected] | ||
|
||
- 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 | ||
) |> | ||
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") | ||
# 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) | ||
renv::install("[email protected]", dependencies = "none") | ||
renv::install("[email protected]", dependencies = "none") | ||
renv::settings$snapshot.type("custom") | ||
renv::snapshot(force = TRUE, prompt = FALSE) | ||
renv::record("[email protected]") | ||
renv::record("devtools") | ||
renv::record("[email protected]") | ||
renv::record("openpharma/staged.dependencies") | ||
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: [email protected] | ||
create_branch: true |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://cran.r-project.org/package=sdtm.oak |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ lock/ | |
python/ | ||
sandbox/ | ||
staging/ | ||
profile |