Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Apr 9, 2024
1 parent c733977 commit 8a4e176
Show file tree
Hide file tree
Showing 14 changed files with 3,172 additions and 12 deletions.
16 changes: 11 additions & 5 deletions R/platforms.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

get_platforms <- function() {
url_platforms <- "https://raw.githubusercontent.com/r-hub/actions/v1/setup/platforms.json"
url_containers <- "https://r-hub.github.io/containers/manifest.json"
url_platforms <- Sys.getenv(
"RHUB_PLATFORMS_URL",
"https://raw.githubusercontent.com/r-hub/actions/v1/setup/platforms.json"
)
url_containers <- Sys.getenv(
"RHUB_CONTAINERS_URL",
"https://r-hub.github.io/containers/manifest.json",
)
ret <- synchronise(when_all(
async_cached_http_get(url_platforms),
async_cached_http_get(url_containers)
Expand Down Expand Up @@ -89,7 +95,7 @@ format.rhub_platforms <- function(x, ...) {
if (x$r_version[p] == "*") {
grey(paste0(" All R versions on GitHub Actions ", x$github_os[p]))
} else {
x$r_version
grey(paste0(" ", x$r_version[p]))
}
)
counter <- counter + 1L
Expand Down Expand Up @@ -157,7 +163,7 @@ format.rhub_platforms_summary <- function(x, ...) {
icon <- if (!has_emoji()) {
ifelse(x$type == "os", "[VM]", "[CT]")
} else {
ifelse(x$type == "os", "\U1F5A5", "\U1F40B")
ifelse(x$type == "os", "\U1F5A5", "\U1F40B") # nocov
}
name <- cli::style_bold(cli::col_blue(x$name))
rv <- abbrev_version(x$r_version)
Expand Down Expand Up @@ -246,7 +252,7 @@ select_platforms <- function(platforms = NULL) {

} else {
platforms <- unique(platforms)
bad <- !platforms %in% unlist(plat$name, plat$aliaeses)
bad <- !platforms %in% unlist(plat$name, plat$aliases)
if (any(bad)) {
throw(pkg_error(
"Unknown platform{?s}: {.val {platforms[bad]}}.",
Expand Down
5 changes: 4 additions & 1 deletion R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ rhub_setup <- function(overwrite = FALSE) {
git_root <- setup_find_git_root()
check_rpkg_root(rpkg_root, git_root)

url <- "https://raw.githubusercontent.com/r-hub/actions/v1/workflows/rhub.yaml"
url <- Sys.getenv(
"RHUB_WORKFLOW_URL",
"https://raw.githubusercontent.com/r-hub/actions/v1/workflows/rhub.yaml"
)
resp <- synchronise(http_get(url))
if (resp$status_code != 200) {
throw(pkg_error(
Expand Down
318 changes: 318 additions & 0 deletions tests/testthat/_snaps/platforms.md

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions tests/testthat/_snaps/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# check_rpkg_root

Code
check_rpkg_root("/pkg/root", "/git/root")
Condition
Error:
! R-hub currently requires that your R package is at the root of the git repository.
i Your R package is at '/pkg/root'.
i Your git repository root is at '/git/root'.

# rhub_setup

Code
rhub_setup()
Message
Setting up R-hub v2.
> Is the current directory part of an R package?
v Found R package at '<wd>'.
> Is the current directory part of a git repository?
v Found git repository at '<wd>'.
Condition
Error:
! Failed to download R-hub worflow file from GitHub.
i URL: <http://127.0.0.1:<port>/badbadbad>.
i HTTP status: 404.
i Make sure that you are online and GitHub is up.

---

Code
rhub_setup()
Message
Setting up R-hub v2.
> Is the current directory part of an R package?
v Found R package at '<wd>'.
> Is the current directory part of a git repository?
v Found git repository at '<wd>'.
v Created workflow file '<wd>/.github/workflows/rhub.yaml'.
Notes:
* The workflow file must be added to the default branch of the GitHub repository.
* GitHub actions must be enabled for the repository. They are disabled for forked repositories by default.
Next steps:
* Add the workflow file to git using `git add <filename>`.
* Commit it to git using `git commit`.
* Push the commit to GitHub using `git push`.
* Call `rhub::rhub_doctor()` to check that you have set up R-hub correctly.
* Call `rhub::rhub_check()` to check your package.

---

Code
rhub_setup()
Message
Setting up R-hub v2.
> Is the current directory part of an R package?
v Found R package at '<wd>'.
> Is the current directory part of a git repository?
v Found git repository at '<wd>'.
v Workflow file '<wd>/.github/workflows/rhub.yaml' already exists and it is current.
Notes:
* The workflow file must be added to the default branch of the GitHub repository.
* GitHub actions must be enabled for the repository. They are disabled for forked repositories by default.
Next steps:
* Add the workflow file to git using `git add <filename>`.
* Commit it to git using `git commit` (if not committed already).
* Push the commit to GitHub using `git push` (if not pushed already).
* Call `rhub::rhub_doctor()` to check that you have set up R-hub correctly.
* Call `rhub::rhub_check()` to check your package.

---

Code
rhub_setup()
Message
Setting up R-hub v2.
> Is the current directory part of an R package?
v Found R package at '<wd>'.
> Is the current directory part of a git repository?
v Found git repository at '<wd>'.
Condition
Error:
! Workflow file already exists at '<wd>/.github/workflows/rhub.yaml'.
i Use `overwrite = TRUE` for overwriting it.

---

Code
rhub_setup(overwrite = TRUE)
Message
Setting up R-hub v2.
> Is the current directory part of an R package?
v Found R package at '<wd>'.
> Is the current directory part of a git repository?
v Found git repository at '<wd>'.
i Updated existing workflow file at '<wd>/.github/workflows/rhub.yaml', as requested
Notes:
* The workflow file must be added to the default branch of the GitHub repository.
* GitHub actions must be enabled for the repository. They are disabled for forked repositories by default.
Next steps:
* Add the workflow file to git using `git add <filename>`.
* Commit it to git using `git commit`.
* Push the commit to GitHub using `git push`.
* Call `rhub::rhub_doctor()` to check that you have set up R-hub correctly.
* Call `rhub::rhub_check()` to check your package.

# setup_find_r_package

Code
setup_find_r_package()
Message
> Is the current directory part of an R package?
v Found R package at '<wd>'.
Output
[1] "<wd>"

---

Code
setup_find_r_package()
Message
> Is the current directory part of an R package?
x Is the current directory part of an R package?
Condition
Error:
! The current directory is not part of an R package.
i You can create an R package in the current directory if you run `usethis::create_package('.')`.
i Alternatively, if you want to use R-hub for a package that is already on GitHub, supply the `gh_url` argument to `rhub_setup()`.

# setup_find_git_root

Code
setup_find_git_root()
Message
> Is the current directory part of a git repository?
x Is the current directory part of a git repository?
Condition
Error:
! The current R package is not in a git repository.
i You can create a git repository for the current package or project if you run `usethis::use_git()`.
i Alternatively, if you want to use R-hub for a package that is already on GitHub, supply the `gh_url` argument to `rhub_setup()`.

---

Code
setup_find_git_root()
Message
> Is the current directory part of a git repository?
v Found git repository at '<wd>'.
Output
[1] "<wd>"

Loading

0 comments on commit 8a4e176

Please sign in to comment.