From 9ffe90ee82351f75b63c6a2277054c414de1b113 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Fri, 3 Jan 2025 08:52:50 +0100 Subject: [PATCH 01/14] chore: restored spellcheck --- .github/workflows/main.yml | 73 ++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6e9e7404..b2e48b2c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ # the developement process. When package is ready to # be published, revisit and add release-related # workflows. -name: admiral CI/CD Workflows +name: admiral CI/CD Wortkflows on: workflow_dispatch: @@ -32,49 +32,46 @@ jobs: id: get_r_version run: echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT shell: bash + spellcheck: name: Spelling - uses: pharmaverse/admiralci/.github/workflows/spellcheck.yml@main - if: github.event_name == 'pull_request' - needs: get_r_version - with: - r-version: "${{ needs.get_r_version.outputs.r-version }}" - linter: - name: Lint - uses: pharmaverse/admiralci/.github/workflows/lintr.yml@main - needs: get_r_version - if: github.event_name == 'pull_request' - with: - r-version: "${{ needs.get_r_version.outputs.r-version }}" - man-pages: - name: Man Pages - uses: pharmaverse/admiralci/.github/workflows/man-pages.yml@main - if: github.event_name == 'pull_request' - needs: get_r_version - with: - r-version: "${{ needs.get_r_version.outputs.r-version }}" - tests: - name: Tests runs-on: ubuntu-latest needs: get_r_version container: image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps - - name: Install dependencies - run: | - Rscript -e 'remotes::install_deps(dependencies = TRUE)' + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: true + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} - - name: Run tests - shell: Rscript {0} - run: | - devtools::load_all(".") - devtools::test() - check: - name: Check - uses: pharmaverse/admiralci/.github/workflows/r-cmd-check.yml@main - if: github.event_name == 'pull_request' - with: - error-on: error + - name: Run Spellcheck + uses: insightsengineering/r-spellcheck-action@v3 \ No newline at end of file From e149ec6687e89b858894cf1154f4b92bd2c87f67 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Fri, 3 Jan 2025 09:08:39 +0100 Subject: [PATCH 02/14] chore: restored linting --- .github/workflows/main.yml | 58 +++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2e48b2c..b3d672e1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,4 +74,60 @@ jobs: git-ref: ${{ steps.branch-name.outputs.current_branch }} - name: Run Spellcheck - uses: insightsengineering/r-spellcheck-action@v3 \ No newline at end of file + uses: insightsengineering/r-spellcheck-action@v3 + + lint: + name: Lint + runs-on: ubuntu-latest + needs: get_r_version + container: + image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" + steps: + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: true + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install latest release of lintr + run: | + install.packages("lintr", repos = "https://packagemanager.posit.co/cran/latest/") + shell: Rscript {0} + + - name: Lint + run: | + lints <- lintr::lint_package() + if (length(lints) > 0L) { + print(lints) + stop("Lints detected. Please review and adjust code according to the comments provided.", call. = FALSE) + } + shell: Rscript {0} \ No newline at end of file From e52220808ed4b8e7a7df21d8f4539d0f4ec6b4d7 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Fri, 3 Jan 2025 09:25:09 +0100 Subject: [PATCH 03/14] chore: restore man-pages --- .github/workflows/main.yml | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b3d672e1..734a72b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -130,4 +130,77 @@ jobs: print(lints) stop("Lints detected. Please review and adjust code according to the comments provided.", call. = FALSE) } - shell: Rscript {0} \ No newline at end of file + shell: Rscript {0} + + man-pages: + name: Man Pages + runs-on: ubuntu-latest + needs: get_r_version + container: + image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" + steps: + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo + uses: actions/checkout@v4.2.2 + if: github.event_name == 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: false + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies from DESCRIPTION + run: | + remotes::install_local(force = TRUE, dependencies = TRUE) + shell: Rscript {0} + env: + R_REMOTES_STANDALONE: "true" + + - name: Generate man pages + run: roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace')) + shell: Rscript {0} + + - name: Set-up safe dir + run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" + shell: bash + + - name: Roxygen check + run: | + git status -s + if [[ -n `git status -s | grep -E "man|DESCRIPTION"` ]] + then { + ROXYGEN_VERSION="$(Rscript -e 'packageVersion("roxygen2")' | awk '{print $NF}')" + echo "šŸ™ˆ Manuals are not up-to-date with roxygen comments!" + echo "šŸ”€ The following differences were noted:" + git diff man/* DESCRIPTION + echo -e "\nšŸ’» Please rerun the following command on your workstation and push your changes" + echo "--------------------------------------------------------------------" + echo "roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace'))" + echo "--------------------------------------------------------------------" + echo "ā„¹ roxygen2 version that was used in this workflow: $ROXYGEN_VERSION" + echo "šŸ™ Please ensure that the 'RoxygenNote' field in the DESCRIPTION file matches this version" + exit 1 + } else { + echo "šŸ’š Manuals are up-to-date with roxygen comments" + } + fi + shell: bash + From 3b24b8b10e2e5a02afd2163d4e4067aaef51e798 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Fri, 3 Jan 2025 09:25:48 +0100 Subject: [PATCH 04/14] chore: restore tests --- .github/workflows/main.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 734a72b3..31465046 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -203,4 +203,28 @@ jobs: } fi shell: bash + tests: + name: Tests + runs-on: ubuntu-latest + needs: get_r_version + container: + image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install system dependencies + run: | + apt-get install -y --no-install-recommends \ + libudunits2-dev + + - name: Install dependencies + run: | + Rscript -e 'remotes::install_deps(dependencies = TRUE)' + + - name: Run tests + shell: Rscript {0} + run: | + devtools::load_all(".") + devtools::test() From 94c80f4d3cd5fc16796179f55700bc0e6788ca71 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Tue, 7 Jan 2025 07:09:16 +0100 Subject: [PATCH 05/14] feat: restored R CMD Check, as-is in admiralci package --- .github/workflows/main.yml | 202 +++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 31465046..382bbd21 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -227,4 +227,206 @@ jobs: run: | devtools::load_all(".") devtools::test() + + check: + runs-on: ubuntu-latest + needs: get_r_version + container: + image: "ghcr.io/pharmaverse/admiralci-${{ matrix.r_version }}:latest" + name: (${{ matrix.r_version }}) + strategy: + fail-fast: false + matrix: + r_version: ["release", "devel", "oldrel"] + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: true + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + R_REPOS: "https://cran.r-project.org" + DEPS_IGNORE: >- + pharmaversesdtm, + pharmaverseadam, + admiral, + admiraldev, + admiralophtha, + admiralonco, + admiralvaccine, + staged.dependencies + steps: + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo (PR) šŸ›Ž + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: | + github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + with: + git-ref: ${{ steps.branch-name.outputs.current_branch }} + run-system-dependencies: false + renv-restore: false + enable-check: false + cran-repos: "https://cloud.r-project.org" + direction: upstream + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies from DESCRIPTION + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + run: | + remotes::install_local(force = TRUE, dependencies = TRUE) + shell: Rscript {0} + + - name: Upload dependencies artifact + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + run: | + dir.create("/workspace/tmp") + library(dplyr) + installed_packages <- as.data.frame(installed.packages()) + packages_to_remove <- Sys.getenv("DEPS_IGNORE", "") + packages_to_remove <- unlist(strsplit(packages_to_remove, ",")) + installed_packages <- installed_packages %>% filter(LibPath != "/usr/local/lib/R/library") %>% # remove pre-built deps + filter(!Package %in% packages_to_remove) + # save deps as csv file + write.csv(installed_packages, "/workspace/tmp/deps-${{ matrix.r_version }}.csv", row.names = FALSE) + # create also renv.lock file + setwd("/workspace/tmp") + + renv_lock <- list( + "R" = list( + "Version" = paste(R.version$major, R.version$minor, sep=".") + ), + "Repositories" = list( + list(Name = "CRAN", URL = Sys.getenv("R_REPOS")) + ), + "Packages" = list() + ) + + # Populate with information about each package + for (package in installed_packages$Package) { + dep_name <- package + dep_version <- installed_packages[installed_packages$Package == package, "Version"] + + version_parts <- strsplit(dep_version, "\\.")[[1]] + if (length(version_parts) == 4) { + print(sprintf("skipping installation of dep %s", dep_name)) + } else { + print(sprintf("append dependency %s - version %s", dep_name, dep_version)) + requirements <- tools::package_dependencies(dep_name, recursive = TRUE) + have_requirements <- length(requirements[[1]]) > 0 + if (have_requirements) { + renv_lock[["Packages"]][[dep_name]] <- list( + "Package" = dep_name, + "Version" = dep_version, + "Source" = "Repository", + "Repository" = "CRAN", + "Requirements" = requirements[[dep_name]] + ) + } else { + renv_lock[["Packages"]][[dep_name]] <- list( + "Package" = dep_name, + "Version" = dep_version, + "Source" = "Repository", + "Repository" = "CRAN" + ) + } + } + } + + # Write the list to a JSON file (renv.lock) + writeLines(jsonlite::toJSON(renv_lock, pretty = TRUE, auto_unbox = TRUE), "renv-${{ matrix.r_version }}.lock") + print("generated renv.lock content") + system("cat renv-${{ matrix.r_version }}.lock") + shell: Rscript {0} + + - name: Upload deps.csv and renv.lock artifacts + uses: actions/upload-artifact@v4 + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + with: + name: deps-${{ matrix.r_version }} + path: | + /workspace/tmp/ + + - name: Check Version + id: check_version + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + run: | + maintenance_version="F" + description_dat <- readLines("DESCRIPTION") + for (i in seq_along(description_dat)) { + if (grepl("^Version:", description_dat[i])) { + current_version <- sub("^Version: ", "", description_dat[i]) + version_parts <- strsplit(current_version, "\\.")[[1]] + # check if maintenance version + if (length(version_parts) == 4) { + print("Maintenance version detected (format X.Y.Z.M with M >= 9000)") + maintenance_version="T" + } + } + } + cat(sprintf("maintenance_version=%s", maintenance_version), file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE) + shell: Rscript {0} + + - name: Check + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + _R_CHECK_FORCE_SUGGESTS_: false + run: | + unlink("tmp",recursive=TRUE) + if ("${{ steps.check_version.outputs.maintenance_version }}" == "T"){ + Sys.setenv("_R_CHECK_CRAN_INCOMING_SKIP_LARGE_VERSION_" = TRUE) + } + if (!requireNamespace("rcmdcheck", quietly = TRUE)) install.packages("rcmdcheck") + options(crayon.enabled = TRUE) + check_error_on <- "error" + if (check_error_on == "") { + check_error_on <- "note" + } + rcmdcheck::rcmdcheck( + args = c("--no-manual", "--as-cran"), + error_on = check_error_on, + check_dir = "check" + ) + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: r${{ matrix.r_version }}-results + path: check From a99da4cc3fb2e60c70f7d6378d5820c4993f8e97 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Tue, 7 Jan 2025 14:17:49 +0100 Subject: [PATCH 06/14] chore: installing deps using pak --- .github/workflows/main.yml | 17 ++++++----------- DESCRIPTION | 1 + 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 382bbd21..2fd9cacf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -169,7 +169,7 @@ jobs: - name: Install dependencies from DESCRIPTION run: | - remotes::install_local(force = TRUE, dependencies = TRUE) + pak::local_install_deps(dependencies = TRUE) shell: Rscript {0} env: R_REMOTES_STANDALONE: "true" @@ -213,14 +213,9 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Install system dependencies - run: | - apt-get install -y --no-install-recommends \ - libudunits2-dev - - name: Install dependencies run: | - Rscript -e 'remotes::install_deps(dependencies = TRUE)' + pak::local_install_deps(dependencies = TRUE) - name: Run tests shell: Rscript {0} @@ -230,10 +225,10 @@ jobs: check: runs-on: ubuntu-latest - needs: get_r_version + needs: tests container: image: "ghcr.io/pharmaverse/admiralci-${{ matrix.r_version }}:latest" - name: (${{ matrix.r_version }}) + name: Check (${{ matrix.r_version }}) strategy: fail-fast: false matrix: @@ -257,7 +252,7 @@ jobs: id: branch-name uses: tj-actions/branch-names@v8 - - name: Checkout repo (PR) šŸ›Ž + - name: Checkout repo uses: actions/checkout@v4.2.2 if: | github.event_name == 'pull_request' @@ -299,7 +294,7 @@ jobs: (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || matrix.r_version != 'devel' run: | - remotes::install_local(force = TRUE, dependencies = TRUE) + pak::local_install_deps(dependencies = TRUE) shell: Rscript {0} - name: Upload dependencies artifact diff --git a/DESCRIPTION b/DESCRIPTION index 2466aac4..ddc33acf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,6 +55,7 @@ Imports: tidyr, tools, utils, + units, zip Encoding: UTF-8 Roxygen: list(markdown = TRUE) From 2436ea9041f8646219965edc035b650bbd7914a3 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Tue, 7 Jan 2025 14:33:42 +0100 Subject: [PATCH 07/14] chore: added docstrings, minor readability improvements --- .github/workflows/main.yml | 52 ++++++++++++-------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2fd9cacf..d68341c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,14 @@ # the developement process. When package is ready to # be published, revisit and add release-related # workflows. -name: admiral CI/CD Wortkflows +# Instead of using reusable actions provided by admiralci, +# the actions are inlined in the workflow file. This is +# because some of the R dependencies required system packages +# not available/installable using reusable actions. +# If any updates are available, the workflow should be +# updated manually. +# Last update: 2025-01-07 +name: Modfified Admiral CI/CD Wortkflows on: workflow_dispatch: @@ -51,12 +58,6 @@ jobs: ref: ${{ steps.branch-name.outputs.head_ref_branch }} repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Checkout repository - uses: actions/checkout@v4.2.2 - if: github.event_name != 'pull_request' - with: - ref: ${{ steps.branch-name.outputs.head_ref_branch }} - - name: Restore cache uses: actions/cache@v4 with: @@ -94,12 +95,6 @@ jobs: ref: ${{ steps.branch-name.outputs.head_ref_branch }} repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Checkout repository - uses: actions/checkout@v4.2.2 - if: github.event_name != 'pull_request' - with: - ref: ${{ steps.branch-name.outputs.head_ref_branch }} - - name: Restore cache uses: actions/cache@v4 with: @@ -115,22 +110,21 @@ jobs: enable-check: false direction: upstream git-ref: ${{ steps.branch-name.outputs.current_branch }} - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - name: Install latest release of lintr + shell: Rscript {0} run: | install.packages("lintr", repos = "https://packagemanager.posit.co/cran/latest/") - shell: Rscript {0} + - name: Lint + shell: Rscript {0} run: | lints <- lintr::lint_package() if (length(lints) > 0L) { print(lints) stop("Lints detected. Please review and adjust code according to the comments provided.", call. = FALSE) } - shell: Rscript {0} man-pages: name: Man Pages @@ -164,15 +158,10 @@ jobs: enable-check: false direction: upstream git-ref: ${{ steps.branch-name.outputs.current_branch }} - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - name: Install dependencies from DESCRIPTION + - name: Install dependencies run: | - pak::local_install_deps(dependencies = TRUE) - shell: Rscript {0} - env: - R_REMOTES_STANDALONE: "true" + Rscript -e 'pak::local_install_deps(dependencies = TRUE)' - name: Generate man pages run: roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace')) @@ -203,6 +192,7 @@ jobs: } fi shell: bash + tests: name: Tests runs-on: ubuntu-latest @@ -215,7 +205,7 @@ jobs: - name: Install dependencies run: | - pak::local_install_deps(dependencies = TRUE) + Rscript -e 'pak::local_install_deps(dependencies = TRUE)' - name: Run tests shell: Rscript {0} @@ -260,13 +250,6 @@ jobs: ref: ${{ steps.branch-name.outputs.head_ref_branch }} repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Checkout repository - uses: actions/checkout@v4.2.2 - if: | - github.event_name != 'pull_request' - with: - ref: ${{ steps.branch-name.outputs.head_ref_branch }} - - name: Restore cache uses: actions/cache@v4 with: @@ -286,16 +269,13 @@ jobs: enable-check: false cran-repos: "https://cloud.r-project.org" direction: upstream - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - name: Install dependencies from DESCRIPTION if: | (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || matrix.r_version != 'devel' run: | - pak::local_install_deps(dependencies = TRUE) - shell: Rscript {0} + Rscript -e 'pak::local_install_deps(dependencies = TRUE)' - name: Upload dependencies artifact if: | From 0b06b6e2b83ec17c24600a804bce29215de1db15 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Tue, 7 Jan 2025 14:36:22 +0100 Subject: [PATCH 08/14] chore: other workflows are required before running check --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d68341c4..d36165f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ # If any updates are available, the workflow should be # updated manually. # Last update: 2025-01-07 -name: Modfified Admiral CI/CD Wortkflows +name: Modified Admiral CI/CD Wortkflows on: workflow_dispatch: @@ -215,7 +215,11 @@ jobs: check: runs-on: ubuntu-latest - needs: tests + needs: + - spellcheck + - tests + - lint + - man-pages container: image: "ghcr.io/pharmaverse/admiralci-${{ matrix.r_version }}:latest" name: Check (${{ matrix.r_version }}) From 2f07da8fbe2aa7a7de2d5608516ff2728d18cd23 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Tue, 7 Jan 2025 14:49:34 +0100 Subject: [PATCH 09/14] chore: more docs --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d36165f5..d820e916 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,8 @@ # the developement process. When package is ready to # be published, revisit and add release-related # workflows. +# The below workflows are based on those provided by admiralci. +# The testing workflow is custom. # Instead of using reusable actions provided by admiralci, # the actions are inlined in the workflow file. This is # because some of the R dependencies required system packages From c52bbec435322c3238555f1b9c4ba503a9abe5f4 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Thu, 9 Jan 2025 08:57:28 +0100 Subject: [PATCH 10/14] chore: copy over admiralci workflows with minimal changes --- .github/workflows/lintr.yml | 145 ++++++++++++ .github/workflows/main.yml | 379 ++---------------------------- .github/workflows/man-pages.yml | 111 +++++++++ .github/workflows/r-cmd-check.yml | 227 ++++++++++++++++++ .github/workflows/spellcheck.yml | 88 +++++++ 5 files changed, 597 insertions(+), 353 deletions(-) create mode 100644 .github/workflows/lintr.yml create mode 100644 .github/workflows/man-pages.yml create mode 100644 .github/workflows/r-cmd-check.yml create mode 100644 .github/workflows/spellcheck.yml diff --git a/.github/workflows/lintr.yml b/.github/workflows/lintr.yml new file mode 100644 index 00000000..2f855d93 --- /dev/null +++ b/.github/workflows/lintr.yml @@ -0,0 +1,145 @@ +on: + workflow_dispatch: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: choice + options: + - devel + - latest + lint-all-files: + description: "Lint all files every time" + default: "false" + required: false + type: string + latest-lintr: + description: "Latest lintr CRAN release" + default: "false" + required: false + type: string + install-package: + description: "Install package locally." + default: "false" + required: false + type: string + workflow_call: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: string + lint-all-files: + description: "Lint all files every time" + default: "false" + required: false + type: string + latest-lintr: + description: "Latest lintr CRAN release" + default: "false" + required: false + type: string + install-package: + description: "Install package locally." + default: "false" + required: false + type: string + +name: Lint + +concurrency: + group: lint-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + container: + image: "ghcr.io/pharmaverse/admiralci-${{ inputs.r-version }}:latest" + if: > + !contains(github.event.commits[0].message, '[skip lint]') + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + ##################### BEGIN boilerplate steps ##################### + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo (PR) šŸ›Ž + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: true + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install latest release of lintr + run: | + install.packages("lintr", repos = "https://packagemanager.posit.co/cran/latest/") + shell: Rscript {0} + if: ${{ inputs.latest-lintr == 'true' }} + + - name: Install package + run: renv::install(".", dependencies = "no-deps") + shell: Rscript {0} + if: ${{ inputs.install-package == 'true' }} + ##################### END boilerplate steps ##################### + + - name: Changed files + id: files + uses: Ana06/get-changed-files@v2.2.0 + with: + format: "json" + filter: "*" + + - name: Lint + run: | + exclusions_list <- NULL + if (!identical("${{ inputs.lint-all-files }}", "true")) { + changed_files <- jsonlite::fromJSON('${{ steps.files.outputs.added_modified }}') + all_files <- list.files(recursive = TRUE) + exclusions_list <- if (any(changed_files %in% c(".lintr", "renv.lock"))) { + as.list(setdiff(all_files, changed_files)) + } else { + NULL + } + } + lints <- lintr::lint_package(exclusions = exclusions_list) + saveRDS(lints, file = "lints.rds") + shell: Rscript {0} + + - name: Error if lints are detected + run: | + lints <- readRDS("lints.rds") + if (length(lints) > 0L) { + print(lints) + stop("Lints detected. Please review and adjust code according to the comments provided.", call. = FALSE) + } + shell: Rscript {0} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d820e916..468da33f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,16 +3,7 @@ # the developement process. When package is ready to # be published, revisit and add release-related # workflows. -# The below workflows are based on those provided by admiralci. -# The testing workflow is custom. -# Instead of using reusable actions provided by admiralci, -# the actions are inlined in the workflow file. This is -# because some of the R dependencies required system packages -# not available/installable using reusable actions. -# If any updates are available, the workflow should be -# updated manually. -# Last update: 2025-01-07 -name: Modified Admiral CI/CD Wortkflows +name: admiral CI/CD Workflows on: workflow_dispatch: @@ -41,160 +32,28 @@ jobs: id: get_r_version run: echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT shell: bash - spellcheck: name: Spelling - runs-on: ubuntu-latest + uses: ./.github/workflows/spellcheck.yml + if: github.event_name == 'pull_request' needs: get_r_version - container: - image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" - steps: - - name: Get branch names - id: branch-name - uses: tj-actions/branch-names@v8 - - - name: Checkout repo - uses: actions/checkout@v4.2.2 - 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: Restore cache - uses: actions/cache@v4 - with: - path: | - ~/.staged.dependencies - key: staged-deps - - - name: Run Staged dependencies - uses: insightsengineering/staged-dependencies-action@v1 - with: - run-system-dependencies: true - renv-restore: false - enable-check: false - direction: upstream - git-ref: ${{ steps.branch-name.outputs.current_branch }} - - - name: Run Spellcheck - uses: insightsengineering/r-spellcheck-action@v3 - - lint: + with: + r-version: "${{ needs.get_r_version.outputs.r-version }}" + linter: name: Lint - runs-on: ubuntu-latest + uses: ./.github/workflows/lintr.yml needs: get_r_version - container: - image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" - steps: - - name: Get branch names - id: branch-name - uses: tj-actions/branch-names@v8 - - - name: Checkout repo - uses: actions/checkout@v4.2.2 - 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: Restore cache - uses: actions/cache@v4 - with: - path: | - ~/.staged.dependencies - key: staged-deps - - - name: Run Staged dependencies - uses: insightsengineering/staged-dependencies-action@v1 - with: - run-system-dependencies: true - renv-restore: false - enable-check: false - direction: upstream - git-ref: ${{ steps.branch-name.outputs.current_branch }} - - - name: Install latest release of lintr - shell: Rscript {0} - run: | - install.packages("lintr", repos = "https://packagemanager.posit.co/cran/latest/") - - - - name: Lint - shell: Rscript {0} - run: | - lints <- lintr::lint_package() - if (length(lints) > 0L) { - print(lints) - stop("Lints detected. Please review and adjust code according to the comments provided.", call. = FALSE) - } - + if: github.event_name == 'pull_request' + with: + r-version: "${{ needs.get_r_version.outputs.r-version }}" man-pages: name: Man Pages - runs-on: ubuntu-latest + uses: ./.github/workflows/man-pages.yml needs: get_r_version - container: - image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" - steps: - - name: Get branch names - id: branch-name - uses: tj-actions/branch-names@v8 - - - name: Checkout repo - uses: actions/checkout@v4.2.2 - if: github.event_name == 'pull_request' - with: - ref: ${{ steps.branch-name.outputs.head_ref_branch }} - - - name: Restore cache - uses: actions/cache@v4 - with: - path: | - ~/.staged.dependencies - key: staged-deps - - - name: Run Staged dependencies - uses: insightsengineering/staged-dependencies-action@v1 - with: - run-system-dependencies: false - renv-restore: false - enable-check: false - direction: upstream - git-ref: ${{ steps.branch-name.outputs.current_branch }} - - - name: Install dependencies - run: | - Rscript -e 'pak::local_install_deps(dependencies = TRUE)' - - - name: Generate man pages - run: roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace')) - shell: Rscript {0} - - - name: Set-up safe dir - run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" - shell: bash - - - name: Roxygen check - run: | - git status -s - if [[ -n `git status -s | grep -E "man|DESCRIPTION"` ]] - then { - ROXYGEN_VERSION="$(Rscript -e 'packageVersion("roxygen2")' | awk '{print $NF}')" - echo "šŸ™ˆ Manuals are not up-to-date with roxygen comments!" - echo "šŸ”€ The following differences were noted:" - git diff man/* DESCRIPTION - echo -e "\nšŸ’» Please rerun the following command on your workstation and push your changes" - echo "--------------------------------------------------------------------" - echo "roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace'))" - echo "--------------------------------------------------------------------" - echo "ā„¹ roxygen2 version that was used in this workflow: $ROXYGEN_VERSION" - echo "šŸ™ Please ensure that the 'RoxygenNote' field in the DESCRIPTION file matches this version" - exit 1 - } else { - echo "šŸ’š Manuals are up-to-date with roxygen comments" - } - fi - shell: bash - + if: github.event_name == 'pull_request' + with: + r-version: "${{ needs.get_r_version.outputs.r-version }}" + tests: name: Tests runs-on: ubuntu-latest @@ -205,209 +64,23 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Install system dependencies + run: | + apt-get install -y --no-install-recommends \ + libudunits2-dev + - name: Install dependencies run: | - Rscript -e 'pak::local_install_deps(dependencies = TRUE)' + Rscript -e 'remotes::install_deps(dependencies = TRUE)' - name: Run tests shell: Rscript {0} run: | devtools::load_all(".") devtools::test() - check: - runs-on: ubuntu-latest - needs: - - spellcheck - - tests - - lint - - man-pages - container: - image: "ghcr.io/pharmaverse/admiralci-${{ matrix.r_version }}:latest" - name: Check (${{ matrix.r_version }}) - strategy: - fail-fast: false - matrix: - r_version: ["release", "devel", "oldrel"] - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - R_KEEP_PKG_SOURCE: true - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - R_REPOS: "https://cran.r-project.org" - DEPS_IGNORE: >- - pharmaversesdtm, - pharmaverseadam, - admiral, - admiraldev, - admiralophtha, - admiralonco, - admiralvaccine, - staged.dependencies - steps: - - name: Get branch names - id: branch-name - uses: tj-actions/branch-names@v8 - - - name: Checkout repo - uses: actions/checkout@v4.2.2 - 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: Restore cache - uses: actions/cache@v4 - with: - path: | - ~/.staged.dependencies - key: staged-deps - - - name: Run Staged dependencies - uses: insightsengineering/staged-dependencies-action@v1 - if: | - (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || - matrix.r_version != 'devel' - with: - git-ref: ${{ steps.branch-name.outputs.current_branch }} - run-system-dependencies: false - renv-restore: false - enable-check: false - cran-repos: "https://cloud.r-project.org" - direction: upstream - - - name: Install dependencies from DESCRIPTION - if: | - (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || - matrix.r_version != 'devel' - run: | - Rscript -e 'pak::local_install_deps(dependencies = TRUE)' - - - name: Upload dependencies artifact - if: | - (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || - matrix.r_version != 'devel' - run: | - dir.create("/workspace/tmp") - library(dplyr) - installed_packages <- as.data.frame(installed.packages()) - packages_to_remove <- Sys.getenv("DEPS_IGNORE", "") - packages_to_remove <- unlist(strsplit(packages_to_remove, ",")) - installed_packages <- installed_packages %>% filter(LibPath != "/usr/local/lib/R/library") %>% # remove pre-built deps - filter(!Package %in% packages_to_remove) - # save deps as csv file - write.csv(installed_packages, "/workspace/tmp/deps-${{ matrix.r_version }}.csv", row.names = FALSE) - # create also renv.lock file - setwd("/workspace/tmp") - - renv_lock <- list( - "R" = list( - "Version" = paste(R.version$major, R.version$minor, sep=".") - ), - "Repositories" = list( - list(Name = "CRAN", URL = Sys.getenv("R_REPOS")) - ), - "Packages" = list() - ) - - # Populate with information about each package - for (package in installed_packages$Package) { - dep_name <- package - dep_version <- installed_packages[installed_packages$Package == package, "Version"] - - version_parts <- strsplit(dep_version, "\\.")[[1]] - if (length(version_parts) == 4) { - print(sprintf("skipping installation of dep %s", dep_name)) - } else { - print(sprintf("append dependency %s - version %s", dep_name, dep_version)) - requirements <- tools::package_dependencies(dep_name, recursive = TRUE) - have_requirements <- length(requirements[[1]]) > 0 - if (have_requirements) { - renv_lock[["Packages"]][[dep_name]] <- list( - "Package" = dep_name, - "Version" = dep_version, - "Source" = "Repository", - "Repository" = "CRAN", - "Requirements" = requirements[[dep_name]] - ) - } else { - renv_lock[["Packages"]][[dep_name]] <- list( - "Package" = dep_name, - "Version" = dep_version, - "Source" = "Repository", - "Repository" = "CRAN" - ) - } - } - } - - # Write the list to a JSON file (renv.lock) - writeLines(jsonlite::toJSON(renv_lock, pretty = TRUE, auto_unbox = TRUE), "renv-${{ matrix.r_version }}.lock") - print("generated renv.lock content") - system("cat renv-${{ matrix.r_version }}.lock") - shell: Rscript {0} - - - name: Upload deps.csv and renv.lock artifacts - uses: actions/upload-artifact@v4 - if: | - (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || - matrix.r_version != 'devel' - with: - name: deps-${{ matrix.r_version }} - path: | - /workspace/tmp/ - - - name: Check Version - id: check_version - if: | - (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || - matrix.r_version != 'devel' - run: | - maintenance_version="F" - description_dat <- readLines("DESCRIPTION") - for (i in seq_along(description_dat)) { - if (grepl("^Version:", description_dat[i])) { - current_version <- sub("^Version: ", "", description_dat[i]) - version_parts <- strsplit(current_version, "\\.")[[1]] - # check if maintenance version - if (length(version_parts) == 4) { - print("Maintenance version detected (format X.Y.Z.M with M >= 9000)") - maintenance_version="T" - } - } - } - cat(sprintf("maintenance_version=%s", maintenance_version), file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE) - shell: Rscript {0} - - - name: Check - if: | - (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || - matrix.r_version != 'devel' - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - _R_CHECK_FORCE_SUGGESTS_: false - run: | - unlink("tmp",recursive=TRUE) - if ("${{ steps.check_version.outputs.maintenance_version }}" == "T"){ - Sys.setenv("_R_CHECK_CRAN_INCOMING_SKIP_LARGE_VERSION_" = TRUE) - } - if (!requireNamespace("rcmdcheck", quietly = TRUE)) install.packages("rcmdcheck") - options(crayon.enabled = TRUE) - check_error_on <- "error" - if (check_error_on == "") { - check_error_on <- "note" - } - rcmdcheck::rcmdcheck( - args = c("--no-manual", "--as-cran"), - error_on = check_error_on, - check_dir = "check" - ) - shell: Rscript {0} - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@v4 - with: - name: r${{ matrix.r_version }}-results - path: check - + name: Check + uses: ./.github/workflows/r-cmd-check.yml + if: github.event_name == 'pull_request' + with: + error-on: error diff --git a/.github/workflows/man-pages.yml b/.github/workflows/man-pages.yml new file mode 100644 index 00000000..332b13e6 --- /dev/null +++ b/.github/workflows/man-pages.yml @@ -0,0 +1,111 @@ +on: + workflow_dispatch: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: choice + options: + - devel + - latest + workflow_call: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: string + +name: Man Pages + +concurrency: + group: roxygen-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Roxygen + runs-on: ubuntu-latest + container: + image: "ghcr.io/pharmaverse/admiralci-${{ inputs.r-version }}:latest" + if: > + !contains(github.event.commits[0].message, '[skip lint]') + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + ##################### BEGIN boilerplate steps ##################### + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo (PR) šŸ›Ž + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: true + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies from DESCRIPTION + run: | + remotes::install_local(force = TRUE, dependencies = TRUE) + shell: Rscript {0} + env: + R_REMOTES_STANDALONE: "true" + + ##################### END boilerplate steps ##################### + + - name: Generate man pages + run: roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace')) + shell: Rscript {0} + + - name: Set-up safe dir + run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" + shell: bash + + - name: Roxygen check + if: "!startsWith(github.event.comment.body, '/roxygenize')" + run: | + git status -s + if [[ -n `git status -s | grep -E "man|DESCRIPTION"` ]] + then { + ROXYGEN_VERSION="$(Rscript -e 'packageVersion("roxygen2")' | awk '{print $NF}')" + echo "šŸ™ˆ Manuals are not up-to-date with roxygen comments!" + echo "šŸ”€ The following differences were noted:" + git diff man/* DESCRIPTION + echo -e "\nšŸ’» Please rerun the following command on your workstation and push your changes" + echo "--------------------------------------------------------------------" + echo "roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace'))" + echo "--------------------------------------------------------------------" + echo "ā„¹ roxygen2 version that was used in this workflow: $ROXYGEN_VERSION" + echo "šŸ™ Please ensure that the 'RoxygenNote' field in the DESCRIPTION file matches this version" + exit 1 + } else { + echo "šŸ’š Manuals are up-to-date with roxygen comments" + } + fi + shell: bash \ No newline at end of file diff --git a/.github/workflows/r-cmd-check.yml b/.github/workflows/r-cmd-check.yml new file mode 100644 index 00000000..7d91adab --- /dev/null +++ b/.github/workflows/r-cmd-check.yml @@ -0,0 +1,227 @@ +on: + workflow_dispatch: + workflow_call: + inputs: + error-on: + description: Input for the 'error_on' parameter in rcmdcheck::rcmdcheck() + required: false + default: note + type: string + +name: R CMD Check + +concurrency: + group: r-cmd-check-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + container: + image: "ghcr.io/pharmaverse/admiralci-${{ matrix.r_version }}:latest" + name: (${{ matrix.r_version }}) + if: > + !contains(github.event.commits[0].message, '[skip r-cmd-check]') + strategy: + fail-fast: false + matrix: + r_version: ["release", "devel", "oldrel"] + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: true + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + R_REPOS: "https://cran.r-project.org" + DEPS_IGNORE: >- + pharmaversesdtm, + pharmaverseadam, + admiral, + admiraldev, + admiralophtha, + admiralonco, + admiralvaccine, + staged.dependencies + + # DEPS_IGNORE: env variable to ignore package when building renv.lock (step Upload dependencies artifact) + # (improvments ideas : get this list of deps to ignore from staged.dependencies yml file) + + steps: + ##################### BEGIN boilerplate steps ##################### + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo (PR) šŸ›Ž + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: | + github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + with: + git-ref: ${{ steps.branch-name.outputs.current_branch }} + run-system-dependencies: true + renv-restore: false + enable-check: false + cran-repos: "https://cloud.r-project.org" + direction: upstream + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies from DESCRIPTION + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + run: | + remotes::install_local(force = TRUE, dependencies = TRUE) + shell: Rscript {0} + + ##################### END boilerplate steps ##################### + + - name: Upload dependencies artifact + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + run: | + dir.create("/workspace/tmp") + library(dplyr) + installed_packages <- as.data.frame(installed.packages()) + packages_to_remove <- Sys.getenv("DEPS_IGNORE", "") + packages_to_remove <- unlist(strsplit(packages_to_remove, ",")) + installed_packages <- installed_packages %>% filter(LibPath != "/usr/local/lib/R/library") %>% # remove pre-built deps + filter(!Package %in% packages_to_remove) + # save deps as csv file + write.csv(installed_packages, "/workspace/tmp/deps-${{ matrix.r_version }}.csv", row.names = FALSE) + # create also renv.lock file + setwd("/workspace/tmp") + + renv_lock <- list( + "R" = list( + "Version" = paste(R.version$major, R.version$minor, sep=".") + ), + "Repositories" = list( + list(Name = "CRAN", URL = Sys.getenv("R_REPOS")) + ), + "Packages" = list() + ) + + # Populate with information about each package + for (package in installed_packages$Package) { + dep_name <- package + dep_version <- installed_packages[installed_packages$Package == package, "Version"] + + version_parts <- strsplit(dep_version, "\\.")[[1]] + if (length(version_parts) == 4) { + print(sprintf("skipping installation of dep %s", dep_name)) + } else { + print(sprintf("append dependency %s - version %s", dep_name, dep_version)) + requirements <- tools::package_dependencies(dep_name, recursive = TRUE) + have_requirements <- length(requirements[[1]]) > 0 + if (have_requirements) { + renv_lock[["Packages"]][[dep_name]] <- list( + "Package" = dep_name, + "Version" = dep_version, + "Source" = "Repository", + "Repository" = "CRAN", + "Requirements" = requirements[[dep_name]] + ) + } else { + renv_lock[["Packages"]][[dep_name]] <- list( + "Package" = dep_name, + "Version" = dep_version, + "Source" = "Repository", + "Repository" = "CRAN" + ) + } + } + } + + # Write the list to a JSON file (renv.lock) + writeLines(jsonlite::toJSON(renv_lock, pretty = TRUE, auto_unbox = TRUE), "renv-${{ matrix.r_version }}.lock") + print("generated renv.lock content") + system("cat renv-${{ matrix.r_version }}.lock") + shell: Rscript {0} + + - name: Upload deps.csv and renv.lock artifacts + uses: actions/upload-artifact@v4 + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + with: + name: deps-${{ matrix.r_version }} + path: | + /workspace/tmp/ + + - name: Check Version + id: check_version + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + run: | + maintenance_version="F" + description_dat <- readLines("DESCRIPTION") + for (i in seq_along(description_dat)) { + if (grepl("^Version:", description_dat[i])) { + current_version <- sub("^Version: ", "", description_dat[i]) + version_parts <- strsplit(current_version, "\\.")[[1]] + # check if maintenance version + if (length(version_parts) == 4) { + print("Maintenance version detected (format X.Y.Z.M with M >= 9000)") + maintenance_version="T" + } + } + } + cat(sprintf("maintenance_version=%s", maintenance_version), file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE) + shell: Rscript {0} + + - name: Check + if: | + (github.event_name == 'workflow_dispatch' && matrix.r_version == 'devel') || + matrix.r_version != 'devel' + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + _R_CHECK_FORCE_SUGGESTS_: false + run: | + unlink("tmp",recursive=TRUE) + if ("${{steps.check_version.outputs.maintenance_version}}" == "T"){ + Sys.setenv("_R_CHECK_CRAN_INCOMING_SKIP_LARGE_VERSION_" = TRUE) + } + if (!requireNamespace("rcmdcheck", quietly = TRUE)) install.packages("rcmdcheck") + options(crayon.enabled = TRUE) + check_error_on <- "${{ inputs.error-on }}" + if (check_error_on == "") { + check_error_on <- "note" + } + rcmdcheck::rcmdcheck( + args = c("--no-manual", "--as-cran"), + error_on = check_error_on, + check_dir = "check" + ) + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: r${{ matrix.r_version }}-results + path: check \ No newline at end of file diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml new file mode 100644 index 00000000..d3f0b200 --- /dev/null +++ b/.github/workflows/spellcheck.yml @@ -0,0 +1,88 @@ +name: Spelling + +on: + workflow_dispatch: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: choice + options: + - devel + - latest + exclude: + description: "List of paths to exclude (comma seperated list)" + default: "" + required: false + type: string + workflow_call: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: string + exclude: + description: "List of paths to exclude (comma seperated list)" + default: "" + required: false + type: string + +concurrency: + group: spelling-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + spellcheck: + name: Spellcheck + runs-on: ubuntu-latest + container: + image: "ghcr.io/pharmaverse/admiralci-${{ inputs.r-version }}:latest" + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + if: > + !contains(github.event.commits[0].message, '[skip spellcheck]') + steps: + ##################### BEGIN boilerplate steps ##################### + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo (PR) šŸ›Ž + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: true + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + ##################### END boilerplate steps ##################### + + - name: Run Spellcheck + uses: insightsengineering/r-spellcheck-action@v3 + with: + additional_options: "" + exclude: "${{ inputs.exclude }}" \ No newline at end of file From ec4dec7ced1b06df23999264a46a7d953060aeb4 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Thu, 9 Jan 2025 09:16:28 +0100 Subject: [PATCH 11/14] chore: migrated tests to separate file --- .github/workflows/main.yml | 27 ++++--------- .github/workflows/test.yml | 79 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 468da33f..e99598ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,6 +32,7 @@ jobs: id: get_r_version run: echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT shell: bash + spellcheck: name: Spelling uses: ./.github/workflows/spellcheck.yml @@ -39,6 +40,7 @@ jobs: needs: get_r_version with: r-version: "${{ needs.get_r_version.outputs.r-version }}" + linter: name: Lint uses: ./.github/workflows/lintr.yml @@ -46,6 +48,7 @@ jobs: if: github.event_name == 'pull_request' with: r-version: "${{ needs.get_r_version.outputs.r-version }}" + man-pages: name: Man Pages uses: ./.github/workflows/man-pages.yml @@ -56,28 +59,12 @@ jobs: tests: name: Tests - runs-on: ubuntu-latest + uses: ./.github/workflows/test.yml needs: get_r_version - container: - image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest" - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Install system dependencies - run: | - apt-get install -y --no-install-recommends \ - libudunits2-dev - - - name: Install dependencies - run: | - Rscript -e 'remotes::install_deps(dependencies = TRUE)' + if: github.event_name == 'pull_request' + with: + r-version: "${{ needs.get_r_version.outputs.r-version }}" - - name: Run tests - shell: Rscript {0} - run: | - devtools::load_all(".") - devtools::test() check: name: Check uses: ./.github/workflows/r-cmd-check.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..32a7e84e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,79 @@ +name: Spelling + +on: + workflow_dispatch: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: choice + options: + - devel + - latest + workflow_call: + inputs: + r-version: + description: "The version of R to use" + default: "release" + required: false + type: string + +concurrency: + group: tests-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + container: + image: "ghcr.io/pharmaverse/admiralci-${{ inputs.r-version }}:latest" + steps: + - name: Get branch names + id: branch-name + uses: tj-actions/branch-names@v8 + + - name: Checkout repo (PR) šŸ›Ž + uses: actions/checkout@v4.2.2 + 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: Checkout repository + uses: actions/checkout@v4.2.2 + if: github.event_name != 'pull_request' + with: + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + ~/.staged.dependencies + key: staged-deps + + - name: Run Staged dependencies + uses: insightsengineering/staged-dependencies-action@v1 + with: + run-system-dependencies: true + renv-restore: false + enable-check: false + direction: upstream + git-ref: ${{ steps.branch-name.outputs.current_branch }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies from DESCRIPTION + run: | + remotes::install_local(force = TRUE, dependencies = TRUE) + shell: Rscript {0} + env: + R_REMOTES_STANDALONE: "true" + + - name: Run tests + shell: Rscript {0} + run: | + devtools::load_all(".") + devtools::test() \ No newline at end of file From 366d86a76fb2e94500918eac9c25f2e5a2b698f1 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Thu, 9 Jan 2025 09:40:36 +0100 Subject: [PATCH 12/14] chore: added docs --- .github/workflows/lintr.yml | 8 ++++++-- .github/workflows/main.yml | 7 +++++++ .github/workflows/man-pages.yml | 8 ++++++-- .github/workflows/r-cmd-check.yml | 8 ++++++-- .github/workflows/spellcheck.yml | 4 ++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lintr.yml b/.github/workflows/lintr.yml index 2f855d93..dd920c5b 100644 --- a/.github/workflows/lintr.yml +++ b/.github/workflows/lintr.yml @@ -1,3 +1,9 @@ +# Source: +# https://github.com/pharmaverse/admiralci/blob/main/.github/workflows/lintr.yml +# Modified to install system dependencies. + +name: Lint + on: workflow_dispatch: inputs: @@ -47,8 +53,6 @@ on: required: false type: string -name: Lint - concurrency: group: lint-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e99598ac..bdd3d051 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,13 @@ # the developement process. When package is ready to # be published, revisit and add release-related # workflows. +# Due to the need of some customization, instead of +# referencing the workflows directly, they are copied +# over and modified to install needed system dependencies. +# This means that in case of an update, the changes +# will need to be applied manually. +# +# Last workflow update: 2025-09-01 name: admiral CI/CD Workflows on: diff --git a/.github/workflows/man-pages.yml b/.github/workflows/man-pages.yml index 332b13e6..4ad1204e 100644 --- a/.github/workflows/man-pages.yml +++ b/.github/workflows/man-pages.yml @@ -1,3 +1,9 @@ +# Source: +# https://github.com/pharmaverse/admiralci/blob/main/.github/workflows/man-pages.yml +# Modified to install system dependencies. + +name: Man Pages + on: workflow_dispatch: inputs: @@ -17,8 +23,6 @@ on: required: false type: string -name: Man Pages - concurrency: group: roxygen-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true diff --git a/.github/workflows/r-cmd-check.yml b/.github/workflows/r-cmd-check.yml index 7d91adab..4d168d91 100644 --- a/.github/workflows/r-cmd-check.yml +++ b/.github/workflows/r-cmd-check.yml @@ -1,3 +1,9 @@ +# Source: +# https://github.com/pharmaverse/admiralci/blob/main/.github/workflows/r-cmd-check.yml +# Modified to install system dependencies. + +name: R CMD Check + on: workflow_dispatch: workflow_call: @@ -8,8 +14,6 @@ on: default: note type: string -name: R CMD Check - concurrency: group: r-cmd-check-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml index d3f0b200..49204447 100644 --- a/.github/workflows/spellcheck.yml +++ b/.github/workflows/spellcheck.yml @@ -1,3 +1,7 @@ +# Source: +# https://github.com/pharmaverse/admiralci/blob/main/.github/workflows/spellcheck.yml +# Modified to install system dependencies. + name: Spelling on: From 4a38b1cf019c35641f0c57874ceee2975923487c Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Thu, 9 Jan 2025 09:42:33 +0100 Subject: [PATCH 13/14] chore: remove units from DESCRIPTION --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ddc33acf..2466aac4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,7 +55,6 @@ Imports: tidyr, tools, utils, - units, zip Encoding: UTF-8 Roxygen: list(markdown = TRUE) From b4861a8185975393d69dad773d193d3680605305 Mon Sep 17 00:00:00 2001 From: m-kolomanski Date: Thu, 9 Jan 2025 09:48:20 +0100 Subject: [PATCH 14/14] chore: added docs for test --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 32a7e84e..e579e41b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,6 @@ -name: Spelling +# Custom workflow created based on jobs available in `admiralci` package. + +name: Tests on: workflow_dispatch: