Skip to main content

Check a package with its Julia code on GitHub Actions

Source: R/scaffold.R

Description

Writes a GitHub Actions workflow that checks the package with and without Julia. With Julia, it runs R CMD check on Linux, Windows and macOS after compiling the package’s Julia code with build_library(), so tests and examples that need the library run. Without Julia, it checks the package once on Linux, as CRAN does, where those tests and examples must be skipped. The workflow is written to .github/workflows/R-CMD-check.yaml.

Usage

use_jlbind_ci(path = ".", overwrite = FALSE)

Arguments

path Path to the package sources.
overwrite If TRUE, replace an existing .github/workflows/R-CMD-check.yaml.

Details

The workflow replaces the standard one written by usethis::use_github_action("check-standard"), which has the same name.

Value

The path to the workflow, invisibly.

Examples

# A package in a temporary directory
pkg <- tempfile("mypkg")
dir.create(pkg)
writeLines(c("Package: mypkg", "Version: 0.1.0"), file.path(pkg, "DESCRIPTION"))

file <- use_jlbind_ci(pkg)
#> Wrote /tmp/RtmpcYf8kH/mypkg193747fcc859/.github/workflows/R-CMD-check.yaml.
writeLines(readLines(file))
#> # Generated by jlbind::use_jlbind_ci(), from r-lib/actions' check-standard
#> # workflow: https://github.com/r-lib/actions/tree/v2/examples
#> #
#> # Runs R CMD check with Julia on Linux, Windows and macOS, after compiling the
#> # package's Julia code into a library its tests and examples can call, and once
#> # on Linux without Julia, which is what CRAN sees: the package must install and
#> # pass its checks without the library.
#> on:
#>   push:
#>     branches: [main, master]
#>   pull_request:
#> 
#> name: R-CMD-check.yaml
#> 
#> permissions: read-all
#> 
#> jobs:
#>   R-CMD-check:
#>     runs-on: ${{ matrix.config.os }}
#> 
#>     name: ${{ matrix.config.os }} (${{ matrix.config.r }})${{ matrix.config.julia == '' && ' without Julia' || format(' Julia {0}', matrix.config.julia) }}
#> 
#>     strategy:
#>       fail-fast: false
#>       matrix:
#>         config:
#>           - {os: ubuntu-latest,   r: 'release', julia: 'nightly'}
#>           - {os: windows-latest,  r: 'release', julia: 'nightly'}
#>           - {os: macos-latest,    r: 'release', julia: 'nightly'}
#>           - {os: ubuntu-latest,   r: 'release', julia: ''}
#> 
#>     env:
#>       GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
#>       R_KEEP_PKG_SOURCE: yes
#> 
#>     steps:
#>       - uses: actions/checkout@v7
#> 
#>       - uses: julia-actions/setup-julia@v3
#>         if: matrix.config.julia != ''
#>         with:
#>           version: ${{ matrix.config.julia }}
#> 
#>       - uses: julia-actions/cache@v3
#>         if: matrix.config.julia != ''
#> 
#>       - uses: r-lib/actions/setup-pandoc@v2
#> 
#>       - uses: r-lib/actions/setup-r@v2
#>         with:
#>           r-version: ${{ matrix.config.r }}
#>           http-user-agent: ${{ matrix.config.http-user-agent }}
#>           use-public-rspm: true
#> 
#>       - uses: r-lib/actions/setup-r-dependencies@v2
#>         with:
#>           extra-packages: any::rcmdcheck, BjarkeHautop/jlbind
#>           needs: check
#> 
#>       # Compiles the package's Julia code into .jlbind/ and points
#>       # JLBIND_LIBRARY at the library, so R CMD check binds the package to it.
#>       - name: Compile the Julia library
#>         if: matrix.config.julia != ''
#>         shell: Rscript {0}
#>         run: |
#>           lib <- jlbind::build_library()
#>           cat(
#>             "JLBIND_LIBRARY=", lib, "\n",
#>             sep = "", file = Sys.getenv("GITHUB_ENV"), append = TRUE
#>           )
#> 
#>       - uses: r-lib/actions/check-r-package@v2
#>         with:
#>           upload-snapshots: true
#>           build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'