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: "Should the package be installed?" required: true default: false type: boolean 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: "Should the package be installed?" required: false default: false type: boolean name: Lint concurrency: group: lint-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: lint: name: Lint runs-on: ubuntu-latest if: > !contains(github.event.commits[0].message, '[skip lint]') env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: pharmaverse/admiralci/.github/actions/setup_R@main with: extra-packages: any::lintr, any::cyclocomp install-package: ${{ inputs.install-package }} - name: Changed files id: files uses: Ana06/get-changed-files@v2.2.0 with: format: "json" filter: "*" - name: Lint run: | # Lint Changed Files 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: | # Error if lints are Detected # attach lintr to ensure the lints are formatted nicely library(lintr) options(warn = 1) 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}