Skip to content

Commit

Permalink
Attempt to get GHA going
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Dec 5, 2023
1 parent 8ae6da6 commit caa26d6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .dev/lint_metadata_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This script is designed to find linters that lack metadata tests.
# To do so, it forces xml_nodes_to_lints() to give the wrong information,
# runs the test suite, and finds linters that nevertheless pass all their tests.
library(testthat)

xml_nodes_to_lints_file <- "R/xml_nodes_to_lints.R"

xml_nodes_to_lints_file |>
readLines() |>
sub(
pattern = "line_number = as.integer(line1)",
replacement = "line_number = as.integer(2^31 - 1)"
) |>
writeLines(xml_nodes_to_lints_file)

pkgload::load_all()

report <- test_dir(
"tests/testthat",
filter = "linter$",
stop_on_failure = FALSE,
reporter = SilentReporter$new()
)
names(report) <- vapply(report, `[[`, "file", FUN.VALUE = character(1L))

# Hack the nested structure of the testthat report to identify which files have
# any failed test
failed <- report |>
vapply(
\(x) any(vapply(x$results, inherits, "expectation_failure", FUN.VALUE = logical(1L))),
logical(1L)
) |>
which() |>
names() |>
unique() |>
gsub(pattern = "^test-|\\.R$", replacement = "")

passed <- setdiff(
available_linters(tags = NULL)$linter,
failed
)

if (length(passed) > 0L) {
stop("Please add tests of lint metadata for the following linters: ", toString(passed))
}
29 changes: 29 additions & 0 deletions .github/workflows/ensure-metadata-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Ensure lint metadata is tested
on:
push:
branches: [main]
pull_request:
branches: [main]

name: ensure-metadata-tests

jobs:
ensure-metadata-tests:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
r-version: "release"
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
- name: Ensure lint metadata is tested
run: |
options(crayon.enabled = TRUE)
callr::rscript(".dev/lint_metadata_test.R")
shell: Rscript {0}

0 comments on commit caa26d6

Please sign in to comment.