diff --git a/.Rprofile b/.Rprofile index 81b960f5..8499baf2 100644 --- a/.Rprofile +++ b/.Rprofile @@ -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") diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1bf6a654..677d0521 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -25,7 +25,7 @@ of overall issues. * Familiarize yourself with our [programming strategy](https://pharmaverse.github.io/admiraldev/main/articles/programming_strategy.html), guidance for [GitHub usage](https://pharmaverse.github.io/admiraldev/main/articles/git_usage.html) and [unit testing](https://pharmaverse.github.io/admiraldev/main/articles/unit_test_guidance.html). - * All newly [created issues](https://github.com/pharmaverse/aok/issues) will be + * All newly [created issues](https://github.com/pharmaverse/oak/issues) will be reviewed within the next backlog meeting and the creator will receive an initial feedback via a comment. Someone from the core development team will then triage new issues by assigning the appropriate labels (such as “user diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml new file mode 100644 index 00000000..7df17ec5 --- /dev/null +++ b/.github/workflows/build_docker_image.yml @@ -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/?tab=packages to go to packages settings) and there https://github.com/users//packages/container/admiralci-4.0/settings diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index a8c9a5d3..cc1cd12a 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -92,11 +92,11 @@ jobs: if: > github.event_name != 'release' with: - r-version: "4.3" + r-version: "4.1" # Whether to skip code coverage badge creation # Setting to 'false' will require you to create # an orphan branch called 'badges' in your repository - skip-coverage-badges: false + skip-coverage-badges: true man-pages: name: Man Pages uses: pharmaverse/admiralci/.github/workflows/man-pages.yml@main diff --git a/.github/workflows/r-renv-lock.yml b/.github/workflows/r-renv-lock.yml new file mode 100644 index 00000000..c84199f6 --- /dev/null +++ b/.github/workflows/r-renv-lock.yml @@ -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/branch-names@v5.4 + + - 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("styler@1.10.2", dependencies = "none") + renv::install("roxygen2@7.2.3", dependencies = "none") + + renv::settings$snapshot.type("custom") + renv::snapshot(force = TRUE, prompt = FALSE) + renv::record("roxygen@7.2.3") + renv::record("devtools") + renv::record("styler@1.10.2") + 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: 113703390+pharmaverse-bot@users.noreply.github.com + create_branch: true diff --git a/.lintr b/.lintr index 2ef2159c..a6fd5cfc 100644 --- a/.lintr +++ b/.lintr @@ -2,7 +2,6 @@ linters: linters_with_defaults( any_duplicated_linter(), any_is_na_linter(), backport_linter("oldrel-4"), - consecutive_assertion_linter(), expect_comparison_linter(), expect_identical_linter(), expect_length_linter(), diff --git a/.lycheeignore b/.lycheeignore index e69de29b..4aa17b34 100644 --- a/.lycheeignore +++ b/.lycheeignore @@ -0,0 +1 @@ +https://cran.r-project.org/package=sdtm.oak diff --git a/DESCRIPTION b/DESCRIPTION index eef249e2..d253c411 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Depends: R (>= 4.1) Imports: - rlang + rlang (>= 1.0.0) Suggests: knitr, rmarkdown, diff --git a/renv/.gitignore b/renv/.gitignore index 0ec0cbba..db03f4af 100644 --- a/renv/.gitignore +++ b/renv/.gitignore @@ -5,3 +5,4 @@ lock/ python/ sandbox/ staging/ +profile