Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create reusable build.yml workflow #5

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
45 changes: 45 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# r-wasm/actions Reusable workflows

This directory contains [reusable workflows](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows) for use in other repositories. Workflows are stored in the `.github/workflows` directory of this repository, and can be used in other repositories by referencing the workflow file in the `uses` field of a workflow step.

Workflows whose name starts with an `_` are intended for internal use only, and should not be used in other repositories.

## List of workflows

### [`r-wasm/actions/.github/workflows/build.yml`](https://github.com/r-wasm/actions/tree/v1/.github/workflows/build.yml)

Reusable workflow to conveniently checkout the repo, and build/upload the package via [`r-wasm/actions/build-wasm-packages`](https://github.com/r-wasm/actions/tree/v1/build-wasm-packages).

#### Inputs

* **packages** (`'packages'`) - A file path to a text file containing a list of [R package references](https://r-lib.github.io/pkgdepends/reference/pkg_refs.html).
* **upload-image** (`true`) - Should the R package library filesystem image be uploaded as an artifact?
* **upload-repo** (`true`) - Should the R package repository be uploaded as an artifact?
* **strip** (`NULL`) - An R expression evaluating to a character vector of directories to strip when building the R package library image. Only the R package library is affected, the R package repository remains unchanged.
* **name** (`'Build wasm packages'`) - The name of the job.

#### Usage

```yaml
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:

name: Build wasm R package repository

jobs:
build:
uses: r-wasm/actions/.github/workflows/build.yml@v1
```

To setup this file in your repository, run the following command:

```r
usethis::use_github_action(
url = "https://raw.githubusercontent.com/r-wasm/actions/v1/examples/build-wasm-repo.yml",
save_as = "build.yml"
)
```
15 changes: 10 additions & 5 deletions .github/workflows/testing.yml → .github/workflows/_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ on:
name: r-wasm actions

jobs:
build-workflow:
# Uses `build-wasm-packages@v1` internally
uses: ./.github/workflows/build.yml
with:
packages: .github/_testing/packages
build:
name: Build wasm artifacts
runs-on: ubuntu-latest
container: ghcr.io/r-wasm/webr:main
steps:
- uses: actions/checkout@v3
- name: Build wasm packages
uses: ./build-wasm-packages
with:
packages: .github/workflows/packages
- uses: actions/checkout@v3
- name: Build wasm packages
uses: ./build-wasm-packages
with:
packages: .github/_testing/packages
download:
name: Download wasm artifacts
needs: build
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
on:
# Allow users to run this workflow via reusable workflow
# Avoids boiler plate of setting the container and running the single steps
# Ex:
# jobs:
# build:
# uses: r-wasm/actions/.github/workflows/build.yml@v1
workflow_call:
inputs:
# New input parameters
name:
description: The name of the job
default: "Build wasm packages"
type: string
required: false
# !! ./build-wasm-packages/action.yml inputs!!
packages:
description: A file containing a list of R package references.
default: packages
type: string
required: false
upload-image:
description: |
Should the R package library filesystem image be uploaded as an artifact?
default: true
type: boolean
required: false
upload-repo:
description: |
Should the R package repository be uploaded as an artifact?
default: true
type: boolean
required: false
strip:
description: |
An R expression evaluating to a character vector of directories to strip
when building the R package library image.
default: "NULL"
type: string
required: false

name: Build wasm R package repository

jobs:
# Build and upload the wasm packages
build:
# Should match the name of `./build-wasm-packages` action name
name: ${{ inputs.name }}
# Run the Docker container on the latest ubuntu
runs-on: ubuntu-latest
container: ghcr.io/r-wasm/webr:main
steps:
- uses: actions/checkout@v3
- name: Build wasm packages
uses: r-wasm/actions/build-wasm-packages@v1
with:
packages: ${{ inputs.packages }}
upload-image: ${{ inputs.upload-image }}
upload-repo: ${{ inputs.upload-repo }}
strip: ${{ inputs.strip }}
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# GitHub Actions for working with R and WebAssembly
![r-wasm actions](https://github.com/r-wasm/actions/actions/workflows/testing.yml/badge.svg)

![r-wasm actions](https://github.com/r-wasm/actions/actions/workflows/_testing.yml/badge.svg)

This repository stores GitHub Actions associated with R WebAssembly tasks, which can be used in CI. It also has a number of example workflows which use these actions.

## Releases and tags

We use major version tags to mark breaking changes in these actions. For the current version, please use the `v1` tag, e.g.:

```
```yaml
- uses: r-wasm/actions/build-wasm-packages@v1
```

## List of actions

* [r-wasm/actions/build-wasm-packages](https://github.com/r-wasm/actions/tree/v1/build-wasm-packages) - Build a list of R packages for WebAssembly, create an R library, and build a CRAN-like repository containing the R package binaries.
* [`r-wasm/actions/build-wasm-packages`](https://github.com/r-wasm/actions/tree/v1/build-wasm-packages) - Build a list of R packages for WebAssembly, create an R library, and build a CRAN-like repository containing the R package binaries.

* [`r-wasm/actions/download-wasm-artifacts`](https://github.com/r-wasm/actions/tree/v1/download-wasm-artifacts) - Download GitHub Actions artifacts previously uploaded by `r-wasm/actions/build-wasm-packages`.

## List of workflows

* [r-wasm/actions/download-wasm-artifacts](https://github.com/r-wasm/actions/tree/v1/download-wasm-artifacts) - Download GitHub Actions artifacts previously uploaded by `r-wasm/actions/build-wasm-packages`.
* [`r-wasm/actions/.github/workflows/build.yml`](https://github.com/r-wasm/actions/tree/v1/.github/workflows/build.yml) - [Reusable workflow](https://docs.github.com/en/actions/learn-github-actions/reusing-workflows) to conveniently checkout the repo, and build/upload the package via [`r-wasm/actions/build-wasm-packages`](https://github.com/r-wasm/actions/tree/v1/build-wasm-packages).

## Other GitHub Actions for R projects

Expand All @@ -24,4 +29,4 @@ We use major version tags to mark breaking changes in these actions. For the cur

## Examples

See the [r-wasm/actions/examples](https://github.com/r-wasm/actions/tree/v1/examples) directory for example workflows using these actions.
See the [r-wasm/actions/examples](https://github.com/r-wasm/actions/tree/v1/examples) directory for example workflows using these actions and workflows.
15 changes: 14 additions & 1 deletion build-wasm-packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ This action uses the [rwasm](https://r-wasm.github.io/rwasm/) R package to build

## Usage

Given the amount of boilerplate and the non-traditional use of `container` required for the workflow, it is recommended to use the reusable [build.yml](.github/workflows/build.yml) workflow file provided by this repository.

```yaml
jobs:
build:
uses: r-wasm/actions/.github/workflows/build.yml@v1
with:
upload-image: true
upload-repo: false
strip: c("demo", "doc", "examples", "help")
```

The workflow example above is equivalent to the following:

```yaml
jobs:
build:
Expand All @@ -27,4 +41,3 @@ jobs:
upload-repo: false
strip: c("demo", "doc", "examples", "help")
```

8 changes: 4 additions & 4 deletions build-wasm-packages/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ inputs:
packages:
description: A file containing a list of R package references.
default: packages
required: true
required: false
upload-image:
description: |
Should the R package library filesystem image be uploaded as an artifact?
default: true
required: true
required: false
upload-repo:
description: |
Should the R package repository be uploaded as an artifact?
default: true
required: true
required: false
strip:
description: |
An R expression evaluating to a character vector of directories to strip
when building the R package library image.
default: "NULL"
required: true
required: false
runs:
using: "composite"
steps:
Expand Down
13 changes: 4 additions & 9 deletions download-wasm-artifacts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ This action can be used to download previously built GitHub Action artifacts con
```yaml
jobs:
build:
runs-on: ubuntu-latest
container: ghcr.io/r-wasm/webr:main
steps:
- uses: actions/checkout@v3
- name: Build wasm packages
uses: r-wasm/actions/build-wasm-packages@v1
with:
upload-image: true
upload-repo: false
uses: r-wasm/actions/.github/workflows/build.yml@v1
with:
upload-image: true
upload-repo: false
deploy:
name: Deploy to GitHub pages
needs: build
Expand Down
9 changes: 3 additions & 6 deletions examples/build-wasm-repo.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Workflow derived from https://github.com/r-wasm/actions/tree/v1/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
Expand All @@ -9,9 +11,4 @@ name: Build wasm R package repository

jobs:
build:
runs-on: ubuntu-latest
container: ghcr.io/r-wasm/webr:main
steps:
- uses: actions/checkout@v3
- name: Build wasm packages
uses: r-wasm/actions/build-wasm-packages@v1
uses: r-wasm/actions/.github/workflows/build.yml@v1
13 changes: 5 additions & 8 deletions examples/deploy-wasm-repo.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Workflow derived from https://github.com/r-wasm/actions/tree/v1/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
Expand All @@ -9,14 +11,9 @@ name: Build wasm R package repository

jobs:
build:
runs-on: ubuntu-latest
container: ghcr.io/r-wasm/webr:main
steps:
- uses: actions/checkout@v3
- name: Build wasm packages
uses: r-wasm/actions/build-wasm-packages@v1
with:
strip: c("demo", "doc", "examples", "help", "html", "include", "tests", "vignette")
uses: r-wasm/actions/.github/workflows/build.yml@v1
with:
strip: c("demo", "doc", "examples", "help", "html", "include", "tests", "vignette")
deploy:
name: Deploy to GitHub pages
needs: build
Expand Down