Skip to content

Commit

Permalink
GHA: skip tests that need GH token in PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Jan 9, 2025
1 parent fa7655c commit 6fc3b1f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/testthat/test-install-github.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ test_that("github_resolve_ref.github_release", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_error(
github_resolve_ref.github_release(
Expand Down Expand Up @@ -38,6 +43,11 @@ test_that("github_resolve_ref.github_release", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_error(
github_resolve_ref(
Expand All @@ -54,6 +64,11 @@ test_that("github_release", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand All @@ -79,6 +94,11 @@ test_that("install_github", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand Down Expand Up @@ -110,6 +130,11 @@ test_that("error if not username, warning if given as argument", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand Down Expand Up @@ -153,6 +178,11 @@ test_that("remote_sha.github_remote", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_equal(
remote_sha.github_remote(
Expand All @@ -176,6 +206,11 @@ test_that("github_remote with deleted branch", {
# skip this test unless we are using curl
skip_if(is_standalone() || !pkg_installed("curl"))

# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_equal(
remote_sha.github_remote(
Expand All @@ -198,6 +233,11 @@ test_that("github_pull", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand All @@ -222,6 +262,11 @@ test_that("remote_sha.github_remote errors if remote doesn't exist", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_error(remote_sha(github_remote("arst/arst")))
})
Expand All @@ -230,6 +275,11 @@ test_that("remote_sha.github_remote returns expected value if remote does exist"
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_equal(remote_sha(github_remote("r-lib/[email protected]")), "ad9aac7b9a522354e1ff363a86f389e32cec181b")
})

0 comments on commit 6fc3b1f

Please sign in to comment.