Skip to content

Commit 7d469c5

Browse files
authored
Merge pull request #320 from vimc/mrc-3665
mrc-3665 way for orderly web to control demo data
2 parents ef814a1 + ea8e611 commit 7d469c5

File tree

8 files changed

+62
-37
lines changed

8 files changed

+62
-37
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ tests/testthat/montagu-reports
1313
tests/testthat/reference/*.zip
1414
orderly_*.tar.gz
1515
tests/testthat/tmp
16+
/doc/
17+
/Meta/
18+
.idea

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: orderly
22
Title: Lightweight Reproducible Reporting
3-
Version: 1.4.10
3+
Version: 1.5.0
44
Description: Order, create and store reports from R. By defining a
55
lightweight interface around the inputs and outputs of an
66
analysis, a lot of the repetitive work for reproducible research
@@ -46,7 +46,7 @@ Suggests:
4646
rmarkdown,
4747
testthat,
4848
vaultr (>= 1.0.4)
49-
RoxygenNote: 7.1.2
49+
RoxygenNote: 7.2.0
5050
Roxygen: list(markdown = TRUE)
5151
VignetteBuilder: knitr
5252
Language: en-GB

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# orderly 1.5.0
2+
3+
* Add `prepare_git_example_from_source` which can be used to generate a git controlled orderly directory
4+
from a source, and another entrypoint `run_orderly_demo` that exposes this function, for use in testing OrderlyWeb (mrc-3665)
5+
16
# orderly 1.4.7
27

38
* Add `orderly_cancel_remote` which can be used to cancel one or more reports running on a remote via its key (mrc-3167)

R/testing.R

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ create_orderly_demo <- function(path = tempfile(), quiet = FALSE,
5151
}
5252

5353

54+
prepare_git_example_from_source <- function(source_path, path) {
55+
temp <- file.path(tempfile(), "demo")
56+
fs::dir_copy(source_path, temp)
57+
generate_source_db(temp)
58+
run_orderly_demo(temp)
59+
build_git_demo(temp)
60+
res <- prepare_orderly_git_example(path, run_report = FALSE)
61+
options(orderly.server.demo = NULL)
62+
unlink(temp, recursive = TRUE)
63+
res
64+
}
65+
66+
5467
run_orderly_demo <- function(path, quiet = FALSE) {
5568
if (quiet) {
5669
oo <- options(orderly.nolog = TRUE)
@@ -79,6 +92,7 @@ run_orderly_demo <- function(path, quiet = FALSE) {
7992
path
8093
}
8194

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

132+
generate_source_db(path)
133+
134+
if (git) {
135+
prepare_basic_git(path, quiet = TRUE)
136+
}
137+
138+
path
139+
}
140+
141+
142+
generate_source_db <- function(path) {
118143
if (file.exists(file.path(path, "source.R"))) {
119144
generator <- source(file.path(path, "source.R"), local = TRUE)$value
120145
} else {
@@ -125,12 +150,6 @@ prepare_orderly_example <- function(name, path = tempfile(), testing = FALSE,
125150
if (length(con) > 0L) {
126151
generator(con)
127152
}
128-
129-
if (git) {
130-
prepare_basic_git(path, quiet = TRUE)
131-
}
132-
133-
path
134153
}
135154

136155

@@ -196,8 +215,10 @@ demo_change_time <- function(id, time, path) {
196215
## extendable...
197216
##
198217
## After building this we have two branches 'master' with
199-
build_git_demo <- function() {
200-
path <- prepare_orderly_example("demo", file.path(tempfile(), "demo"))
218+
build_git_demo <- function(path = NULL) {
219+
if (is.null(path)) {
220+
path <- prepare_orderly_example("demo", file.path(tempfile(), "demo"))
221+
}
201222
dir.create(file.path(path, "extra"))
202223
move <- setdiff(dir(file.path(path, "src"), pattern = "^[^.]+$"),
203224
c("minimal", "global"))

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ COPY . /orderly
5353
RUN R CMD INSTALL /orderly && \
5454
Rscript -e 'orderly:::write_script("/usr/bin")' && \
5555
cp /orderly/inst/create_orderly_demo.sh /usr/bin/ && \
56+
cp /orderly/inst/run_orderly_demo /usr/bin/ && \
5657
rm -rf /orderly
5758

5859
ENTRYPOINT ["/usr/bin/orderly"]

docker/teamcity-demo.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

inst/run_orderly_demo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -ex
3+
if [ "$#" -ne 2 ]; then
4+
echo "Expected two arguments (source_path, dest_path)"
5+
exit 1
6+
fi
7+
SRC=$1
8+
DEST=$2
9+
Rscript -e "orderly:::prepare_git_example_from_source(\"$SRC\", \"$DEST\")"

tests/testthat/test-testing.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,16 @@ test_that("create_orderly_demo can create a git repo", {
1616
expect_true(file.exists(file.path(path, ".git")))
1717
expect_true(same_path(gert::git_pull(repo = path), path))
1818
})
19+
20+
21+
test_that("can create an orderly git repo from given source", {
22+
skip_on_cran()
23+
path <- tempfile()
24+
dir.create(path)
25+
on.exit(unlink(path, recursive = TRUE))
26+
source <- system.file("examples/demo", package = "orderly")
27+
prepare_git_example_from_source(source, path)
28+
expect_true(file.exists(file.path(path, ".git")))
29+
expect_true(dir.exists(file.path(path, "archive")))
30+
expect_true(same_path(gert::git_pull(repo = path), path))
31+
})

0 commit comments

Comments
 (0)