9 changed files with 295 additions and 117 deletions
@ -0,0 +1,102 @@ |
|||
#' Submits a build job for a package |
|||
#' |
|||
#' This function assumes you know what you're doing and expects a valid |
|||
#' `.build.yml` in the `package` directory. |
|||
#' |
|||
#' @param package path to package (assumes current directory) |
|||
#' @param note human-friendly description of this build (markdown, optional) |
|||
#' @param tags character vector of strings that identify this build and can be |
|||
#' used to navigate the dashboard. Each string must use only lowercase |
|||
#' alphanumeric characters, or any of "-_." |
|||
#' @param read_access,write_access character vector of users that have read or write access to the job. |
|||
#' @param execute start build immediately? (Default: `TRUE`) |
|||
#' @param secrets provide secrets to the build? (Default: `TRUE`) |
|||
#' @param browse open browser to the builder URL? (Default: `FALSE`) |
|||
#' @param username see [sourcehut_user()] |
|||
#' @param pat see [sourcehut_pat()] |
|||
#' @references <https://man.sr.ht/builds.sr.ht/api.md> |
|||
#' @export |
|||
build_pkg <- function(package = ".", |
|||
note = "New build", |
|||
tags = c("package", "rstats"), |
|||
read_access = NULL, |
|||
write_access = NULL, |
|||
execute = TRUE, |
|||
secrets = TRUE, |
|||
browse = FALSE, |
|||
username = sourcehut_user(), |
|||
pat = sourcehut_pat()) { |
|||
|
|||
stopifnot(is_package(package)) |
|||
|
|||
build_yml <- rprojroot::find_package_root_file(".build.yml", path = package) |
|||
build_yml <- paste0(readLines(build_yml, warn = FALSE), collapse="\n") |
|||
|
|||
httr::POST( |
|||
url = "https://builds.sr.ht/api/jobs", |
|||
body = list( |
|||
`manifest` = build_yml, |
|||
`note` = note, |
|||
`tags` = tags, |
|||
`access:read` = read_access, |
|||
`access:write` = write_access, |
|||
`execute` = execute, |
|||
`secrets` = secrets |
|||
), |
|||
encode = "json", |
|||
sh_authorize(pat), |
|||
.SOURCEHUT_UA |
|||
) -> res |
|||
|
|||
out <- process_response(res) |
|||
|
|||
if ("id" %in% names(out)) { |
|||
if (browse) { |
|||
browseURL(glue::glue("https://builds.sr.ht/{username}/job/{out[['id']]}")) |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
#' @rdname build_pkg |
|||
#' @param job_id `builds.sr.ht` job id |
|||
#' @export |
|||
get_build_status <- function(job_id, pat = sourcehut_pat()) { |
|||
|
|||
route_url <- glue::glue("https://builds.sr.ht/api/jobs/{job_id}") |
|||
|
|||
res <- make_get_request(route_url) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
|||
#' @rdname build_pkg |
|||
#' @export |
|||
get_build_manifest <- function(job_id, pat = sourcehut_pat()) { |
|||
|
|||
route_url <- glue::glue("https://builds.sr.ht/api/jobs/{job_id}/manifest") |
|||
|
|||
res <- make_get_request(route_url) |
|||
|
|||
httr::stop_for_status(res) |
|||
|
|||
httr::content(res, as = "text", encoding = "UTF-8") |
|||
|
|||
} |
|||
|
|||
#' @rdname build_pkg |
|||
#' @export |
|||
start_build <- function(job_id, pat = sourcehut_pat()) { |
|||
|
|||
route_url <- glue::glue("https://builds.sr.ht/api/jobs/{job_id}/start") |
|||
|
|||
httr::POST( |
|||
url = route_url, |
|||
encode = "json", |
|||
sh_authorize(pat), |
|||
.SOURCEHUT_UA |
|||
) -> res |
|||
|
|||
process_response(res) |
|||
|
|||
} |
@ -0,0 +1,111 @@ |
|||
#!/bin/bash |
|||
# -*- sh-basic-offset: 2; sh-indentation: 2 -*- |
|||
# Helpers for running R pkg builds on builds.sr.ht |
|||
# |
|||
# https://git.sr.ht/~hrbrmstr/sourcehut/blob/master/inst/helpers/build-helper.sh |
|||
|
|||
setup_locale() { |
|||
|
|||
echo "en_US.UTF-8 UTF-8" > loc |
|||
|
|||
sudo cp loc /etc/locale.gen |
|||
sudo locale-gen --purge "en_US.UTF-8" |
|||
sudo /usr/sbin/update-locale LANG=en_US.UTF-8 |
|||
|
|||
export LC_ALL=en_US.UTF-8 |
|||
export LANG=en_US.UTF-8 |
|||
export LANGUAGE=en_US.UTF-8 |
|||
|
|||
rm -f loc |
|||
|
|||
} |
|||
|
|||
setup_cran_repo() { |
|||
|
|||
mkdir -p ~/packages |
|||
|
|||
echo 'options(repos = c(CRAN = "https://cloud.r-project.org"))' > ~/.Rprofile |
|||
echo 'R_LIBS_USER=/home/build/packages' > ~/.Renviron |
|||
|
|||
} |
|||
|
|||
setup_compiler() { |
|||
|
|||
mkdir ~/.R |
|||
echo "CFLAGS=" > ~/.R/Makevars |
|||
echo "CPPFLAGS= " >> ~/.R/Makevars |
|||
echo "CXXFLAGS=" >> ~/.R/Makevars |
|||
echo "FCFLAGS=" >> ~/.R/Makevars |
|||
echo "FFLAGS=" >> ~/.R/Makevars |
|||
echo "GCJFLAGS=" >> ~/.R/Makevars |
|||
echo "LDFLAGS =" >> ~/.R/Makevars |
|||
echo "OBJCFLAGS=" >> ~/.R/Makevars |
|||
echo "OBJCXXFLAGS=" >> ~/.R/Makevars |
|||
|
|||
} |
|||
|
|||
setup_java() { |
|||
|
|||
export LC_ALL=en_US.UTF-8 |
|||
export LANG=en_US.UTF-8 |
|||
export LANGUAGE=en_US.UTF-8 |
|||
|
|||
sudo R CMD javareconf |
|||
|
|||
} |
|||
|
|||
install_deps() { |
|||
|
|||
export LC_ALL=en_US.UTF-8 |
|||
export LANG=en_US.UTF-8 |
|||
export LANGUAGE=en_US.UTF-8 |
|||
|
|||
Rscript -e "devtools::install_deps(pkg = '${R_PACKAGE}', upgrade = 'never', dependencies = TRUE)" |
|||
|
|||
} |
|||
|
|||
build_and_check() { |
|||
|
|||
export LC_ALL=en_US.UTF-8 |
|||
export LANG=en_US.UTF-8 |
|||
export LANGUAGE=en_US.UTF-8 |
|||
|
|||
export _R_CHECK_CRAN_INCOMING_=FALSE |
|||
export _R_CHECK_URLS_USE_CURL_=FALSE |
|||
export _R_CHECK_LENGTH_1_CONDITION_=TRUE |
|||
export _R_CHECK_LENGTH_1_LOGIC2_=TRUE |
|||
export _R_CHECK_TOPLEVEL_FILES_=TRUE |
|||
export _R_CHECK_VC_DIRS_=TRUE |
|||
export _R_CHECK_TIMINGS_=10 |
|||
export _R_CHECK_INSTALL_DEPENDS_=TRUE |
|||
export _R_CHECK_SUGGESTS_ONLY_=TRUE |
|||
export _R_CHECK_NO_RECOMMENDED_=TRUE |
|||
export _R_CHECK_EXECUTABLES_EXCLUSIONS_=FALSE |
|||
export _R_CHECK_DOC_SIZES2_=TRUE |
|||
export _R_CHECK_CODE_ASSIGN_TO_GLOBALENV_=TRUE |
|||
export _R_CHECK_CODE_ATTACH_=TRUE |
|||
export _R_CHECK_CODE_DATA_INTO_GLOBALENV_=TRUE |
|||
export _R_CHECK_CODE_USAGE_VIA_NAMESPACES_=TRUE |
|||
export _R_CHECK_DOT_FIRSTLIB_=TRUE |
|||
export _R_CHECK_DEPRECATED_DEFUNCT_=TRUE |
|||
export _R_CHECK_REPLACING_IMPORTS_=TRUE |
|||
export _R_CHECK_SCREEN_DEVICE_=stop |
|||
export _R_CHECK_TOPLEVEL_FILES_=TRUE |
|||
export _R_CHECK_S3_METHODS_NOT_REGISTERED_=TRUE |
|||
export _R_CHECK_OVERWRITE_REGISTERED_S3_METHODS_=TRUE |
|||
export _R_CHECK_PRAGMAS_=TRUE |
|||
export _R_CHECK_CRAN_INCOMING_USE_ASPELL_=TRUE |
|||
export _R_CHECK_COMPILATION_FLAGS_=TRUE |
|||
export _R_CHECK_R_DEPENDS_=warn |
|||
export _R_CHECK_SERIALIZATION_=TRUE |
|||
export _R_CHECK_R_ON_PATH_=TRUE |
|||
export _R_CHECK_PACKAGES_USED_IN_TESTS_USE_SUBDIRS_=TRUE |
|||
export _R_CHECK_SHLIB_OPENMP_FLAGS_=TRUE |
|||
export _R_CHECK_CONNECTIONS_LEFT_OPEN_=TRUE |
|||
export _R_CHECK_FUTURE_FILE_TIMESTAMPS_=TRUE |
|||
export _R_CHECK_AUTOCONF_=TRUE |
|||
|
|||
R CMD build ${R_PACKAGE} |
|||
R CMD check --as-cran ${R_PACKAGE}_*gz |
|||
|
|||
} |
@ -0,0 +1,50 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/build-pkg.R |
|||
\name{build_pkg} |
|||
\alias{build_pkg} |
|||
\alias{get_build_status} |
|||
\alias{get_build_manifest} |
|||
\alias{start_build} |
|||
\title{Submits a build job for a package} |
|||
\usage{ |
|||
build_pkg(package = ".", note = "New build", tags = c("package", |
|||
"rstats"), read_access = NULL, write_access = NULL, execute = TRUE, |
|||
secrets = TRUE, browse = FALSE, username = sourcehut_user(), |
|||
pat = sourcehut_pat()) |
|||
|
|||
get_build_status(job_id, pat = sourcehut_pat()) |
|||
|
|||
get_build_manifest(job_id, pat = sourcehut_pat()) |
|||
|
|||
start_build(job_id, pat = sourcehut_pat()) |
|||
} |
|||
\arguments{ |
|||
\item{package}{path to package (assumes current directory)} |
|||
|
|||
\item{note}{human-friendly description of this build (markdown, optional)} |
|||
|
|||
\item{tags}{character vector of strings that identify this build and can be |
|||
used to navigate the dashboard. Each string must use only lowercase |
|||
alphanumeric characters, or any of "-_."} |
|||
|
|||
\item{read_access, write_access}{character vector of users that have read or write access to the job.} |
|||
|
|||
\item{execute}{start build immediately? (Default: \code{TRUE})} |
|||
|
|||
\item{secrets}{provide secrets to the build? (Default: \code{TRUE})} |
|||
|
|||
\item{browse}{open browser to the builder URL? (Default: \code{FALSE})} |
|||
|
|||
\item{username}{see \code{\link[=sourcehut_user]{sourcehut_user()}}} |
|||
|
|||
\item{pat}{see \code{\link[=sourcehut_pat]{sourcehut_pat()}}} |
|||
|
|||
\item{job_id}{\code{builds.sr.ht} job id} |
|||
} |
|||
\description{ |
|||
This function assumes you know what you're doing and expects a valid |
|||
\code{.build.yml} in the \code{package} directory. |
|||
} |
|||
\references{ |
|||
\url{https://man.sr.ht/builds.sr.ht/api.md} |
|||
} |
Loading…
Reference in new issue