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

Chore: customize github workflows to correctly install system dependencies #151

Merged
merged 14 commits into from
Jan 16, 2025
Merged
149 changes: 149 additions & 0 deletions .github/workflows/lintr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Source:
# https://github.com/pharmaverse/admiralci/blob/main/.github/workflows/lintr.yml
# Modified to install system dependencies.

name: Lint

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

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/[email protected]
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/[email protected]
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/[email protected]
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}
40 changes: 20 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -32,49 +39,42 @@ 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
uses: ./.github/workflows/spellcheck.yml
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
uses: ./.github/workflows/lintr.yml
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'
uses: ./.github/workflows/man-pages.yml
needs: get_r_version
if: github.event_name == 'pull_request'
with:
r-version: "${{ needs.get_r_version.outputs.r-version }}"

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 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: pharmaverse/admiralci/.github/workflows/r-cmd-check.yml@main
uses: ./.github/workflows/r-cmd-check.yml
if: github.event_name == 'pull_request'
with:
error-on: error
115 changes: 115 additions & 0 deletions .github/workflows/man-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 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:
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: 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/[email protected]
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/[email protected]
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
Loading
Loading