|
| 1 | + |
1 | 2 | # webr-github-action-wasm-binaries
|
2 | 3 |
|
3 | 4 | <!-- badges: start -->
|
| 5 | + |
4 | 6 | [](https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/actions/workflows/R-CMD-check.yaml)
|
5 | 7 | [](https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/actions/workflows/deploy-cran-repo.yml)
|
6 | 8 | <!-- badges: end -->
|
7 | 9 |
|
8 |
| -Example GitHub Actions workflow with an R package that generates developmental webR binaries |
| 10 | +Example GitHub Action workflow to generate developmental webR/R WASM |
| 11 | +Package binaries |
| 12 | + |
| 13 | +# Overview |
| 14 | + |
| 15 | +Interested in having your R package automatically be built for |
| 16 | +[webR](https://docs.r-wasm.org/webr/latest/) through a [GitHub |
| 17 | +Action](https://github.com/features/actions)? If so, this is the |
| 18 | +repository for you! Here’s a summary of what you can find in the |
| 19 | +repository: |
| 20 | + |
| 21 | +- [`.github/workflows/deploy-cran-repo.yml`](.github/workflows/deploy-cran-repo.yml): |
| 22 | + Modified version of [`r-wasm/actions`’ |
| 23 | + deploy-cran-repo.yml](https://github.com/r-wasm/actions/blob/d21bf7da50e539df543bbee973087ec585deaba6/examples/deploy-cran-repo.yml) |
| 24 | +- [`DESCRIPTION`](DESCRIPTION): Standard description information for an |
| 25 | + R package |
| 26 | +- [`R/in-webr.R`](R/in-webr.R): Check to see if we’re inside of webR or |
| 27 | + not. |
| 28 | + |
| 29 | +You can view the pushed webR package binary parts by looking at the |
| 30 | +[`gh-pages`](https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/tree/gh-pages) |
| 31 | +branch of the repository. Specifically, we can see binary package data |
| 32 | +[`bin/emscripten/contrib/4.3`](https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/tree/gh-pages/bin/emscripten/contrib/4.3) |
| 33 | +and the package information in |
| 34 | +[`src/contrib`](https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/tree/gh-pages/src/contrib). |
| 35 | +You can read more about package repositories that are CRAN-like in the |
| 36 | +[R Administration: 6.6 Setting up a package |
| 37 | +repository](https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Setting-up-a-package-repository). |
9 | 38 |
|
10 |
| -## Steps |
| 39 | +## Setup |
11 | 40 |
|
12 |
| -1. Deployed |
| 41 | +You can re-create the necessary parts to automatically compile R WASM |
| 42 | +package binaries and make them available on GitHub Pages with: |
13 | 43 |
|
14 |
| -```r |
| 44 | +``` r |
| 45 | +if(!requireNamespace("usethis", quietly = TRUE)) {install.packages("usethis")} |
| 46 | + |
| 47 | + |
| 48 | +# Ensure GitHub Pages is setup |
| 49 | +usethis::use_github_pages() |
| 50 | + |
| 51 | +# Obtain the modified version of the rwasm repo setup |
15 | 52 | usethis::use_github_action(
|
16 |
| - url = "https://raw.githubusercontent.com/r-wasm/actions/v1/examples/deploy-cran-repo.yml" |
| 53 | + "https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/blob/main/.github/workflows/deploy-cran-repo.yml" |
17 | 54 | )
|
18 | 55 | ```
|
19 | 56 |
|
20 |
| -2. Modify to include `packages: .` to trigger `pak` to treat the local environment as the package |
| 57 | +Viola! Binaries will automatically be built on each new commit and |
| 58 | +published on the repository’s website served by GitHub Pages. |
21 | 59 |
|
22 |
| -3. Enable GH pages |
| 60 | +## Accessing Binaries |
23 | 61 |
|
24 |
| -```r |
25 |
| -usethis::use_github_pages() |
26 |
| -``` |
| 62 | +Inside of a webR session, you can access the built binaries by using the |
| 63 | +repository’s GitHub Pages URL, e.g. |
27 | 64 |
|
28 |
| -Avoids: |
| 65 | + https://gh-username.github.io/repo-name |
29 | 66 |
|
30 |
| -``` |
31 |
| -Error: Creating Pages deployment failed |
32 |
| -Error: HttpError: Not Found |
33 |
| - at /home/runner/work/_actions/actions/deploy-pages/v2/node_modules/@octokit/request/dist-node/index.js:86:1 |
34 |
| - at processTicksAndRejections (node:internal/process/task_queues:96:5) |
35 |
| - at createPagesDeployment (/home/runner/work/_actions/actions/deploy-pages/v2/src/internal/api-client.js:126:1) |
36 |
| - at Deployment.create (/home/runner/work/_actions/actions/deploy-pages/v2/src/internal/deployment.js:80:1) |
37 |
| - at main (/home/runner/work/_actions/actions/deploy-pages/v2/src/index.js:30:1) |
38 |
| -Error: Error: Failed to create deployment (status: 404) with build version 0e5457c152727daecc085994d0dd749653c6ab17. Ensure GitHub Pages has been enabled: https://github.com/coatless-tutorials/webr-github-action-wasm-binaries/settings/pages |
| 67 | +This can be set either using `options()` or specifying the location in |
| 68 | +each `webr::install()` call. |
| 69 | + |
| 70 | +The easiest is probably to define the location webR should search for in |
| 71 | +`options()`. |
| 72 | + |
| 73 | +``` r |
| 74 | +# Run once at the start of the session |
| 75 | +options( |
| 76 | + repos = c("https://gh-username.github.io/repo-name", |
| 77 | + "https://repo.r-wasm.org/") |
| 78 | +) |
| 79 | + |
| 80 | +# Call |
| 81 | +webr::install("pkgname") |
39 | 82 | ```
|
40 | 83 |
|
41 |
| -4. Enable `main` or `master` branch deployments to `gh-pages` to avoid running into: |
| 84 | +Otherwise, you can specify it each time: |
42 | 85 |
|
43 |
| -```sh |
44 |
| -Branch "main" is not allowed to deploy to github-pages due to environment protection rules. |
| 86 | +``` r |
| 87 | +webr::install("pkgname", "https://gh-username.github.io/repo-name") |
45 | 88 | ```
|
46 | 89 |
|
47 |
| -Perform the following steps: |
| 90 | +## Verify |
| 91 | + |
| 92 | +Go to the [webR REPL Editor](https://webr.r-wasm.org/v0.2.2/) (pinned to |
| 93 | +v0.2.2) and run the following: |
| 94 | + |
| 95 | +``` r |
| 96 | +# Check if package `{demorwasmbinary}` is installed |
| 97 | +"demorwasmbinary" %in% installed.packages()[,"Package"] |
| 98 | +# Install the binary from a repository |
| 99 | +webr::install( |
| 100 | + "demorwasmbinary", |
| 101 | + repos = "https://tutorials.thecoatlessprofessor.com/webr-github-action-wasm-binaries/" |
| 102 | +) |
| 103 | +# Check to see if the function works |
| 104 | +demorwasmbinary::in_webr() |
| 105 | +# View help documentation |
| 106 | +?demorwasmbinary::in_webr |
| 107 | +``` |
48 | 108 |
|
49 |
| -- Click the repository **Settings**. |
50 |
| -- Select **Environments** under Code and automation section. |
51 |
| -- Click on the **github-pages** environment. |
52 |
| -- Under **Deployment branches** click on **Add deployment branch or tag rule**. |
53 |
| -- Enter the pattern `main` or `master` depending on the name of the primary repository branch. |
| 109 | +You should receive: |
54 | 110 |
|
| 111 | + |
0 commit comments