forked from hughjonesd/huxtable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-cran.R
executable file
·88 lines (59 loc) · 2.48 KB
/
build-cran.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/local/bin/Rscript
library(devtools)
library(git2r)
library(glue)
library(rhub)
library(rstudioapi)
# Check version number is up to date----------------------------------------------------------------
v <- devtools::as.package('.')$version
if (grepl(v, "9000")) stop('Still using development version. Use usethis::use_version()')
# Check git is up to date --------------------------------------------------------------------------
gdiff <- git2r::diff(repository())
if (length(gdiff) > 0) stop('Working tree differs from last commit, please make commits!')
# nb this may fail for some reason
# Check vignette files are same in vignettes and docs ----------------------------------------------
for (f in list.files('vignettes', pattern = "(Rmd|cvs)$")) {
out <- system2('diff', args = c('-q', file.path('vignettes', f), file.path('docs', f)), stdout = TRUE)
if (length(out) > 0) stop(glue('vignettes and docs file {f} differs, please fix!'))
}
# Run R CMD check ----------------------------------------------------------------------------------
# this automatically builds the package
chk <- devtools::check(
env_vars = c('RSTUDIO_PANDOC' = '/Applications/RStudio.app/Contents/MacOS/pandoc'),
document = FALSE,
remote = TRUE
)
if (length(chk$errors) > 0 || length(chk$warnings) > 0) {
cat('\n\nR CMD CHECK errors:\n')
cat(chk$errors)
cat('\n\nR CMD CHECK warnings:\n')
cat(chk$warnings)
stop('Not tagging built release.')
}
if (length(chk$notes)) {
cat('R CMD CHECK notes:\n')
cat(chk$notes)
cat('\nTag this version? y[n]')
yn <- if (interactive()) readline() else readLines(con="stdin", 1)
if (! yn %in% c('Y', 'y')) stop('OK, stopping.')
}
# Tag new version ----------------------------------------------------------------------------------
newtag <- paste0('v', v, '-rc')
tags <- tags()
tags <- grep(newtag, names(tags), fixed = TRUE, value = TRUE)
tags <- as.numeric(gsub(newtag, '', tags))
rc <- if (length(tags)) as.integer(max(tags) + 1) else 1L
newtag <- paste0(newtag, rc)
cat('\nTagging current version as: ', newtag, '\n')
tag(repository('.'), newtag, message = paste('CRAN release candidate for', v))
system2('git', c('push', '--tags'))
# Build package
devtools::build()
# run checks
rhc <- rhub::check_for_cran(show_status = FALSE)
devtools::check_win_devel()
devtools::check_win_release()
rstudioapi::jobRunScript("check-reverse-dependencies.R", exportEnv = "revdep_results")
# update CRAN-comments.md
# now release!
devtools::release()