The goal of this repository is to demonstrate how to automate R package submissions to CRAN when a GitHub tag (pre-release) is pushed. You can read more about the motivation and implementation in the blog post.
The Python ecosystem has long enabled developers to automate package publishing to the Python Package Index (PyPI) on a GitHub tag push. This is accomplished through GitHub Actions that listen for tag events and execute the necessary steps to build and submit the package to PyPI, creating a seamless integration between version control and package distribution.
Until now, the R community has lacked a similar mechanism for automating
CRAN submissions. The closest has been using
devtools::submit_cran()
locally in an interactive context, which still requires human
confirmation and local building of the package. While the CRAN
submission process isn’t fully automatable (you still need to manually
confirm via email and handle reviewer feedback), this repository
demonstrates how to automate significant portions of the workflow:
- Building the package tarball (which can be time-consuming, especially for packages with compiled code)
- Submitting the package to CRAN’s web form
- Tracking the submission status through GitHub issues
This automation connects GitHub’s release workflow to CRAN submissions, bringing the R package ecosystem closer to the level of automation enjoyed by Python developers.
- Create a pre-release tag for your R package
- GitHub Actions automatically:
- Runs R CMD check with
--as-cran
flag - Builds the package tarball
- Submits the package to CRAN
- Creates a GitHub issue with the submission status and next steps
- Runs R CMD check with
- You still need to manually click the confirmation link in the CRAN email
To implement this workflow in your own R package:
You can add the necessary files directly from R:
# Create directories if they don't exist
dir.create(path = ".github/workflows", recursive = TRUE, showWarnings = FALSE)
dir.create(path = ".github/scripts", recursive = TRUE, showWarnings = FALSE)
# Download the workflow yaml file
download.file(
url = "https://raw.githubusercontent.com/coatless-r-n-d/r-pkg-submit-on-tag/main/.github/workflows/submit-cran.yaml",
destfile = ".github/workflows/submit-cran.yaml"
)
# Download the submission script
download.file(
url = "https://raw.githubusercontent.com/coatless-r-n-d/r-pkg-submit-on-tag/main/.github/scripts/submit-to-cran.R",
destfile = ".github/scripts/submit-to-cran.R"
)
Alternatively, you can copy the files manually:
- Create
.github/workflows
and.github/scripts
directories in your repository - Copy the
submit-cran.yaml
file to
.github/workflows/
- Copy the
submit-to-cran.R
script to
.github/scripts/
and runchmod +x .github/scripts/submit-to-cran.R
to make it executable.
Once implemented:
- Create a GitHub pre-release when you’re ready to submit to CRAN
- Monitor the GitHub Action logs and the created issue
- Check your email for the CRAN confirmation link (you still need to click this!)
- Cannot fully automate the process (manual email confirmation still required)
- Doesn’t handle communication with CRAN reviewers
- Still an experimental workflow, not yet a proper GitHub Action
AGPL (>= 3)