Update r-tests.yml #5
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 <- sum(sapply(results, function(res) length(res) > 0)); | |
write(errors, file = "lint_errors.txt"); | |
saveRDS(results, file = "lint_results.rds"); | |
' | |
- name: Print linting errors | |
run: | | |
R -e ' | |
results <- readRDS("lint_results.rds"); | |
for (file_results in results) { | |
if (length(file_results) > 0) { | |
print(file_results); | |
} | |
} | |
' | |
- name: Check for linting errors | |
run: | | |
errors=$(cat lint_errors.txt) | |
if [ "$errors" -ne 0 ]; then | |
echo "Linting errors found" | |
exit 1 | |
else | |
echo "No linting errors" | |
fi |