Skip to content

Add lint-changed-lines workflow (incremental linting) — supersedes #559 #5

Add lint-changed-lines workflow (incremental linting) — supersedes #559

Add lint-changed-lines workflow (incremental linting) — supersedes #559 #5

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
#
# Lints only the lines a pull request adds or modifies, rather than whole
# changed files. New and edited code must satisfy the linters, while
# untouched legacy code in the same file is not flagged -- so lint rules
# can be adopted or tightened incrementally as files are touched.
on:
pull_request:
name: lint-changed-lines.yaml
permissions: read-all
jobs:
lint-changed-lines:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
steps:
- uses: actions/checkout@v4
with:
# Check out the PR head, not the default refs/pull/N/merge ref. The
# "changed lines" in lint-changed-lines.R come from the PR "files"
# patch, whose line numbers are relative to the PR head; the merge
# ref's line numbers can drift from those if the base branch has
# advanced in the same file region, which would silently drop real
# lints on changed lines.
ref: ${{ github.event.pull_request.head.sha }}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@HEAD
with:
extra-packages: |
any::gh
r-lib/lintr
needs: lint
- name: Add lintr options
run: |
cat('\noptions(lintr.linter_file = ".lintr")\n', file = "~/.Rprofile", append = TRUE)
shell: Rscript {0}
- name: Install package
run: R CMD INSTALL .
- name: Lint lines changed by this PR
run: Rscript .github/scripts/lint-changed-lines.R
env:
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}