Created
August 2, 2019 18:39
-
-
Save gshotwell/ee574811072ce5cf0c85282c572c9104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
releasePackages <- function() { | |
dir.create("builds") | |
on.exit(unlink("builds", recursive = TRUE)) | |
if (repository_head()$name != "master") { | |
stop("You can only release the master branch. Merge your changes into master before releasing.") | |
} | |
repo <- gitPath("repo") | |
released <- readRDS(file.path(repo, "src", "contrib", "PACKAGES.rds")) | |
released <- data.frame(released, stringsAsFactors = FALSE) | |
files <- list.files() | |
pkgs <- lapply(files, function(x){ | |
if (file.exists(file.path(x, "DESCRIPTION"))) { | |
return(x) | |
} | |
}) %>% | |
unlist() | |
lapply( pkgs, function(x) { | |
# Get package versions | |
desc <- readLines(file.path(x, "DESCRIPTION")) | |
package <- desc[grepl("^Package:", desc)] %>% | |
str_extract("(: ).*$") %>% | |
str_replace("^: ", "") | |
version <- desc[grepl("^Version:", desc)] %>% | |
str_extract("(: ).*$") %>% | |
str_replace("^: ", "") | |
if (released$Version[released$Package == package] >= version) { | |
warning("Skipping ", package, " ", version, " because it's already been released. Did you forget to bump the version?") | |
} else { | |
message("Testing", x) | |
Sys.setenv(INTEGRATION = TRUE) | |
devtools::test(x, stop_on_failure = TRUE) | |
message("Building", x) | |
build(x, path = "builds") | |
build(x, path = "builds", binary = TRUE) | |
Sys.setenv(INTEGRATION = FALSE) | |
} | |
} | |
) | |
repo <- repository(gitPath("repo")) | |
checkout(repo, "add_packages", create = TRUE) | |
builds <- list.files("builds", full.names = TRUE) | |
if (length(builds) == 0) { | |
stop("No builds to release.") | |
} | |
lapply(builds, function(x){ | |
drat::insertPackage(x, repo) | |
}) | |
files <- status(repo) | |
add(repo, unlist(c(files$unstaged, files$untracked))) | |
commit(repo, "update packages") | |
unlink("builds", recursive = TRUE) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment