Skip to content

Commit

Permalink
feat: Automatically merge news from dev versions before release (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Oct 20, 2023
2 parents 1945d79 + 30df397 commit d2dbd8f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
45 changes: 37 additions & 8 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,25 @@ pre_release_impl <- function(which, force) {

cli_h1("1. Creating a release branch and getting ready")

fledgeling <- read_fledgling()

# bump version on main branch to version set by user
# Avoid `bump_version()` to avoid showing `NEWS.md` at this stage,
# because it changes as we jump between branches.
update_news(which = which)
commit_version()

# FIXME: This will be obsolete later
fledgeling <- read_fledgling()
new_version <- fledge_guess_version(fledgeling[["version"]], which)

# switch to release branch and update cran-comments
release_branch <- create_release_branch(fledgeling$version, force)
release_branch <- create_release_branch(new_version, force)
switch_branch(release_branch)

fledgeling <- merge_dev_news(fledgeling, new_version)
write_fledgling(fledgeling)
gert::git_add(files = c("NEWS.md"))
gert::git_commit(message = "Update NEWS")

update_cran_comments()

# push main branch, bump to devel version and push again
Expand Down Expand Up @@ -145,6 +152,33 @@ get_remote_name <- function(branch = get_main_branch()) {
remote
}

merge_dev_news <- function(fledgeling, new_version) {
dev_idx <- grepl("^[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+$", fledgeling$news$version)
stopifnot(dev_idx[[1]])

n_dev <- rle(dev_idx)$lengths[[1]]

news <- regroup_news(unlist(fledgeling$news$news[seq_len(n_dev)], recursive = FALSE))

new_section <- tibble::tibble(
start = 3,
end = NA,
h2 = any(fledgeling[["news"]][["h2"]][seq_len(n_dev)]),
version = new_version,
date = maybe_date(fledgeling[["news"]]),
nickname = NA,
news = list(news),
raw = "",
title = "",
section_state = "new"
)

fledgeling$version <- as.package_version(new_version)
fledgeling$news <- vctrs::vec_rbind(new_section, fledgeling$news[-seq_len(n_dev), ])

fledgeling
}

create_release_branch <- function(version, force, ref = "HEAD") {
branch_name <- paste0("cran-", version)

Expand Down Expand Up @@ -310,11 +344,6 @@ release_impl <- function() {
}

is_news_consistent <- function() {
# FIXME: For tests, no longer needed after #658
if (nzchar(Sys.getenv("FLEDGE_DONT_BOTHER_CRAN_THIS_IS_A_TEST"))) {
return(TRUE)
}

headers <- with_repo(get_news_headers())

# One entry is fine, zero entries are an error
Expand Down
2 changes: 2 additions & 0 deletions R/fledgling.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ trim_empty_lines <- function(x) {
}

write_fledgling <- function(fledgeling) {
force(fledgeling)

# store version
desc::desc_set_version(
fledgeling$version,
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/auto/NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- NEWS.md is maintained by https://fledge.cynkra.com, contributors should not edit this file -->

# tea 2.0.0

- Add cool blop.
- Add cool bla.
- Added a `NEWS.md` file to track changes to the package.

23 changes: 23 additions & 0 deletions tests/testthat/test-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ test_that("guess_next_impl() works", {
})
})

test_that("merge_dev_news() works", {
skip_if_not_installed("rlang", "1.0.1")

local_options("fledge.quiet" = TRUE)
local_options(repos = NULL) # because of usethis::use_news_md() -> available.packages()
local_demo_project(quiet = TRUE)

use_r("bla")
gert::git_add("R/bla.R")
gert::git_commit("* Add cool bla.")
shut_up_fledge(bump_version())

use_r("blop")
gert::git_add("R/blop.R")
gert::git_commit("* Add cool blop.")
shut_up_fledge(bump_version())

fledgeling <- read_fledgling()
fledgeling <- merge_dev_news(fledgeling, "2.0.0")
write_fledgling(fledgeling)
expect_snapshot_file("NEWS.md")
})

test_that("create_release_branch() works", {
local_demo_project()
gert::git_branch_create("bla")
Expand Down

0 comments on commit d2dbd8f

Please sign in to comment.