Skip to content

Commit 9dc7269

Browse files
authored
Merge pull request #10 from ThinkR-open/cran-release
Cran release
2 parents 90ae24d + 5d597d4 commit 9dc7269

File tree

9 files changed

+128
-20
lines changed

9 files changed

+128
-20
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
^data-raw$
1313
^gitdown$
1414
^\.github$
15+
^cran-comments\.md$
16+
^CRAN-RELEASE$

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
matrix:
2424
config:
2525
- {os: windows-latest, r: 'release'}
26+
- {os: windows-latest, r: 'devel'}
2627
- {os: macOS-latest, r: 'release'}
2728
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
2829
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ inst/doc
55
testbook
66
docs/
77
gitdown
8+
cran-comments.md
9+
CRAN-RELEASE

R/utils.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ write_in <- function(x, repo, dir = "gitdown", rmd = "index.Rmd") {
2121
dir_out <- normalizePath(file.path(repo, dir))
2222
if (!dir.exists(dir_out)) {dir.create(dir_out)}
2323
there <- file.path(dir_out, rmd)
24-
write(x, file = there, append = TRUE)
24+
write(enc2utf8(x), file = there, append = TRUE)
2525
}
2626

2727
#' Presentation of commit
@@ -39,11 +39,11 @@ presentation_commit <- function(commit) {
3939
paste("- Date:", commit$when),
4040
"\n",
4141
paste("- Message content:"),
42-
"\n",
42+
"\n\n",
4343
"```",
4444
"\n",
4545
paste(commit$message),
46-
"\n",
46+
"\n\n",
4747
"```",
4848
"\n",
4949
paste("- Related patterns:\n"),

dev_history.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ usethis::use_github_action("test-coverage")
6868
rcmdcheck::rcmdcheck(args = "--as-cran")
6969
spelling::spell_check_package()
7070
rhub::check_for_cran()
71-
rhub::check_on_windows()
71+
rhub::check_on_windows(check_args = "--force-multiarch")
7272
rhub::check_on_fedora()
7373
devtools::check_win_devel()
74+
devtools::check_win_release()
75+
76+
usethis::use_cran_badge()
77+
usethis::use_cran_comments()
78+
usethis::use_git_ignore("cran-comments.md")
79+
usethis::use_git_ignore("CRAN-RELEASE")
80+
7481
devtools::release()

inst/booktemplate/_output.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bookdown::gitbook:
22
css: style.css
3+
split_by: chapter
34
config:
45
toc:
56
before: |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Author: Alice ; E-mail: [email protected]
55
- Date: 2020-08-05 10:25:29
66
- Message content:
7+
78
```
89
Add NEWS
910
@@ -12,6 +13,7 @@ issue #1.
1213
ticket6789.
1314
ticket1234
1415
Creation of the NEWS file for version 0.1.
16+
1517
```
1618
- Related patterns:
1719
+ Issues: [#32](#issues-32), [#1](#issues-1), [#12](#issues-12)

tests/testthat/test-git_down.R

Lines changed: 106 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
library(withr)
22

3+
# debug if problems with CRAN to retrieve outputs
4+
debug <- FALSE
5+
36
repo_input <- tempfile(pattern = "git2r-")
47
repo <- fake_repo(repo_input)
58

@@ -13,13 +16,26 @@ with_dir(repo, {
1316
lines <- readLines(file.path(dirname(res), "section-issue.html"))
1417
one_line_exists <- grep('<h2><span class="header-section-number">1.2</span> Issue: #1</h2>',
1518
lines, fixed = TRUE)
19+
sub_commit_1 <- grep('<h3><span class="header-section-number">1.2.1</span> commit: example: modification</h3>',
20+
lines, fixed = TRUE)
21+
sub_commit_2 <- grep('<h3><span class="header-section-number">1.2.2</span> commit: Add NEWS</h3>',
22+
lines, fixed = TRUE)
1623

1724
test_that("git_down function",{
1825
expect_match(res, regexp = ".html")
1926
expect_true(file.exists(file.path(dirname(res), "section-issue.html")))
20-
expect_true(length(one_line_exists) == 1)
27+
expect_length(one_line_exists, 1)
28+
expect_length(sub_commit_1, 1)
29+
expect_length(sub_commit_2, 1)
2130
})
2231

32+
# clean dir
33+
if (debug) {
34+
dir.create("res_one")
35+
file.copy(dirname(res), "res_one", recursive = TRUE, overwrite = TRUE)
36+
}
37+
unlink(dirname(res), recursive = TRUE)
38+
2339
# Pattern without name and special characters cleaned
2440
with_dir(repo, {
2541
res <- git_down(author = "StatnMap",
@@ -38,30 +54,99 @@ test_that("git_down no name function",{
3854
expect_true(length(one_line_exists) == 1)
3955
})
4056

57+
# clean dir
58+
if (debug) {
59+
dir.create("res_two")
60+
file.copy(dirname(res), "res_two", recursive = TRUE, overwrite = TRUE)
61+
}
62+
unlink(dirname(res), recursive = TRUE)
63+
4164
# With multiple patterns ----
4265

4366
with_dir(repo, {
67+
4468
res <- git_down(author = "Seb",
4569
pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"),
4670
open = FALSE
4771
)
48-
res <- normalizePath(res)
72+
73+
74+
# For Debugging with CRAN ----
75+
if (debug) {
76+
res_files <- paste(list.files(dirname(res)), collapse = ", ")
77+
78+
# repo <- "."
79+
80+
res_commits <- nest_commits_by_pattern(
81+
repo,
82+
pattern = c("Issues" = "#[[:digit:]]+", "Tickets" = "ticket[[:digit:]]+"),
83+
silent = TRUE
84+
)
85+
86+
res_pattern <- purrr::map_dfr(
87+
names(c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+")),
88+
~each_pattern(res_commits, pattern.type = .x))
89+
90+
res_content <- paste(c(paste0("# Gitbook for ", "toto", "{-} \n"),
91+
paste0("Done on: ", Sys.time(), "\n"), "\n", unlist(res_pattern$text)),
92+
collapse = "\n\n")
93+
94+
dir.create(normalizePath(file.path(repo, "gitdown-cran"), mustWork = FALSE), recursive = TRUE)
95+
file.copy(from = list.files(system.file("booktemplate", package = "gitdown"), full.names = TRUE),
96+
to = normalizePath(file.path(repo, "gitdown-cran")), overwrite = TRUE)
97+
98+
gitdown:::write_in(x = res_content, repo = repo, dir = "gitdown-cran", rmd = "index.Rmd")
99+
res_render <- rmarkdown::render(file.path(repo, "gitdown-cran", "index.Rmd"))
100+
}
49101
})
50-
lines <- readLines(file.path(dirname(res), "section-issues.html"))
51-
one_line_exists <- grep('<h2><span class="header-section-number">2.2</span> Issue: #1</h2>',
52-
lines, fixed = TRUE)
53-
lines <- readLines(file.path(dirname(res), "section-tickets.html"))
54-
one_line_ticket_exists <- grep('<h2><span class="header-section-number">1.2</span> Ticket: ticket1234</h2>',
55-
lines, fixed = TRUE)
102+
103+
# For Debugging with CRAN ----
104+
if (debug) {
105+
dput(res_commits, file = "res_commits.txt")
106+
dput(res_files, file = "res_files.txt")
107+
dput(res_pattern, file = "res_pattern.txt")
108+
dput(res_content, file = "res_content.txt")
109+
file.copy(file.path(repo, "gitdown", 'index.Rmd'), "res_index.txt", overwrite = TRUE)
110+
file.copy(file.path(repo, "gitdown-cran", 'index.Rmd'), "res_index_cran.txt", overwrite = TRUE)
111+
file.copy(file.path(repo, "gitdown", '_bookdown.yml'), "res_bookdown.txt", overwrite = TRUE)
112+
file.copy(file.path(repo, "gitdown", '_output.yml'), "res_output.txt", overwrite = TRUE)
113+
114+
115+
dir.create("res_three")
116+
file.copy(dirname(res), "res_three", recursive = TRUE, overwrite = TRUE)
117+
}
56118

57119
test_that("git_down multiple pattern works", {
58120
expect_match(res, regexp = ".html")
59-
expect_true(file.exists(file.path(dirname(res), "section-issues.html")))
60-
expect_true(file.exists(file.path(dirname(res), "section-tickets.html")))
61-
expect_true(length(one_line_exists) == 1)
121+
122+
issues_file <- normalizePath(file.path(dirname(res), "section-issues.html"))
123+
tickets_file <- normalizePath(file.path(dirname(res), "section-tickets.html"))
124+
125+
# For Debugging with CRAN ----
126+
if (debug) {
127+
dput(dirname(res), file = "res_dirname.txt")
128+
dput(issues_file, file = "res_issues_file.txt")
129+
dput(tickets_file, file = "res_tickets_file.txt")
130+
}
131+
132+
expect_true(file.exists(issues_file))
133+
expect_true(file.exists(tickets_file))
134+
135+
lines <- readLines(tickets_file)
136+
one_line_ticket_exists <- grep('<h2><span class="header-section-number">1.2</span> Ticket: ticket1234</h2>',
137+
lines, fixed = TRUE)
138+
62139
expect_true(length(one_line_ticket_exists) == 1)
140+
141+
lines <- readLines(issues_file)
142+
one_line_exists <- grep('<h2><span class="header-section-number">2.2</span> Issue: #1</h2>',
143+
lines, fixed = TRUE)
144+
expect_true(length(one_line_exists) == 1)
63145
})
64146

147+
# clean dir
148+
unlink(dirname(res), recursive = TRUE)
149+
65150
# With table of correspondence
66151
pattern.table <- data.frame(
67152
number = c("#2", "#1", "#1000"),
@@ -79,3 +164,13 @@ test_that("git_down with pattern table",{
79164
expect_match(res, regexp = ".html")
80165
})
81166
})
167+
168+
if (debug) {
169+
all_res_files <- list.files(pattern = '^res_', full.names = TRUE)
170+
dir.create("debug")
171+
file.copy(all_res_files, "debug", recursive = TRUE)
172+
unlink(all_res_files, recursive = TRUE)
173+
}
174+
175+
# clean dir
176+
unlink(dirname(res), recursive = TRUE)

tests/testthat/test-utils.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
context("utils functions")
21
library(withr)
32

43
repo_input <- tempfile(pattern = "git2r-")
@@ -47,8 +46,6 @@ nest_out_pattern_table <- nest_commits_by_pattern(
4746
pattern.table = pattern.table,
4847
pattern = c("Tickets" = "ticket[[:digit:]]+", "Issues" = "#[[:digit:]]+"))
4948

50-
# writeLines(aa, "tests/testthat/presentation_commit")
51-
5249
test_that("nest_commits_by_pattern", {
5350
# One pattern
5451
expect_equal(
@@ -146,10 +143,11 @@ one_commit <- structure(
146143
)
147144

148145
prez_commit <- gitdown:::presentation_commit(one_commit)
149-
# writeLines(prez_commit, "tests/testthat/presentation_commit")
146+
# writeLines(prez_commit, "tests/testthat/presentation_commit.md")
147+
# paste(readLines("tests/testthat/presentation_commit.md"), collapse = "\n")
150148

151149
test_that("presentation_commit", {
152-
expect_equal(prez_commit, paste(readLines("presentation_commit"), collapse = "\n"))
150+
expect_equal(prez_commit, paste(readLines("presentation_commit.md"), collapse = "\n"))
153151
})
154152

155153
# clean_link ----

0 commit comments

Comments
 (0)