--- name: Style 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: style-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: style: name: Code Style runs-on: ubuntu-latest if: > !contains(github.event.commits[0].message, '[skip style]') env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: pharmaverse/admiralci/.github/actions/setup_R@main with: extra-packages: any::styler - name: Get changed files id: changed-files uses: Ana06/get-changed-files@v2.3.0 with: format: csv filter: | * !renv/*.R - name: Run styler run: | # Run styler changed_files <- unlist(strsplit( "${{ steps.changed-files.outputs.all }}", split="," )) is_r_file <- function(x) { ext <- tools::file_ext(x) ext %in% c("R", "Rmd", "Rnw", "Rmarkdown", "qmd") } changed_r_files <- Filter(is_r_file, changed_files) changed_r_files <- Filter(file.exists, changed_r_files) detect <- styler::style_file(changed_r_files) if (TRUE %in% detect$changed) { problems <- subset(detect$file, detect$changed == TRUE) cat(paste( "☠ One or more files had styling errors.", "Please see the log above for remediations,", "or simply run the following commands", "for an immediate fix:\n" )) cat("────────────────────────────────────────\n") cat(paste0( "styler::style_file(", capture.output(dput(problems)), ")\n" )) cat("────────────────────────────────────────\n") cat("⚠️ Here is the complete git diff for the files that changed:\n") system(paste0("git diff ", paste(unlist(problems), collapse=' '))) cat("────────────────────────────────────────\n") cat(paste("ℹ️ Version of styler used in this workflow:", packageVersion("styler"))) quit(status = length(problems)) } shell: Rscript {0}