Skip to content

Commit

Permalink
feat: Support pre-patch version, new versioning scheme starting at 99…
Browse files Browse the repository at this point in the history
…00 (#794)
  • Loading branch information
aviator-app[bot] authored Nov 16, 2024
2 parents 199e10f + 5035ff8 commit 9398a55
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 24 deletions.
2 changes: 1 addition & 1 deletion R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ init_release <- function(which = "next", force = FALSE) {
check_only_modified(character())
check_gitignore("cran-comments.md")

stopifnot(which %in% c("next", "patch", "minor", "major"))
stopifnot(which %in% c("next", "patch", "minor", "major", "pre-patch", "pre-minor", "pre-major"))
if (which == "next") {
which <- guess_next()
}
Expand Down
35 changes: 18 additions & 17 deletions R/utils-parse-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,26 @@ fledge_guess_version <- function(version, which) {
major = major + 1,
major
)
} else if (which %in% c("pre-minor", "pre-major")) {
# pre-minor and pre-major

if (patch >= 99) {
cli::cli_abort("Can't bump to {.val {which}} from version {.val {version}} (patch >= 99).")
}

if (minor >= 99) {
cli::cli_abort("Can't bump to {.val {which}} from version {.val {version}} (minor >= 99).")
} else if (which == "pre-patch") {
dev <- max(dev + 1, 9900)
} else if (which == "pre-minor") {
if (patch > 99) {
cli::cli_abort("Can't bump to {.val {which}} from version {.val {version}} (patch > 99).")
} else if (patch == 99) {
dev <- max(dev + 1, 9900)
} else {
patch <- 99
dev <- 9900
}

dev <- "9000"
patch <- "99"
# pre-minor: make patch 99
# pre-major: make both minor and patch 99
if (which == "pre-major") {
minor <- "99"
} else if (which == "pre-major") {
if (minor > 99) {
cli::cli_abort("Can't bump to {.val {which}} from version {.val {version}} (minor > 99).")
} else if (minor == 99) {
dev <- max(dev + 1, 9900)
} else {
stopifnot(which == "pre-minor")
dev <- 9900
patch <- 99
minor <- 99
}
} else {
cli::cli_abort("Unknown version specifier {.val {which}}.")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/utils-parse-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
Code
fledge_guess_version("1.1.1", "pre-minor")
Output
[1] "1.1.99.9000"
[1] "1.1.99.9900"

---

Code
fledge_guess_version("1.1.1", "pre-major")
Output
[1] "1.99.99.9000"
[1] "1.99.99.9900"

---

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-auto-full-cycle-pre.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test_that("full cycle pre-minor", {

expect_equal(
as.character(desc::desc_get_version()),
"0.0.99.9000"
"0.0.99.9900"
)

## init release ----
Expand Down Expand Up @@ -61,6 +61,6 @@ test_that("full cycle pre-minor", {
expect_equal(nrow(gert::git_status()), 0)
expect_setequal(
gert::git_tag_list()[["name"]],
c("v0.0.99.9000", "v0.1.0")
c("v0.0.99.9900", "v0.1.0")
)
})
8 changes: 6 additions & 2 deletions tests/testthat/test-utils-parse-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ test_that("fledge_guess_version() works", {

expect_equal(fledge_guess_version("1.0.0", "dev"), "1.0.0.9000")
expect_equal(fledge_guess_version("1.0.0.9000", "dev"), "1.0.0.9001")
expect_equal(fledge_guess_version("1.0.0.9000", "pre-patch"), "1.0.0.9900")
expect_equal(fledge_guess_version("1.0.0.9900", "pre-patch"), "1.0.0.9901")
expect_equal(fledge_guess_version("1.0.0.9000", "patch"), "1.0.1")
expect_equal(fledge_guess_version("1.0.0.9001", "pre-minor"), "1.0.99.9000")
expect_equal(fledge_guess_version("1.0.0.9001", "pre-minor"), "1.0.99.9900")
expect_equal(fledge_guess_version("1.0.99.9900", "pre-minor"), "1.0.99.9901")
expect_equal(fledge_guess_version("1.0.0.9001", "minor"), "1.1.0")
expect_equal(fledge_guess_version("1.0.0.9001", "pre-major"), "1.99.99.9000")
expect_equal(fledge_guess_version("1.0.0.9001", "pre-major"), "1.99.99.9900")
expect_equal(fledge_guess_version("1.99.99.9900", "pre-major"), "1.99.99.9901")
expect_equal(fledge_guess_version("1.0.0.9001", "major"), "2.0.0")
})
56 changes: 56 additions & 0 deletions vignettes/auto.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: "Automate CRAN releases v2"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{cran-automation-2}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

## Goals, and how achieved

1. Avoid conflicts in `NEWS.md` and `DESCRIPTION`
- Bumping to CRAN version and back to dev version is atomic, no dangling release branch
- Support for subsequent release attempts off of a branch created from a tag

2. Easy to undo a release attempt
- Pre-flight with `init_release("pre-patch")`, including grooming of `NEWS.md`
- Caveat: once committed to a release, there is no way back, to avoid conflicts

3. More rigorous checks before release
- On GitHub Actions for branches that start with `cran-`
- Locally through `urlchecker::url_update()`, `devtools::check_win_devel()`, and `rhub::check_for_cran()`
- TODO: Compatibility with `usethis::use_release_issue()`

4. Minimize interactive wait time
- Checks run on GitHub Actions for branches that start with `cran-`
- TODO: Use background jobs via `job::empty()` where useful

5. Compatibility with auto-merge and merge queues
- GHA workflow

6. Support merge and squash commits
- We can always create a tag
- PR merge is triggered by user

7. Support for dev version header
- TODO: Composable workflow, grooming can be separate from release

8. Compatibility with manual release workflow
- `init_release("pre-patch")`

9. Consistency with `usethis::use_release_issue()`
- TODO: snapshot tests for `usethis:::release_checklist()`, maintain own list

## Non-goals

1. Always release from main branch
- Conflicts with important goal to avoid conflicts, and also with auto-merge and merge queues
- Release from main branch possible in some cases

0 comments on commit 9398a55

Please sign in to comment.