Skip to content

Commit

Permalink
separate 'get_available_packages' fn to work on gh runners with no mi…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
mpadge committed Aug 27, 2024
1 parent b4219af commit 559455f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pkgcheck
Title: rOpenSci Package Checks
Version: 0.1.2.057
Version: 0.1.2.058
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
11 changes: 1 addition & 10 deletions R/check-on-cran.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ pkgchk_on_cran <- function (checks) {
)
pkg <- desc$Package

op <- options ()
if (is.null (getOption ("repos"))) {
# Needed for GitHub runners, because avail.pkgs fails with no mirror set
options (repos = c (CRAN = "https://cloud.r-project.org"))
}
ap <- tryCatch (
data.frame (utils::available.packages (), stringsAsFactors = FALSE),
error = function (e) NULL
)
options (op)
ap <- get_available_packages ()
res <- pkg %in% ap$Package

if (res) {
Expand Down
16 changes: 7 additions & 9 deletions R/check-pkgname-available.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

#' Check that package name is available and/or already on CRAN.
#'
#' @param checks A 'pkgcheck' object with full \pkg{pkgstats} summary and
#' \pkg{goodpractice} results.
#' @noRd
pkgchk_pkgname_available <- function (checks) {

desc <- data.frame (read.dcf (fs::path (
checks$pkg$path,
"DESCRIPTION"
)),
stringsAsFactors = FALSE
desc <- data.frame (
read.dcf (fs::path (
checks$pkg$path,
"DESCRIPTION"
)),
stringsAsFactors = FALSE
)
pkg <- desc$Package

Expand All @@ -20,9 +20,7 @@ pkgchk_pkgname_available <- function (checks) {
value = TRUE
)

ap <- data.frame (utils::available.packages (),
stringsAsFactors = FALSE
)
ap <- get_available_packages ()

return (
!pkg %in% ap$Package &
Expand Down
22 changes: 21 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Tick symbol for markdown output
#' @noRd
symbol_tck <- function () {
Expand Down Expand Up @@ -105,3 +104,24 @@ env2namespace <- function (e) {

return (e)
}

#' Try to get available.packages()
#'
#' That function fails when no CRAN mirror is set, which is generally the case
#' on GitHub runners, even if set as "repos" option. In those cases, this
#' returns `NULL`.
#' @noRd
get_available_packages <- function () {
op <- options ()
if (is.null (getOption ("repos"))) {
# Needed for GitHub runners, because avail.pkgs fails with no mirror set
options (repos = c (CRAN = "https://cloud.r-project.org"))
}
ap <- tryCatch (
data.frame (utils::available.packages (), stringsAsFactors = FALSE),
error = function (e) NULL
)
options (op)

return (ap)
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/pkgcheck",
"issueTracker": "https://github.com/ropensci-review-tools/pkgcheck/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.2.057",
"version": "0.1.2.058",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 559455f

Please sign in to comment.