Skip to content

Commit c5ec645

Browse files
authored
Merge pull request #174 from r-hub/feature/rhub2
R-hub v2 post
2 parents b114c40 + aeb6375 commit c5ec645

File tree

2 files changed

+549
-0
lines changed

2 files changed

+549
-0
lines changed
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
---
2+
slug: rhub2
3+
title: "R-hub v2"
4+
authors:
5+
- Gábor Csárdi
6+
date: "2024-04-11"
7+
tags:
8+
- R-hub
9+
output: hugodown::hugo_document
10+
summary: |
11+
After eight years, we are retiring the current version of R-hub, in favor
12+
of a better, faster, modern system.
13+
We call the new system R-hub v2.
14+
R-hub v2 runs R package checks on
15+
[GitHub Actions](https://github.com/features/actions).
16+
R-hub v2 works best if your R package is in a GitHub repository.
17+
This post helps you transition to R-hub v2 from the previous version.
18+
---
19+
20+
```{r, setup, include = FALSE}
21+
knitr::opts_chunk$set(
22+
comment = "",
23+
asciicast_theme = "pkgdown",
24+
cache = FALSE
25+
)
26+
asciicast::init_knitr_engine(
27+
echo = FALSE,
28+
echo_input = FALSE,
29+
startup = quote({
30+
library(cli)
31+
options(cli.num_colors = 256)
32+
})
33+
)
34+
options(asciicast_knitr_output = "html")
35+
```
36+
37+
```{asciicast asciicast-setup, include = FALSE, results = "hide"}
38+
pkgload::load_all("~/works/r-hub/rhub")
39+
# emoji output is slightly incorrect currently, maybe a font issue
40+
options(pkg.emoji = FALSE)
41+
options(rlib_interactive = TRUE)
42+
# we do this to have a package to use in the examples
43+
setwd("/tmp")
44+
if (!file.exists("cli")) system("git clone --depth 1 https://github.com/r-lib/cli")
45+
setwd("cli")
46+
unlink(".github/workflows/rhub.yaml")
47+
```
48+
49+
After eight years, we are retiring the current version of R-hub, in favor
50+
of a better, faster, modern system.
51+
We call the new system R-hub v2.
52+
R-hub v2 runs R package checks on
53+
[GitHub Actions](https://github.com/features/actions).
54+
R-hub v2 works best if your R package is in a GitHub repository.
55+
This post helps you transition to R-hub v2 from the previous version.
56+
57+
# TL;DR
58+
59+
**Is your package on GitHub?**
60+
61+
1. Install or update the rhub package.
62+
2. Run `rhub::rhub_setup()` to set up R-hub v2 for your package.
63+
3. Run `rhub::rhub_check()` to run R-hub checks.
64+
65+
**You don't want to put your package on GitHub?**
66+
67+
1. Install or update the rhub package.
68+
2. Run `rhub::rc_submit()` to run R-hub checks.
69+
70+
Do you want to know more? Read on.
71+
72+
# Introduction
73+
74+
R-hub v2 is a completely new check system. To use it you'll need at least
75+
version 2.0.0 of the rhub package.
76+
77+
There are two ways to use R-hub v2. Our recommendation is to store your
78+
R package in a GitHub repository and use the `rhub::rhub_*()` functions to
79+
start checks on GitHub Actions, using your own GitHub account.
80+
81+
Alternatively, if you don't want to store your R package at GitHub, you
82+
can use the `rhub::rc_*()` functions to run checks in a shared GitHub
83+
organization at https://github.com/r-hub2, using the R Consortium runners.
84+
85+
# Transitioning from R-hub v1
86+
87+
In this section we assume that your R package is in a GitHub repository.
88+
See "The R Consortium Runners" section below for a different way of using
89+
R-hub v2.
90+
91+
## Differences from R-hub v1
92+
93+
- The check picks up the package from GitHub, so it does not use
94+
changes in your local git clone. You need to push the changes to
95+
GitHub first. You can use a non-default branch, with the `branch`
96+
argument of `rhub_check()`.
97+
- You'll not get an email about the check results. But you'll receive
98+
regular GitHub notifications about check failures, unless you opt out.
99+
Github can also turn these into emails if you like.
100+
- There is no live output from the check at the R console. See the
101+
'Actions' tab of your repository on GitHub for a live check log.
102+
- Many more specialized platforms are available.
103+
- Most platforms use binary packages, so checks and in particular
104+
installing dependencies is much faster.
105+
106+
### Private repositories
107+
108+
GitHub Actions is free for public repositories.
109+
For private repositories you also get some minutes for free, depending on
110+
the GitHub subscription you have. See
111+
[About billing for GitHub Actions](https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions)
112+
for pricing and more details.
113+
114+
### Branches
115+
116+
You can run checks on any branch that you push to GitHub, but the R-hub
117+
workflow file (`.github/workflows/rhub.yaml` within your repo) must be
118+
present in **both** your default branch (usually `main`) and also in the
119+
branch you want to run the check on.
120+
121+
## Requirements
122+
123+
- First, you need a GitHub account.
124+
- Second, you need to have your R package in a GitHub repository.
125+
Make sure that upstream git remote is set to the GitHub repository
126+
in your local git clone. Run `git branch -vv` to see your local branches
127+
and the upstream branches they are tracking. Example output:
128+
```
129+
❯ git branch -vv
130+
...
131+
* main 87a2066 [origin/main] Avoid fancy quotes in test snapshots
132+
...
133+
❯ git remote -v
134+
origin [email protected]:r-hub/rhub.git (fetch)
135+
origin [email protected]:r-hub/rhub.git (push)
136+
```
137+
which means that the `main` branch is tracking `origin/main`, and
138+
from the second command we can see that `origin` indeed refers to GitHub.
139+
- Third, you need a GitHub
140+
[Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
141+
(PAT) and you need to store it in the git credential store on your
142+
machine. You can use `gitcreds::gitcreds_set()` to add the token to the
143+
git credential store. If you cannot use the git credential store for some
144+
reason (e.g. you are on Linux, and there is no good credential helper
145+
available for you), you can also set the `GITHUB_PAT` environment
146+
variable to your GitHub PAT in the `~/.Renviron` file.
147+
148+
## Set up R-hub v2
149+
150+
Once you took care of all these requirements, setting up R-hub v2 for your
151+
package goes like this.
152+
153+
### STEP 1: install the rhub package
154+
155+
Install the rhub package:
156+
157+
```{r, asciicast-install, eval = FALSE, cache = FALSE}
158+
install.packages("rhub")
159+
```
160+
161+
### STEP 2: add the R-hub v2 workflow
162+
163+
In your local git clone, switch to your default git branch and call
164+
`rhub::rhub_setup()`. This adds a GitHub Actions workflow to your local
165+
repository. Push this change to GitHub, into your default git branch.
166+
167+
`rhub::rhub_setup()` guides you through the process:
168+
```r
169+
rhub::rhub_setup()
170+
```
171+
```{asciicast rhub-setup}
172+
rhub::rhub_setup()
173+
```
174+
175+
(If you want to run checks on another branch, you need to add this
176+
workflow to that branch as well, manually or with `rhub::rhub_setup()`.)
177+
178+
### STEP 3: check your setup
179+
180+
Call `rhub::rhub_doctor()` to check that everything is set up correctly:
181+
182+
```r
183+
rhub::rhub_doctor()
184+
```
185+
```{asciicast rhub-doctor}
186+
rhub::rhub_doctor()
187+
```
188+
189+
### STEP 4: run checks
190+
191+
If `rhub::rhub_doctor()` did not find any issue, then you are ready
192+
to run checks with `rhub::rhub_check()`. It goes like this:
193+
194+
```{asciicast include = FALSE}
195+
testthat::local_mocked_bindings(
196+
gh_rest_post = function(...) list(status_code = 204L),
197+
readline = function(prompt) {
198+
cat(prompt)
199+
Sys.sleep(1)
200+
cat("1, 5\n")
201+
"1, 5"
202+
}
203+
)
204+
```
205+
```r
206+
rhub::rhub_check()
207+
```
208+
209+
```{asciicast rhub-check}
210+
rhub::rhub_check()
211+
```
212+
213+
# The R Consortium runners
214+
215+
If you don't want to put your package on GitHub, you can still use the
216+
rhub package to run package checks on any supported platform using a
217+
shared pool of runners in the https://github.com/r-hub2 GitHub
218+
organization, that belong to the R Consortium.
219+
220+
## Set up the RC runners
221+
222+
The process is similar to R-hub v1:
223+
224+
### STEP 1: install the rhub package
225+
226+
```r
227+
install.packages("rhub")
228+
```
229+
230+
### STEP 2: get an R-hub token
231+
232+
Obtain a token from R-hub, to verify your email address:
233+
```
234+
rc_new_token()
235+
```
236+
237+
You do not need to do this, if you already submitted packages to a
238+
previous version of R-hub from the same machine, using the same email
239+
address. Call `rc_list_local_tokens()` to see the email addresses that
240+
you you already have tokens for on this machine.
241+
242+
### STEP 3: submit a check
243+
244+
Submit a check with
245+
```
246+
rc_submit()
247+
```
248+
249+
Select the platforms you want to use, and follow the instructions and
250+
the link provided to see your check results.
251+
252+
## Limitations of the RC runners
253+
254+
Using the R Consortium runners comes with some limitations.
255+
256+
* You package will be public for the world, and will be stored in the
257+
https://github.com/r-hub2 organization. Your check output and results
258+
will be public for anyone with a GitHub account. If you want to keep
259+
your package private, you can put it in a private GitHub repository,
260+
and use the `rhub_setup()` and `rhub_check()` functions instead of the
261+
RC runners.
262+
* The R Consortium runners are shared among all users, so you might need
263+
to wait for your builds to start.
264+
* You have to wait at least five minutes between submissions with
265+
`rc_submit()`.
266+
* Currently you need to create a GitHub account to see the check logs of
267+
your package. You don't need a GitHub account to submit the checks.
268+
269+
To avoid these limitations (except for the neeed for a GitHub accounr),
270+
put your package in a GitHub repository, and use the `rhub_setup()` and
271+
`rhub_check()` functions instead of `rc_submit()` and the R Consortium
272+
runners.
273+
274+
# Feedback
275+
276+
We believe that R-hub v2 is already working better than the previous
277+
version of R-hub, but you might still run into edge cases.
278+
279+
If you have question about R-hub, please use our
280+
[discussions forum on GitHub](https://github.com/r-hub/rhub/discussions).
281+
282+
If you found a bug, then please open an issue at
283+
[our issue tracker](https://github.com/r-hub/rhub/issues).
284+
285+
We hope that this resource will be useful for your R work!

0 commit comments

Comments
 (0)