From 06c912107d5e9605cbb3578ceb1782eee89df832 Mon Sep 17 00:00:00 2001 From: harupy Date: Mon, 20 Dec 2021 11:05:57 +0900 Subject: [PATCH 1/4] Dockerize R package build Signed-off-by: harupy --- .github/workflows/master.yml | 4 ++++ mlflow/R/mlflow/.Rbuildignore | 4 ++++ mlflow/R/mlflow/.build-package.R | 16 ++++++++++++++++ mlflow/R/mlflow/.gitignore | 1 + mlflow/R/mlflow/.run-tests.R | 25 ++++++++----------------- mlflow/R/mlflow/.utils.R | 18 ++++++++++++++++++ mlflow/R/mlflow/Dockerfile.build | 5 +++++ mlflow/R/mlflow/build-package.sh | 5 +++++ 8 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 mlflow/R/mlflow/.build-package.R create mode 100644 mlflow/R/mlflow/.utils.R create mode 100644 mlflow/R/mlflow/Dockerfile.build create mode 100755 mlflow/R/mlflow/build-package.sh diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 0d86bc963a674..b62dcbff32229 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -137,6 +137,10 @@ jobs: Rscript -e 'covr::codecov()' || : env: COVR_RUNNING: true + - name: Test package build + working-directory: mlflow/R/mlflow + run: | + ./build-package.sh - name: Show 00check.log on failure if: ${{ failure() }} run: | diff --git a/mlflow/R/mlflow/.Rbuildignore b/mlflow/R/mlflow/.Rbuildignore index 02cd4160f1e96..553d22ffd68cf 100644 --- a/mlflow/R/mlflow/.Rbuildignore +++ b/mlflow/R/mlflow/.Rbuildignore @@ -19,3 +19,7 @@ Reference_Manual_mlflow.md ^logs/ ^depends\.Rds ^R-version +^\.utils\.R$ +^\.build-package\.R$ +^build-package\.sh$ +^Dockerfile\.build$ diff --git a/mlflow/R/mlflow/.build-package.R b/mlflow/R/mlflow/.build-package.R new file mode 100644 index 0000000000000..7c9a58db65480 --- /dev/null +++ b/mlflow/R/mlflow/.build-package.R @@ -0,0 +1,16 @@ +source(".utils.R") + +# Increase the timeout length for `utils::download.file` because the default value (60 seconds) +# could be too short to download large packages such as h2o. +options(timeout=300) +# Install dependencies required for the submission check. +devtools::install_deps(".", dependencies = TRUE) +# Bundle up the package into a .tar.gz file. This file will be submitted to CRAN. +package_path <- devtools::build(".") +# Run the submission check against the built package. +devtools::check_built( + package_path, + remote = should_enable_cran_incoming_checks(), + error_on = "note", + args = c("--no-tests", "--as-cran"), +) diff --git a/mlflow/R/mlflow/.gitignore b/mlflow/R/mlflow/.gitignore index 324bc7c23a210..b4e671316b953 100644 --- a/mlflow/R/mlflow/.gitignore +++ b/mlflow/R/mlflow/.gitignore @@ -19,3 +19,4 @@ Reference_Manual_mlflow.md *.Rcheck/ depends.Rds R-version +*.tar.gz diff --git a/mlflow/R/mlflow/.run-tests.R b/mlflow/R/mlflow/.run-tests.R index 5bdfb0a1bfb00..61ff4aa2f99c0 100644 --- a/mlflow/R/mlflow/.run-tests.R +++ b/mlflow/R/mlflow/.run-tests.R @@ -1,24 +1,15 @@ +source("../utils.R") + parent_dir <- dir("../", full.names = TRUE) package <- parent_dir[grepl("mlflow_", parent_dir)] library(reticulate) use_condaenv(mlflow:::mlflow_conda_env_name()) -# Disable CRAN incoming feasibility check within a week after the latest release because it fails. -# -# Relevant code: -# https://github.com/wch/r-source/blob/4561aea946a75425ddcc8869cdb129ed5e27af97/src/library/tools/R/QC.R#L8005-L8008 -install.packages(c("xml2", "rvest")) -library(xml2) -library(rvest) - -url <- "https://cran.r-project.org/web/packages/mlflow/index.html" -html <- read_html(url) -xpath <- '//td[text()="Published:"]/following-sibling::td[1]/text()' -published_date <- as.Date(html_text(html_nodes(html, xpath=xpath))) -today <- Sys.Date() -days_since_last_release <- difftime(today, published_date, units="days") -remote <- as.numeric(days_since_last_release) > 7 - -devtools::check_built(path = package, remote = remote, error_on = "note", args = "--no-tests") +devtools::check_built( + path = package, + remote = should_enable_cran_incoming_checks(), + error_on = "note", + args = "--no-tests" +) source("testthat.R") diff --git a/mlflow/R/mlflow/.utils.R b/mlflow/R/mlflow/.utils.R new file mode 100644 index 0000000000000..45f845c089512 --- /dev/null +++ b/mlflow/R/mlflow/.utils.R @@ -0,0 +1,18 @@ + +# This script defines utility functions only used during development. + +should_enable_cran_incoming_checks <- function() { + # The CRAN incoming feasibility check performs a package recency check (this is undocumented) + # that examines the number of days since the last release and raises a NOTE if it's < 7. + # Relevant code: + # https://github.com/wch/r-source/blob/4561aea946a75425ddcc8869cdb129ed5e27af97/src/library/tools/R/QC.R#L8005-L8008 + # This check needs to be disabled for a week after releasing a new version. + desc_url <- url("https://cran.r-project.org/web/packages/mlflow/DESCRIPTION") + field <- "Date/Publication" + desc <- read.dcf(desc_url, fields = c(field)) + close(desc_url) + publication_date <- as.Date(unname(desc[1, field])) + today <- Sys.Date() + days_since_last_release <- as.numeric(difftime(today, publication_date, units="days")) + days_since_last_release > 7 +} diff --git a/mlflow/R/mlflow/Dockerfile.build b/mlflow/R/mlflow/Dockerfile.build new file mode 100644 index 0000000000000..a4b9f80f3c0de --- /dev/null +++ b/mlflow/R/mlflow/Dockerfile.build @@ -0,0 +1,5 @@ +FROM rocker/r-ver:4.1.2 + +RUN apt-get update -y +RUN apt-get install pandoc -y +RUN Rscript -e 'install.packages("devtools", dependencies = TRUE)' diff --git a/mlflow/R/mlflow/build-package.sh b/mlflow/R/mlflow/build-package.sh new file mode 100755 index 0000000000000..74d0188160ad6 --- /dev/null +++ b/mlflow/R/mlflow/build-package.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -ex + +docker build -f Dockerfile.build -t r-build-package . +docker run --rm --workdir /app -v $(pwd):/app r-build-package Rscript -e 'source(".build-package.R", echo = TRUE)' From e4d57b101e7ca359a704b79cec67317807a848c5 Mon Sep 17 00:00:00 2001 From: harupy Date: Mon, 20 Dec 2021 11:15:03 +0900 Subject: [PATCH 2/4] fix path Signed-off-by: harupy --- mlflow/R/mlflow/.run-tests.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlflow/R/mlflow/.run-tests.R b/mlflow/R/mlflow/.run-tests.R index 61ff4aa2f99c0..1ee27f28927d0 100644 --- a/mlflow/R/mlflow/.run-tests.R +++ b/mlflow/R/mlflow/.run-tests.R @@ -1,4 +1,4 @@ -source("../utils.R") +source("../.utils.R") parent_dir <- dir("../", full.names = TRUE) package <- parent_dir[grepl("mlflow_", parent_dir)] From 35b3bc7ee2ac23e37cee51b40e4c8323365baddf Mon Sep 17 00:00:00 2001 From: harupy <17039389+harupy@users.noreply.github.com> Date: Mon, 20 Dec 2021 14:16:25 +0900 Subject: [PATCH 3/4] specify path Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> --- mlflow/R/mlflow/.build-package.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlflow/R/mlflow/.build-package.R b/mlflow/R/mlflow/.build-package.R index 7c9a58db65480..898d1451e2b3d 100644 --- a/mlflow/R/mlflow/.build-package.R +++ b/mlflow/R/mlflow/.build-package.R @@ -6,10 +6,10 @@ options(timeout=300) # Install dependencies required for the submission check. devtools::install_deps(".", dependencies = TRUE) # Bundle up the package into a .tar.gz file. This file will be submitted to CRAN. -package_path <- devtools::build(".") +package_path <- devtools::build(".", path = ".") # Run the submission check against the built package. devtools::check_built( - package_path, + pkg = normalizePath(package_path), remote = should_enable_cran_incoming_checks(), error_on = "note", args = c("--no-tests", "--as-cran"), From f4f8830e7ebec83190c3efa9ce59ffb89d55f852 Mon Sep 17 00:00:00 2001 From: harupy <17039389+harupy@users.noreply.github.com> Date: Mon, 20 Dec 2021 14:37:07 +0900 Subject: [PATCH 4/4] fix argument name Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> --- mlflow/R/mlflow/.build-package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlflow/R/mlflow/.build-package.R b/mlflow/R/mlflow/.build-package.R index 898d1451e2b3d..e4945a29a5ecf 100644 --- a/mlflow/R/mlflow/.build-package.R +++ b/mlflow/R/mlflow/.build-package.R @@ -9,7 +9,7 @@ devtools::install_deps(".", dependencies = TRUE) package_path <- devtools::build(".", path = ".") # Run the submission check against the built package. devtools::check_built( - pkg = normalizePath(package_path), + path = normalizePath(package_path), remote = should_enable_cran_incoming_checks(), error_on = "note", args = c("--no-tests", "--as-cran"),