diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index 16590d24..a5271d0b 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -21,6 +21,11 @@ on: required: false type: boolean default: true + lint-all-files: + description: Lint all files every time + default: false + required: false + type: boolean concurrency: group: lint-${{ github.event.pull_request.number || github.ref }} @@ -75,6 +80,42 @@ jobs: VALIDATE_DOCKERFILE: true VALIDATE_MARKDOWN: true MARKDOWN_CONFIG_FILE: .markdownlint.yaml - VALIDATE_R: true VALIDATE_YAML: true - LINTR_ERROR_ON_LINT: ${{ inputs.lintr_error_on_lint }} + + lint-r-code: + name: Lint R code ๐Ÿงถ + runs-on: ubuntu-latest + if: > + !contains(github.event.commits[0].message, '[skip linter]') + && github.event.pull_request.draft == false + container: + image: ghcr.io/insightsengineering/rstudio_4.3.1_bioc_3.17:latest + steps: + - name: Checkout repo ๐Ÿ›Ž + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - 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 <- as.list(setdiff(all_files, changed_files)) + } + lints <- lintr::lint_package(exclusions = exclusions_list) + if (length(lints) > 0L) { + print(lints) + if (identical("${{ inputs.lintr_error_on_lint }}", "true")) { + stop("Lints detected. Please review and adjust code according to the comments provided.", call. = FALSE) + } + } + shell: Rscript {0}