Skip to content

Commit

Permalink
Merge pull request #320 from vimc/mrc-3665
Browse files Browse the repository at this point in the history
mrc-3665 way for orderly web to control demo data
  • Loading branch information
hillalex authored Oct 26, 2022
2 parents ef814a1 + ea8e611 commit 7d469c5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ tests/testthat/montagu-reports
tests/testthat/reference/*.zip
orderly_*.tar.gz
tests/testthat/tmp
/doc/
/Meta/
.idea
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orderly
Title: Lightweight Reproducible Reporting
Version: 1.4.10
Version: 1.5.0
Description: Order, create and store reports from R. By defining a
lightweight interface around the inputs and outputs of an
analysis, a lot of the repetitive work for reproducible research
Expand Down Expand Up @@ -46,7 +46,7 @@ Suggests:
rmarkdown,
testthat,
vaultr (>= 1.0.4)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Language: en-GB
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# orderly 1.5.0

* Add `prepare_git_example_from_source` which can be used to generate a git controlled orderly directory
from a source, and another entrypoint `run_orderly_demo` that exposes this function, for use in testing OrderlyWeb (mrc-3665)

# orderly 1.4.7

* Add `orderly_cancel_remote` which can be used to cancel one or more reports running on a remote via its key (mrc-3167)
Expand Down
37 changes: 29 additions & 8 deletions R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ create_orderly_demo <- function(path = tempfile(), quiet = FALSE,
}


prepare_git_example_from_source <- function(source_path, path) {
temp <- file.path(tempfile(), "demo")
fs::dir_copy(source_path, temp)
generate_source_db(temp)
run_orderly_demo(temp)
build_git_demo(temp)
res <- prepare_orderly_git_example(path, run_report = FALSE)
options(orderly.server.demo = NULL)
unlink(temp, recursive = TRUE)
res
}


run_orderly_demo <- function(path, quiet = FALSE) {
if (quiet) {
oo <- options(orderly.nolog = TRUE)
Expand Down Expand Up @@ -79,6 +92,7 @@ run_orderly_demo <- function(path, quiet = FALSE) {
path
}


## This is a really rubbish set of test data. It requires an open
## "source" database and will write out two tables. This is used by
## the examples.
Expand Down Expand Up @@ -115,6 +129,17 @@ prepare_orderly_example <- function(name, path = tempfile(), testing = FALSE,
src_files <- dir(src, full.names = TRUE)
file_copy(src_files, path, overwrite = TRUE, recursive = TRUE)

generate_source_db(path)

if (git) {
prepare_basic_git(path, quiet = TRUE)
}

path
}


generate_source_db <- function(path) {
if (file.exists(file.path(path, "source.R"))) {
generator <- source(file.path(path, "source.R"), local = TRUE)$value
} else {
Expand All @@ -125,12 +150,6 @@ prepare_orderly_example <- function(name, path = tempfile(), testing = FALSE,
if (length(con) > 0L) {
generator(con)
}

if (git) {
prepare_basic_git(path, quiet = TRUE)
}

path
}


Expand Down Expand Up @@ -196,8 +215,10 @@ demo_change_time <- function(id, time, path) {
## extendable...
##
## After building this we have two branches 'master' with
build_git_demo <- function() {
path <- prepare_orderly_example("demo", file.path(tempfile(), "demo"))
build_git_demo <- function(path = NULL) {
if (is.null(path)) {
path <- prepare_orderly_example("demo", file.path(tempfile(), "demo"))
}
dir.create(file.path(path, "extra"))
move <- setdiff(dir(file.path(path, "src"), pattern = "^[^.]+$"),
c("minimal", "global"))
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ COPY . /orderly
RUN R CMD INSTALL /orderly && \
Rscript -e 'orderly:::write_script("/usr/bin")' && \
cp /orderly/inst/create_orderly_demo.sh /usr/bin/ && \
cp /orderly/inst/run_orderly_demo /usr/bin/ && \
rm -rf /orderly

ENTRYPOINT ["/usr/bin/orderly"]
27 changes: 0 additions & 27 deletions docker/teamcity-demo.sh

This file was deleted.

9 changes: 9 additions & 0 deletions inst/run_orderly_demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -ex
if [ "$#" -ne 2 ]; then
echo "Expected two arguments (source_path, dest_path)"
exit 1
fi
SRC=$1
DEST=$2
Rscript -e "orderly:::prepare_git_example_from_source(\"$SRC\", \"$DEST\")"
13 changes: 13 additions & 0 deletions tests/testthat/test-testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ test_that("create_orderly_demo can create a git repo", {
expect_true(file.exists(file.path(path, ".git")))
expect_true(same_path(gert::git_pull(repo = path), path))
})


test_that("can create an orderly git repo from given source", {
skip_on_cran()
path <- tempfile()
dir.create(path)
on.exit(unlink(path, recursive = TRUE))
source <- system.file("examples/demo", package = "orderly")
prepare_git_example_from_source(source, path)
expect_true(file.exists(file.path(path, ".git")))
expect_true(dir.exists(file.path(path, "archive")))
expect_true(same_path(gert::git_pull(repo = path), path))
})

0 comments on commit 7d469c5

Please sign in to comment.