From f7e20057c83cf5052260d7efe565aa12b2a3993e Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Nov 2023 09:56:13 -0500 Subject: [PATCH 1/7] Create build.yml --- .github/workflows/build.yml | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c88ddc9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +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: + # !! Same as ./build-wasm-packages/action.yml inputs!! + packages: + description: A file containing a list of R package references. + default: packages + type: string + required: true + upload-image: + description: | + Should the R package library filesystem image be uploaded as an artifact? + default: true + type: boolean + required: true + upload-repo: + description: | + Should the R package repository be uploaded as an artifact? + default: true + type: boolean + required: true + 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: true + +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: + packages: ${{ inputs.packages }} + upload-image: ${{ inputs.upload-image }} + upload-repo: ${{ inputs.upload-repo }} + strip: ${{ inputs.strip }} From 103d3970456765864eeb36f1681b54ab2e34870c Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Nov 2023 10:16:20 -0500 Subject: [PATCH 2/7] Docs --- .github/workflows/README.md | 37 +++++++++++++++++++++++++++++++ .github/workflows/build.yml | 2 ++ README.md | 12 ++++++---- build-wasm-packages/README.md | 15 ++++++++++++- download-wasm-artifacts/README.md | 13 ++++------- examples/build-wasm-repo.yml | 7 +----- examples/deploy-wasm-repo.yml | 11 +++------ 7 files changed, 69 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/README.md diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..9a9334b --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,37 @@ +# 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). + +##### 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 = "build2.yml" +) +``` diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c88ddc9..1a40b6c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,9 @@ on: name: Build wasm R package repository jobs: + # Build and upload the wasm packages build: + # Run the Docker container on the latest ubuntu runs-on: ubuntu-latest container: ghcr.io/r-wasm/webr:main steps: diff --git a/README.md b/README.md index 7ace935..f94566c 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,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 +28,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/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..7093ccc 100644 --- a/examples/build-wasm-repo.yml +++ b/examples/build-wasm-repo.yml @@ -9,9 +9,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..4864c40 100644 --- a/examples/deploy-wasm-repo.yml +++ b/examples/deploy-wasm-repo.yml @@ -9,14 +9,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 From 8e9631461224dfadecdb53689e834fe2f86b716c Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Nov 2023 10:16:57 -0500 Subject: [PATCH 3/7] Rename testing workflow. Move `packages` file to not clutter `workflows` directory --- .github/{workflows => _testing}/packages | 0 .github/workflows/{testing.yml => _testing.yml} | 15 ++++++++++----- README.md | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) rename .github/{workflows => _testing}/packages (100%) rename .github/workflows/{testing.yml => _testing.yml} (62%) 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/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/README.md b/README.md index f94566c..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. From b23502541a0411e42d52390845cf6c658b84b758 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Nov 2023 10:23:51 -0500 Subject: [PATCH 4/7] Do not require parameters for `build-wasm-packages` action --- .github/workflows/build.yml | 8 ++++---- build-wasm-packages/action.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a40b6c..2d054f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,26 +12,26 @@ on: description: A file containing a list of R package references. default: packages type: string - required: true + required: false upload-image: description: | Should the R package library filesystem image be uploaded as an artifact? default: true type: boolean - required: true + required: false upload-repo: description: | Should the R package repository be uploaded as an artifact? default: true type: boolean - 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" type: string - required: true + required: false name: Build wasm R package repository 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: From 8c961c65a622bb611902d0a50f4d3cda2d0472db Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Nov 2023 10:30:53 -0500 Subject: [PATCH 5/7] Add `name` input. Inputs docs for workflow --- .github/workflows/README.md | 12 ++++++++++-- .github/workflows/build.yml | 10 +++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 9a9334b..0f5026e 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -6,11 +6,19 @@ Workflows whose name starts with an `_` are intended for internal use only, and ## List of workflows -#### [`r-wasm/actions/.github/workflows/build.yml`](https://github.com/r-wasm/actions/tree/v1/.github/workflows/build.yml) +### [`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). -##### Usage +#### 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: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d054f8..1b276bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,13 @@ on: # uses: r-wasm/actions/.github/workflows/build.yml@v1 workflow_call: inputs: - # !! Same as ./build-wasm-packages/action.yml 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 @@ -38,6 +44,8 @@ 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 From c9fa531e620615878cfd1a79273c3418e46e430b Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 9 Nov 2023 14:52:00 -0500 Subject: [PATCH 6/7] Update .github/workflows/README.md --- .github/workflows/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 0f5026e..373128d 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -40,6 +40,6 @@ 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 = "build2.yml" + save_as = "build.yml" ) ``` From abab303d5d474f5c4f0c94bec158f076b0f80484 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 9 Nov 2023 14:53:54 -0500 Subject: [PATCH 7/7] Add comment as to where the examples came from and how to debug --- examples/build-wasm-repo.yml | 2 ++ examples/deploy-wasm-repo.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/examples/build-wasm-repo.yml b/examples/build-wasm-repo.yml index 7093ccc..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] diff --git a/examples/deploy-wasm-repo.yml b/examples/deploy-wasm-repo.yml index 4864c40..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]