Repository navigation
Point to Stanford's Stats 311/EE 377 on the home page #293
This file contains hidden or 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
| # 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 files changed in a PR (diffed against the base via the GitHub | |
| # API), giving fast feedback that flags newly-introduced lint issues without | |
| # failing on pre-existing ones elsewhere in the repo. Complements | |
| # lint-project.yaml, which lints the whole project on push and PR. | |
| on: | |
| pull_request: | |
| name: lint-changed-files.yaml | |
| permissions: read-all | |
| # Cancel a superseded run when a newer commit is pushed to the same PR. | |
| concurrency: | |
| group: lint-changed-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint-changed-files: | |
| # Pinned to match the noble binary repo used below (issue #199). | |
| runs-on: ubuntu-24.04 | |
| env: | |
| GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| # `ids` is a self-referential symlink (`ids -> .`, see CLAUDE.md). Left | |
| # in place, `all_files` below would also list every real file a second | |
| # time under `ids/...`, and lintr's exclusions field always resolves | |
| # through normalize_path() (see .lintr.R), which follows symlinks: a | |
| # `ids/<changed-file>` entry in `all_files` normalizes onto the exact | |
| # same path as the real changed file, so `setdiff(all_files, | |
| # changed_files)` -- which only strips the real path, never its | |
| # ids-prefixed alias -- ends up excluding the real changed file too. | |
| # Removing the symlink up front avoids both problems. | |
| - name: Remove self-referential ids symlink before linting | |
| run: rm -f ids | |
| - uses: r-lib/actions/setup-r@f9a764fea8d5c63df6ef9a5c7795bf7deb5d7e05 # v2.14.0 | |
| with: | |
| use-public-rspm: true | |
| - name: Install lintr and dependencies | |
| run: install.packages(c("lintr", "gh", "purrr", "withr"), repos = "https://packagemanager.posit.co/cran/__linux__/noble/latest") | |
| shell: Rscript {0} | |
| # No need to set options(lintr.linter_file): lintr auto-detects `.lintr.R` | |
| # (find_config() resolves it with no option set), same as | |
| # lint-project.yaml's bare lint_dir(). | |
| - name: Lint files changed by this PR | |
| run: | | |
| files <- gh::gh( | |
| "GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files", | |
| .limit = Inf | |
| ) | |
| changed_files <- purrr::map_chr(files, "filename") | |
| # all.files = TRUE so changed dotfiles (e.g. .lintr.R) appear here and | |
| # get excluded too, rather than being linted on every PR. | |
| all_files <- list.files(recursive = TRUE, all.files = TRUE) | |
| # lint_dir() lints everything except the exclusions, so exclude every | |
| # file that this PR did NOT change. | |
| exclusions_list <- as.list(setdiff(all_files, changed_files)) | |
| lintr::lint_dir(exclusions = exclusions_list) | |
| shell: Rscript {0} | |
| env: | |
| LINTR_ERROR_ON_LINT: true |