Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add template file for GHA #11

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ License: Artistic-2.0
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
URL: https://github.com/lcolladotor/biocthis
BugReports: https://support.bioconductor.org/t/biocthis
biocViews: Software, ReportWriting
Imports:
BiocManager,
fs,
glue,
rlang,
Expand Down
67 changes: 41 additions & 26 deletions R/use_bioc_github_action.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
.normalizeVersion <- function() {
if (BiocManager:::isDevel())
"devel"
else
paste0("RELEASE_", gsub("\\.", "_", BiocManager::version()))
}

.GHARversion <- function() {
rver <- with(R.version, paste(major, minor, sep = "."))
gsub("\\.", "-", rver)
}

#' Create a biocthis-style GitHub Actions workflow
#'
#' This function is very similar to `usethis::use_github_action()` except
#' that it uses a template from `biocthis`. It creates a Bioconductor-friendly
#' GitHub action workflow for your package. You can also use this GitHub
#' Actions workflow by executing
#' `usethis::use_github_action("check-bioc", "https://bit.ly/biocthis_gha", "check-bioc.yml")`
#' without having to install `biocthis`.
#' Actions workflow by executing `usethis::use_github_action()`.
#'
#' For the full history on how this GitHub Actions workflow came to be, check
#' the "biocthis developer notes" vignette
#' <https://lcolladotor.github.io/biocthis/articles/biocthis_dev_notes.html>.
#'
#' @return This function adds and/or replaces the
#' `.github/workflows/check-bioc.yml` file in your R package.
#'
#' @export
#'
#' @import usethis
#'
#' @examples
#'
#' \dontrun{
#' ## Run this function in your package
#' biocthis::use_bioc_github_action()
#'
#' ## You can also use this GitHub Actions workflow without installing biocthis
#' ## by running:
#' usethis::use_github_action(
#' "check-bioc", "https://bit.ly/biocthis_gha",
#' "check-bioc.yml"
#' )
#' ## Run this function in your package
#' biocthis::use_bioc_github_action()
#' }
#'
#' ## Create an example package for illustrative purposes.
#' ## Note: you do not need to run this for your own package!
#' pkgdir <- biocthis_example_pkg()
#'
#' ## Create a GitHub Actions workflow that is Bioconductor-friendly
#' biocthis::use_bioc_github_action()
use_bioc_github_action <- function() {
usethis::use_github_action(
"check-bioc",
url = paste0(
"https://raw.githubusercontent.com/",
"lcolladotor/biocthis/",
"master/actions/check-bioc.yml"
)
datalist <- list(
version = .normalizeVersion(),
rversion = .GHARversion(),
rvernum = BiocManager:::.get_R_version()
)
template <- system.file(package = "biocthis", "templates",
"check-bioc.yml", mustWork = TRUE)
contents <- readLines(template)
idx <- grep("[^$]\\{\\{", contents)
parts <- grep("[^$]\\{\\{", contents, value = TRUE)
pco <- vector("character", length(parts))
for (i in seq_along(parts)) {
pco[[i]] <- mapply(
function(x, y) {
parts[[i]] <<- gsub(x, y, parts[[i]], fixed = TRUE)
}, x = paste0("{{", names(datalist), "}}"), y = datalist
)[[length(datalist)]]
}
contents[idx] <- pco
## code taken from usethis
usethis:::use_dot_github(ignore = TRUE)
save_as <- fs::path(".github", "workflows", "check-bioc.yml")
usethis:::create_directory(dirname(usethis:::proj_path(save_as)))
new <- usethis:::write_over(usethis:::proj_path(save_as), contents)
invisible(new)
}
97 changes: 97 additions & 0 deletions inst/templates/check-bioc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
on:
push:
pull_request:

name: R-CMD-BiocCheck

jobs:
build-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
container: ${{ matrix.config.cont }}
## Environment variables unique to this job.

strategy:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, r: '{{rvernum}}', cont: bioconductor/bioconductor_docker:{{version}}, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }
- { os: macOS-latest, r: '{{rvernum}}' }
- { os: windows-latest, r: '{{rvernum}}' }
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
NOT_CRAN: true
TZ: UTC

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

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

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
shell: Rscript {0}

- name: Install Bioconductor
if: runner.os != 'Linux'
run: |
install.packages('BiocManager')
BiocManager::install(version = '{{version}}')
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-{{rversion}}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-{{rversion}}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')


- name: Install Dependencies
run: |
remotes::install_local(dependencies = TRUE, repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE)
BiocManager::install("rcmdcheck", update = TRUE, ask = FALSE)
shell: Rscript {0}

- name: Run CMD check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Get Session Info
run: |
options(width = 100)
pkgs <- installed.packages()[, "Package"]
sessioninfo::session_info(pkgs, include_base = TRUE)
shell: Rscript {0}

- name: Run BiocCheck
run: |
BiocCheck::BiocCheck(dir('check', 'tar.gz$', full.names = TRUE), `quit-with-status` = TRUE)
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-r-{{rversion}}-bioc-{{version}}-results
path: check

22 changes: 3 additions & 19 deletions man/use_bioc_github_action.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.