diff --git a/.github/workflows/packages b/.github/_testing/packages similarity index 100% rename from .github/workflows/packages rename to .github/_testing/packages diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..373128d --- /dev/null +++ b/.github/workflows/README.md @@ -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" +) +``` diff --git a/.github/workflows/testing.yml b/.github/workflows/_testing.yml similarity index 62% rename from .github/workflows/testing.yml rename to .github/workflows/_testing.yml index 0f1e76e..dc822c3 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/_testing.yml @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1b276bf --- /dev/null +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/README.md b/README.md index 7ace935..df89fda 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # 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. @@ -7,15 +8,19 @@ This repository stores GitHub Actions associated with R WebAssembly tasks, which 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 @@ -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. diff --git a/build-wasm-packages/README.md b/build-wasm-packages/README.md index c9f9f84..75f6211 100644 --- a/build-wasm-packages/README.md +++ b/build-wasm-packages/README.md @@ -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: @@ -27,4 +41,3 @@ jobs: upload-repo: false strip: c("demo", "doc", "examples", "help") ``` - diff --git a/build-wasm-packages/action.yml b/build-wasm-packages/action.yml index 8782cca..939f206 100644 --- a/build-wasm-packages/action.yml +++ b/build-wasm-packages/action.yml @@ -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: diff --git a/download-wasm-artifacts/README.md b/download-wasm-artifacts/README.md index 41bd8cf..30756fa 100644 --- a/download-wasm-artifacts/README.md +++ b/download-wasm-artifacts/README.md @@ -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 diff --git a/examples/build-wasm-repo.yml b/examples/build-wasm-repo.yml index 9fcb03b..2f7bf43 100644 --- a/examples/build-wasm-repo.yml +++ b/examples/build-wasm-repo.yml @@ -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] @@ -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 diff --git a/examples/deploy-wasm-repo.yml b/examples/deploy-wasm-repo.yml index 052e5da..34e4911 100644 --- a/examples/deploy-wasm-repo.yml +++ b/examples/deploy-wasm-repo.yml @@ -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] @@ -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