Skip to content

Commit

Permalink
update R functions to include additional args in YAML files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai-Li-NOAA committed Nov 19, 2024
1 parent 4f09a34 commit 82fb038
Show file tree
Hide file tree
Showing 16 changed files with 915 additions and 313 deletions.
97 changes: 61 additions & 36 deletions .github/workflows/build-pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:

name: build-pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: build pkgdown
run: |
Rscript -e 'pkgdown::build_site()'
- name: save pkgdown output
uses: actions/upload-artifact@v4
with:
name: pkgdown-site
path: docs/

# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:
inputs:
additional_args_windows:
required: false
type: string
default: ""
additional_args_macos:
required: false
type: string
default: ""
additional_args_ubuntu:
required: false
type: string
default: ""

name: build-pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: run additional args on windows
if: matrix.config.os == 'windows-latest'
run: ${{ inputs.additional_args_windows }}

- name: run additional args on macOS
if: matrix.config.os == 'macOS-latest'
run: ${{ inputs.additional_args_macos }}

- name: run additional args on ubuntu
if: matrix.config.os == 'ubuntu-latest'
run: ${{ inputs.additional_args_ubuntu }}

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: build pkgdown
run: |
Rscript -e 'pkgdown::build_site()'
- name: save pkgdown output
uses: actions/upload-artifact@v4
with:
name: pkgdown-site
path: docs/

68 changes: 68 additions & 0 deletions .github/workflows/call-build-pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Checks that the pkgdown site builds for a repository.
# this assumes pkgdown is already set up.
name: call-build-pkgdown
# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
# this workflow runs on pushes to main or master or any time a new tag is pushed
# it also runs everytime a pull request to main or master is opened.
push:
branches: [main, master]
tags: ['*']
pull_request:
branches: [main, master]
jobs:
call-workflow:
uses: nmfs-fish-tools/ghactions4r/.github/workflows/build-pkgdown.yml@add-input-option-workflows
# uses: nmfs-fish-tools/ghactions4r/.github/workflows/build-pkgdown.yml@main
with:
with:
additional_args_ubuntu: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get install --only-upgrade libstdc++6
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
with:
additional_args_ubuntu: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get install --only-upgrade libstdc++6
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
with:
additional_args_ubuntu: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get install --only-upgrade libstdc++6
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
with:
additional_args_ubuntu: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get install --only-upgrade libstdc++6
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
with:
additional_args_ubuntu: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get install --only-upgrade libstdc++6
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
3 changes: 2 additions & 1 deletion .github/workflows/call-r-cmd-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
tree
39 changes: 26 additions & 13 deletions .github/workflows/call-update-pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# updates exiting pkgdown site for a repository
# deploys to a branch gh-pages
name: call-update-pkgdown
# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
# this workflow runs on pushes to main or master or any time a new tag is pushed
workflow_dispatch:
push:
branches: [main, master]
tags: ['*']
jobs:
call-workflow:
uses: nmfs-fish-tools/ghactions4r/.github/workflows/update-pkgdown.yml@main
# updates exiting pkgdown site for a repository
# deploys to a branch gh-pages
name: call-update-pkgdown
# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
# this workflow runs on pushes to main or master or any time a new tag is pushed
workflow_dispatch:
push:
branches: [main, master]
tags: ['*']
jobs:
call-workflow:
uses: nmfs-fish-tools/ghactions4r/.github/workflows/update-pkgdown.yml@add-input-option-workflows
# uses: nmfs-fish-tools/ghactions4r/.github/workflows/update-pkgdown.yml@main
with:
with:
additional_args_ubuntu: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get install --only-upgrade libstdc++6
additional_args_macos: |
brew install curl
additional_args_windows: |
tree
25 changes: 25 additions & 0 deletions .github/workflows/update-pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:
inputs:
additional_args_windows:
required: false
type: string
default: ""
additional_args_macos:
required: false
type: string
default: ""
additional_args_ubuntu:
required: false
type: string
default: ""

name: update-pkgdown

Expand All @@ -12,6 +25,18 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- name: run additional args on windows
if: matrix.config.os == 'windows-latest'
run: ${{ inputs.additional_args_windows }}

- name: run additional args on macOS
if: matrix.config.os == 'macOS-latest'
run: ${{ inputs.additional_args_macos }}

- name: run additional args on ubuntu
if: matrix.config.os == 'ubuntu-latest'
run: ${{ inputs.additional_args_ubuntu }}

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
45 changes: 32 additions & 13 deletions R/input_checks.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# functions to check inputs

#' Check the workflow name is formatted correctly
#'
#' Basically check that it is a filename that ends in .yml
#' @template workflow_name
check_workflow_name <- function(workflow_name) {
stopifnot(is.character(workflow_name))
stopifnot(length(workflow_name) == 1)
get_ext <- grep("\\.yml$", workflow_name)
stopifnot(isTRUE(length(get_ext) == 1))
return(invisible(workflow_name))
}
# functions to check inputs

#' Check the workflow name is formatted correctly
#'
#' Basically check that it is a filename that ends in .yml
#' @template workflow_name
check_workflow_name <- function(workflow_name) {
stopifnot(is.character(workflow_name))
stopifnot(length(workflow_name) == 1)
get_ext <- grep("\\.yml$", workflow_name)
stopifnot(isTRUE(length(get_ext) == 1))
return(invisible(workflow_name))
}

#' Validate additional arguments for R functions
#'
#' @inheritParams use_r_cmd_check
validate_additional_args <- function(additional_args) {
if (!is.null(additional_args)) {
if (!is.list(additional_args)) {
cli::cli_abort("{.var additional_args} must be a named list.")
}
invalid_platforms <- setdiff(names(additional_args), c("windows", "macos", "ubuntu"))
if (length(invalid_platforms) > 0 | is.null(invalid_platforms)) {
cli::cli_abort("Invalid platform in {.var additional_args}: {.val {invalid_platforms}}.
Allowed platforms are {.val windows}, {.val macos}, and {.val ubuntu}.")
}
if (!all(vapply(additional_args, is.character, logical(1)))) {
cli::cli_abort("All values in {.var additional_args} must be character vectors.")
}
}
}
Loading

0 comments on commit 82fb038

Please sign in to comment.