Update r-tests.yml #6
Workflow file for this run
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
name: Lint R Scripts and Notebooks | |
on: [push, pull_request] | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
folder: [PM1, PM2] | |
name: Lint ${{ matrix.folder }} folder | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up R | |
uses: r-lib/actions/setup-r@v2 | |
- name: Install lintr | |
run: R -e 'install.packages("lintr")' | |
- name: Lint R scripts and notebooks in ${{ matrix.folder }} | |
id: lint | |
run: | | |
R -e ' | |
files <- list.files("${{ matrix.folder }}", pattern = "\\.(R|r|Rmd|rmd|irnb)$", full.names = TRUE); | |
linters <- lintr::with_defaults(line_length_linter = lintr::line_length_linter(119)); | |
results <- lapply(files, lintr::lint, linters = linters); | |
errors_and_warnings <- lapply(results, function(res) { | |
errs_warns <- sapply(res, function(x) grepl("Error:", x$message) || grepl("Warning:", x$message)) | |
res[errs_warns] | |
}) | |
saveRDS(errors_and_warnings, file = "lint_errors_warnings.rds"); | |
saveRDS(results, file = "lint_results.rds"); | |
total_errors <- sum(sapply(errors_and_warnings, length)) | |
write(total_errors, file = "total_lint_errors.txt"); | |
' | |
- name: Print all linting results | |
run: | | |
R -e ' | |
results <- readRDS("lint_results.rds"); | |
for (file_results in results) { | |
for (result in file_results) { | |
print(result) | |
} | |
} | |
' | |
- name: Print linting errors and warnings | |
run: | | |
R -e ' | |
errors_and_warnings <- readRDS("lint_errors_warnings.rds"); | |
for (file_errors_warnings in errors_and_warnings) { | |
for (error_warning in file_errors_warnings) { | |
print(error_warning) | |
} | |
} | |
' | |
- name: Check for linting errors and warnings | |
run: | | |
total_errors=$(cat total_lint_errors.txt) | |
if [ "$total_errors" -ne 0 ]; then | |
echo "Linting errors or warnings found" | |
exit 1 | |
else | |
echo "No linting errors or warnings" | |
fi |