Search code examples
rpackagerepositorygithub-actionsr-usethis

Setting up GH actions in a subdirectory (several packages in one repo)


When writing R packages, I prefer to set up CI with usethis::use_github_actions(), which creates a .github/ directory in the root, where GH action jobs are designed to run: https://stackoverflow.com/a/72268873/8400969. I have a legacy repo that contains several R packages in a /R directory, and some other things (e.g., a python application) in other directories, and would like to set up continuous integration for the R packages (each, separately, ideally without moving each to their own repo). How can I set up the GH actions workflows so they check each R package in the /R parent directory, separately? Will I be able to use the tools from usethis to create badges, pkgdown websites, etc. with a repo structure like this?

Hard to know what a reproducible example is, but maybe this is a good starting point: a directory with two mature R packages in them, each (currently) with their own .github subdirectory providing instructions for GH actions.

Commands entered into shell on macOS to create:

mkdir example_repo
cd example_repo
git clone https://github.com/r-lib/scales.git
git clone https://github.com/r-lib/roxygen2
cd roxygen2
rm -rf .git
cd ../scales
rm -rf .git

Solution

  • I got this to work by modifying the workflow (.github/workflows/R-CMD-check.yaml) to set the working-directory for both r-lib/actions/setup-r-dependencies@v2 and r-lib/actions/check-r-package@v2 to point to the package sub-directories. For example, in my case the relevant section of the workflow looks like this ...

           - uses: r-lib/actions/setup-r-dependencies@v2
             with:
               extra-packages: any::rcmdcheck
               needs: check
               working-directory: './pkg/grImport2'
     
           - uses: r-lib/actions/check-r-package@v2
             with:
               upload-snapshots: true
               build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
               working-directory: './pkg/grImport2'
    

    I found the working-directory option here.