all updated and refreshed into final report-tlf-pilot3.pdf #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
workflow_call: | |
inputs: | |
r-version: | |
description: 'The version of R to use' | |
default: '4.2' | |
required: false | |
type: string | |
lint-all-files: | |
description: 'Lint all files every time' | |
default: 'false' | |
required: false | |
type: string | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
name: Check Lint | |
concurrency: | |
group: lint-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
get_r_version: | |
name: Get R version | |
runs-on: ubuntu-latest | |
if: > | |
!contains(github.event.commits[0].message, '[skip lint]') | |
outputs: | |
r-version: ${{ steps.normalizer.outputs.R_VERSION }} | |
steps: | |
- name: Normalize inputs | |
id: normalizer | |
run: | | |
R_VERSION="${{ inputs.r-version }}" | |
if [ "$R_VERSION" == "" ] | |
then { | |
R_VERSION="4.2" | |
} | |
fi | |
echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT | |
shell: bash | |
lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
container: | |
image: "ghcr.io/pharmaverse/admiralci-${{needs.get_r_version.outputs.r-version}}:latest" | |
if: > | |
!contains(github.event.commits[0].message, '[skip lint]') | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
needs: get_r_version | |
steps: | |
##################### BEGIN boilerplate 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: Checkout repository | |
uses: actions/checkout@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
ref: ${{ steps.branch-name.outputs.head_ref_branch }} | |
- name: Normalize inputs | |
id: normalizer | |
run: | | |
R_VERSION="${{ inputs.r-version }}" | |
if [ "$R_VERSION" == "" ] | |
then { | |
R_VERSION="4.2" | |
} | |
fi | |
echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Restore cache | |
uses: actions/cache@v3 | |
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 | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
##################### END boilerplate steps ##################### | |
- name: Changed files | |
id: files | |
uses: Ana06/get-changed-files@v2.2.0 | |
with: | |
format: 'json' | |
filter: '*' | |
- name: Lint | |
run: | | |
install.packages("lintr") | |
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_dir(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} |