1
1
2
+
2
3
# Unified GH Action for webR/R WASM Package Binaries and {pkgdown} Deployment
3
4
4
5
<!-- badges: start -->
5
6
6
- [ ![ R-CMD-check] ( https://github.com/coatless-tutorials/webr-github-action-wasm-binaries /actions/workflows/R-CMD-check.yaml/badge.svg )] ( https://github.com/coatless-tutorials/webr-github-action-wasm-binaries /actions/workflows/R-CMD-check.yaml )
7
- [ ![ webr-build-binary] ( https://github.com/coatless-tutorials/webr-github-action-wasm-binaries /actions/workflows/deploy-cran-repo .yml/badge.svg )] ( https://github.com/coatless-tutorials/webr-github-action-wasm-binaries /actions/workflows/deploy-cran-repo .yml )
7
+ [ ![ R-CMD-check] ( https://github.com/coatless-tutorials/webr-unified-gh-workflow /actions/workflows/R-CMD-check.yaml/badge.svg )] ( https://github.com/coatless-tutorials/webr-unified-gh-workflow /actions/workflows/R-CMD-check.yaml )
8
+ [ ![ webr-build-binary] ( https://github.com/coatless-tutorials/webr-unified-gh-workflow /actions/workflows/webr-pkgdown-build-and-deploy .yml/badge.svg )] ( https://github.com/coatless-tutorials/webr-unified-gh-workflow /actions/workflows/webr-pkgdown-build-and-deploy .yml )
8
9
<!-- badges: end -->
9
10
10
- Example GitHub Action workflow combining creation of developmental
11
- webR/R WASM Package binaries and ` {pkgdown} ` websites.
11
+ ## Introduction
12
+
13
+ Welcome to this tutorial on combining compiling an R package for
14
+ [ webR] ( https://docs.r-wasm.org/webr/latest/ ) and creating a ` {pkgdown} `
15
+ website using GitHub Actions. In this guide, you will find sample GitHub
16
+ Action workflows designed to generate developmental webR/R WASM Package
17
+ binaries alongside a ` {pkgdown} ` website. If you’re eager to streamline
18
+ the process of building and deploying your R packages for webR while
19
+ also creating a ` {pkgdown} ` website, you’ve come to the right place.
12
20
13
- This repository is part of a series of repositories exploring the topic.
21
+ This repository is part of a series exploring three different
22
+ approaches:
14
23
15
24
- [ Org-focused webR/WASM Package Repository without a ` {pkgdown} `
16
- website
17
- (Preferred)] ( https://github.com/coatless-tutorials/webr-org-gh-action )
25
+ website] ( https://github.com/coatless-tutorials/webr-org-gh-action )
26
+ - This repository serves as an example implementation of the webR
27
+ Project’s [ Build R packages using GitHub
28
+ Actions] ( https://r-wasm.github.io/rwasm/articles/github-actions.html )
29
+ documentation. It focuses on creating an organizational webR/WASM
30
+ Package Repository without the inclusion of a ` {pkgdown} ` website
31
+ that is meant to be triggered through workflow dispatches or changes
32
+ to a ` packages ` file. Explore this repository for insights into
33
+ structuring your own organization-centric webR package repository
34
+ using GitHub Actions.
18
35
- ** [ Unified GitHub Action Deployment using artifacts of R WASM Package
19
- binaries and {pkgdown}
20
- website ] ( https://github.com/coatless-tutorials/webr-unified-gh-workflow )
36
+ binaries and
37
+ {pkgdown} ] ( https://github.com/coatless-tutorials/webr-unified-gh-workflow )
21
38
\[ This repository\] **
39
+ - This repository introduces a unified approach to GitHub Action
40
+ deployment by using artifacts. Unlike the previous strategy, this
41
+ allows for the simultaneous deployment of R WASM binaries and the
42
+ associated ` {pkgdown} ` website by using artifacts. This approach
43
+ helps prevent a continuous increase in repository size. Explore this
44
+ repository to understand how the use of artifacts can streamline
45
+ your deployment process while maintaining a clean and efficient
46
+ version control history.
22
47
- [ Separate GitHub Action Deployment onto ` gh-pages ` branch of R WASM
23
48
Package binaries and {pkgdown}
24
49
website] ( https://github.com/coatless-tutorials/webr-github-action-wasm-binaries )
50
+ - This repository adopts a workflow approach familiar to R package
51
+ developers using ` usethis ` . It employs separate GitHub Actions for
52
+ generating the R WASM package binaries and ` {pkgdown} ` website. The
53
+ key aspect of this approach is the merging and deployment of both
54
+ outputs through the ` gh-pages ` branch. This strategy enhances
55
+ clarity in tracking file changes and provides a transparent view of
56
+ the deployed content. Explore this repository to understand how this
57
+ approach can streamline your R package deployment workflow.
25
58
26
59
# Overview
27
60
@@ -33,42 +66,124 @@ this is the repository for you! Here’s a summary of what you can find in
33
66
the repository:
34
67
35
68
- [ ` .github/workflows/webr-pkgdown-build-and-deploy.yml ` ] ( .github/workflows/webr-pkgdown-build-and-deploy.yml ) :
36
- Modified version of [ ` r-wasm/actions ` ’
37
- deploy-cran-repo.yml] ( https://github.com/r-wasm/actions/blob/d21bf7da50e539df543bbee973087ec585deaba6/examples/deploy-cran-repo.yml )
69
+ A combined workflow leveraging the
70
+ [ ` r-wasm/actions/build-rwasm ` ] ( https://github.com/r-wasm/actions/blob/d21bf7da50e539df543bbee973087ec585deaba6/build-rwasm/README.md )
71
+ action to create R WASM packages,
72
+ [ ` r-lib/actions/examples/pkgdown.yml ` ] ( https://github.com/r-lib/actions/blob/46e9e5f2d0dd3aa6ee94b8f49bcc146201e90959/examples/pkgdown.yaml )
73
+ action to build a ` {pkgdown} ` website,
74
+ [ ` actions/upload-artifact ` ] ( https://github.com/actions/upload-artifact )
75
+ action to make available content in a later portion of the workflow,
76
+ [ ` actions/download-artifact ` ] ( https://github.com/actions/download-artifact )
77
+ action to retrieve a previously created artifact,
78
+ [ ` actions/upload-pages-artifact ` ] ( https://github.com/actions/upload-pages-artifact )
79
+ to upload an artifact onto GitHub Pages, and
80
+ [ ` actions/deploy-pages ` ] ( https://github.com/actions/deploy-pages ) to
81
+ deploy the artifact onto GitHub Pages.
82
+ - [ ` _pkgdown.yml ` ] ( _pkgdown.yml ) : Usual configuration for a ` {pkgdown} `
83
+ website.
38
84
- [ ` DESCRIPTION ` ] ( DESCRIPTION ) : Standard description information for an
39
85
R package
40
86
- [ ` R/in-webr.R ` ] ( R/in-webr.R ) : Check to see if we’re inside of webR or
41
87
not.
42
88
43
- ## Deployment
89
+ ## Deployment Strategy
44
90
45
- This approach moves away from tracking website deployments in a
46
- ` gh-pages ` to generating artifacts with GitHub Actions and, then,
47
- deploying them onto GitHub Pages. As a result, the size of the
48
- repository should not grow large with the addition of a webR/R WASM
49
- Package binary. Though, this means that changes associated with new
91
+ This strategy diverges from the traditional approach of tracking website
92
+ deployments in a ` gh-pages ` branch. Instead, it opts for generating
93
+ artifacts through GitHub Actions and subsequently deploying them onto
94
+ GitHub Pages. This alteration ensures that the repository’s size remains
95
+ manageable even with the inclusion of a webR/R WASM Package binary.
96
+ However, it comes with the trade-off that changes related to new
50
97
` {pkgdown} ` deployments are no longer tracked in the ` gh-pages ` branch.
98
+ The deployments can be downloaded and explored separately from a ` tar `
99
+ file as discussed below.
51
100
52
101
## Setup
53
102
54
- You can re-create the necessary parts to automatically compile R WASM
55
- package binaries and make them available on GitHub Pages with:
103
+ For the setup, we’re going to aim to use [ ` {usethis} ` R
104
+ package] ( https://github.com/r-lib/usethis ) to enable GitHub Pages and
105
+ retrieve a workflow for building both R WASM packages and ` {pkgdown} `
106
+ websites.
56
107
57
- ``` r
58
- if (! requireNamespace(" usethis" , quietly = TRUE )) {install.packages(" usethis" )}
108
+ ### Setup Github Pages on the Repository
59
109
110
+ We can enable GitHub pages directly from ` usethis ` with:
60
111
61
- # Ensure GitHub Pages is setup
112
+ ``` r
113
+ if (! requireNamespace(" usethis" , quietly = TRUE )) {
114
+ install.packages(" usethis" )
115
+ }
116
+
117
+ # Ensure GitHub Pages is set up
62
118
usethis :: use_github_pages()
119
+ ```
120
+
121
+ Another option is directly enabling GitHub Pages on the repository by
122
+ following:
123
+
124
+ 1 . Click on the ** Settings** tab for the repository
125
+ 2 . Under “Code and automation”, select the ** Pages** menu item.
126
+ 3 . Under the “Source” option select ** GitHub Actions** from the drop
127
+ down.
128
+ 4 . In the “Custom Domain” settings, make sure that ** Enforce HTTPS** is
129
+ checked.
130
+
131
+ ![ Example configuration of GitHub
132
+ Pages] ( man/figures/gh-pages-setup-options.png )
133
+
134
+ ### Setup the R WASM Package Build GitHub Action
135
+
136
+ Next, obtain a copy of the modified GitHub Action workflow that compiles
137
+ the R WASM package binaries and deploys them onto GitHub Pages by
138
+ committing into the ` gh-pages ` branch with the following R code:
63
139
140
+ ``` r
64
141
# Obtain the modified version of the rwasm repo setup
65
142
usethis :: use_github_action(
66
143
" https://github.com/coatless-tutorials/webr-unified-gh-workflow/blob/main/.github/workflows/webr-pkgdown-build-and-deploy.yml"
67
144
)
68
145
```
69
146
70
- Viola! Binaries will automatically be built on each new commit and
71
- published on the repository’s website served by GitHub Pages.
147
+ Or, you can re-create what ` usethis ` is doing by using:
148
+
149
+ ``` r
150
+ # Create the GitHub workflows directory if not present
151
+ dir.create(" .github/workflows" , showWarnings = FALSE , recursive = TRUE )
152
+
153
+ # Download the GitHub Action workflow into the repository
154
+ download.file(
155
+ url = " https://github.com/coatless-tutorials/webr-unified-gh-workflow/blob/main/.github/workflows/webr-pkgdown-build-and-deploy.yml" ,
156
+ destfile = " .github/workflows/webr-pkgdown-build-and-deploy.yml"
157
+ )
158
+
159
+ # Block R build from including the GitHub folder
160
+ writeLines(
161
+ text = " ^\. github$" ,
162
+ con = file(" .Rbuildignore" , " a" )
163
+ )
164
+ ```
165
+
166
+ That’s it! Binaries alongside a ` {pkgdown} ` website will now be
167
+ automatically built upon each new commit and published on the
168
+ repository’s website served by GitHub Pages.
169
+
170
+ ## Observing Data Uploaded
171
+
172
+ When the workflow completes, the packages and ` {pkgdown} ` website are
173
+ uploaded onto GitHub Pages through an artifact. The artifacts are stored
174
+ for 90 days (by default) and can be found under the workflow summary:
175
+
176
+ 1 . Click on the ** Actions** tab for the repository
177
+ 2 . Select a completed build
178
+ 3 . Press the ** Summary** option
179
+ 4 . Under “Artifacts”, click on ** github-pages** to download the built
180
+ repository
181
+
182
+ ![ ] ( man/figures/github-actions-webr-repo-github-pages-artifact.png )
183
+
184
+ ** Note:** The size of the ` github-pages ` deployment is 9.88 MB of
185
+ compressed space, while the size of the ` rwasmrepo ` is only 3.97 MB of
186
+ the total compressed space.
72
187
73
188
## Accessing Binaries
74
189
@@ -92,46 +207,44 @@ The easiest is probably to define the location webR should search for in
92
207
` options() ` .
93
208
94
209
``` r
95
- # Run once at the start of the session
96
- options(
97
- webr_pkg_repos = c(
210
+ # # Run once at the start of the session
211
+
212
+ # Specify where to search for the R WASM packages
213
+ list_of_repos = c(
98
214
" https://gh-username.github.io/repo-name" ,
99
215
" https://other-gh-username.github.io/another-repo" ,
100
216
" https://username.r-universe.dev" ,
101
217
" https://repo.r-wasm.org/"
102
218
)
219
+
220
+ # Set the repository URLs
221
+ options(
222
+ repos = list_of_repos ,
223
+ webr_pkg_repos = list_of_repos
103
224
)
104
225
105
- # Call
226
+ # Install the R WASM Package
106
227
webr :: install(" pkgname" )
107
228
```
108
229
109
- <div >
110
-
111
- > ** Note**
230
+ > [ !NOTE]
112
231
>
113
232
> This is different than the ` repos ` option one would usually set since
114
233
> webR only checks the [ ` webr_pkg_repos `
115
- > key] ( https://github.com/r-wasm/webr/blob/010223433079d1a9ef3eb9bbf73d8eccb38e6adc/packages/webr/R/install.R#L23 )
116
-
117
- </ div >
234
+ > key] ( https://github.com/r-wasm/webr/blob/010223433079d1a9ef3eb9bbf73d8eccb38e6adc/packages/webr/R/install.R#L23 ) ;
235
+ > however, other R functions like ` available.packages() ` check the
236
+ > ` repos ` parameter.
118
237
119
238
Otherwise, you can specify it each time in the ` webr::install() `
120
239
command:
121
240
122
241
``` r
123
- webr :: install(" pkgname" , c(
124
- " https://gh-username.github.io/repo-name" ,
125
- " https://other-gh-username.github.io/another-repo" ,
126
- " https://username.r-universe.dev" ,
127
- " https://repo.r-wasm.org/"
128
- )
129
- )
130
- ```
242
+ webr :: install(" pkgname" , repos = " https://gh-username.github.io/repo-name" )
131
243
132
- <div >
244
+ webr :: install(" pkgname" , repos = list_of_repos )
245
+ ```
133
246
134
- > ** Note **
247
+ > [ !NOTE ]
135
248
>
136
249
> We do not suggest modifying at the initialization phase the
137
250
> [ ` repoUrl ` ] ( https://docs.r-wasm.org/webr/latest/api/js/interfaces/WebR.WebROptions.html#repourl )
@@ -140,11 +253,7 @@ webr::install("pkgname", c(
140
253
> as that will limit the packages to only one repository (e.g. the
141
254
> custom repository).
142
255
143
- </div >
144
-
145
- <div >
146
-
147
- > ** Important**
256
+ > [ !IMPORTANT]
148
257
>
149
258
> Please make sure the repository’s [ GitHub Pages website is available
150
259
> over
@@ -160,8 +269,6 @@ webr::install("pkgname", c(
160
269
>
161
270
> Warning: unable to access index for repository http://gh-username.github.io/repo-name/bin/emscripten/contrib/4.3
162
271
163
- </div >
164
-
165
272
## Verify
166
273
167
274
Go to the [ webR REPL Editor] ( https://webr.r-wasm.org/v0.2.2/ ) (pinned to
0 commit comments