Skip to content

Commit 30bc851

Browse files
authored
Updates for latest lifecycle workflow (#1349)
Fixes #1323
1 parent 23300fc commit 30bc851

File tree

9 files changed

+45
-58
lines changed

9 files changed

+45
-58
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# usethis (development version)
22

3+
* `use_lifecycle()` has been updated for changes in our lifecycle workflow
4+
(#1323).
5+
36
* `use_tidy_pkgdown()` has been renamed to `use_pkgdown_github_pages()` since
47
the function is useful for anyone who wants to automatically publish to GitHub
58
pages, not just the tidyverse team (#1308).
69

710
* All functions that require a package now ask you if you'd like to install it.
811

9-
`use_readme_rmd()`, `use_readme_md()`, `use_tidy_contributing()`, and `use_tidy_support()` use updated logic for determining the `OWNER/REPO` spec of the target repo (#1312).
12+
* `use_readme_rmd()`, `use_readme_md()`, `use_tidy_contributing()`, and `use_tidy_support()` use updated logic for determining the `OWNER/REPO` spec of the target repo (#1312).
1013

1114
# usethis 2.0.0
1215

R/badge.R

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,15 @@
1515
#' * `use_cran_badge()`: badge indicates what version of your package is
1616
#' available on CRAN, powered by <https://www.r-pkg.org>
1717
#' * `use_lifecycle_badge()`: badge declares the developmental stage of a
18-
#' package (or argument or function) according to
19-
#' <https://lifecycle.r-lib.org/articles/lifecycle.html>:
20-
#' - Experimental
21-
#' - Maturing
22-
#' - Stable
23-
#' - Questioning
24-
#' - Superseded
25-
#' - Soft-deprecated (function or argument)
26-
#' - Deprecated (function or argument)
27-
#' - Defunct (function or argument)
18+
#' package according to <https://lifecycle.r-lib.org/articles/stages.html>.
2819
#'
2920
#' * `use_binder_badge()`: badge indicates that your repository can be launched
3021
#' in an executable environment on <https://mybinder.org/>
3122
#'
3223
#' @param badge_name Badge name. Used in error message and alt text
3324
#' @param href,src Badge link and image src
34-
#' @param stage Stage of the package lifecycle
35-
#'
25+
#' @param stage Stage of the package lifecycle. One of "experimental",
26+
#' "stable", "superseded", or "deprecated".
3627
#' @seealso Functions that configure continuous integration, such as
3728
#' [use_github_actions()], also create badges.
3829
#'
@@ -102,24 +93,22 @@ use_lifecycle_badge <- function(stage) {
10293
check_is_package("use_lifecycle_badge()")
10394
pkg <- project_name()
10495

105-
stage <- match.arg(tolower(stage), names(stages))
96+
stage <- tolower(stage)
97+
stage <- arg_match0(stage, names(stages))
10698
colour <- stages[[stage]]
10799

108100
src <- glue("https://img.shields.io/badge/lifecycle-{stage}-{colour}.svg")
109-
href <- glue("https://www.tidyverse.org/lifecycle/#{stage}")
101+
href <- glue("https://lifecycle.r-lib.org/articles/stages.html#{stage}")
110102
use_badge(paste0("Lifecycle: ", stage), href, src)
111103

112104
invisible(TRUE)
113105
}
114106

115107
stages <- c(
116108
experimental = "orange",
117-
maturing = "blue",
118109
stable = "brightgreen",
119110
superseded = "blue",
120-
archived = "red",
121-
dormant = "blue",
122-
questioning = "blue"
111+
deprecated = "orange"
123112
)
124113

125114
#' @rdname badges

R/lifecycle.R

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#' Use lifecycle badges
22
#'
33
#' @description
4+
#' This helper adds lifecycle as a dependency, copies the lifecycle badges into
5+
#' the `man/figures` folder, and reminds you how to use the badge syntax.
46
#'
5-
#' This helper copies the lifecycle badges in to the `man/figures`
6-
#' folder of your package. It also reminds you of the syntax to use
7-
#' them in the documentation of individual functions or arguments.
8-
#'
9-
#' See the [getting started
10-
#' vignette](https://lifecycle.r-lib.org/articles/lifecycle.html) of the
11-
#' lifecycle package.
7+
#' Learn more at <https://lifecycle.r-lib.org/articles/communicate.html>
128
#'
139
#' @seealso [use_lifecycle_badge()] to signal the [global lifecycle
1410
#' stage](https://www.tidyverse.org/lifecycle/) of your package as a whole.
15-
#'
1611
#' @export
1712
use_lifecycle <- function() {
1813
check_is_package("use_lifecycle()")
@@ -22,6 +17,8 @@ use_lifecycle <- function() {
2217
Turn on roxygen2 markdown support {ui_code('use_roxygen_md()')}")
2318
}
2419

20+
use_package("lifecycle")
21+
2522
dest_dir <- proj_path("man", "figures")
2623
create_directory(dest_dir)
2724

@@ -33,15 +30,9 @@ use_lifecycle <- function() {
3330

3431
ui_todo(c(
3532
"Add badges in documentation topics by inserting one of:",
36-
"- `r lifecycle::badge('experimental')`",
37-
"- `r lifecycle::badge('superseded')`",
38-
"- `r lifecycle::badge('questioning')`",
39-
"- `r lifecycle::badge('deprecated')`"
40-
))
41-
42-
ui_todo(c(
43-
"If you want to use functions like `lifecycle::deprecate_soft()` in your package:",
44-
"- `usethis::use_package(\"lifecycle\")`"
33+
"#' `r lifecycle::badge('experimental')`",
34+
"#' `r lifecycle::badge('superseded')`",
35+
"#' `r lifecycle::badge('deprecated')`"
4536
))
4637

4738
invisible(TRUE)

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ knitr::opts_chunk$set(
1919
[![R-CMD-check](https://github.com/r-lib/usethis/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/usethis/actions)
2020
[![Codecov test coverage](https://codecov.io/gh/r-lib/usethis/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/usethis?branch=master)
2121
[![CRAN status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis)
22-
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
22+
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
2323
<!-- badges: end -->
2424

2525
usethis is a workflow package: it automates repetitive tasks that arise during project setup and development, both for R packages and non-package projects.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ coverage](https://codecov.io/gh/r-lib/usethis/branch/master/graph/badge.svg)](ht
1111
[![CRAN
1212
status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis)
1313
[![Lifecycle:
14-
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
14+
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
1515
<!-- badges: end -->
1616

1717
usethis is a workflow package: it automates repetitive tasks that arise

man/badges.Rd

Lines changed: 3 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/use_lifecycle.Rd

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/badge.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# use_lifecycle_badge() handles bad and good input
2+
3+
Code
4+
use_lifecycle_badge()
5+
Error <simpleError>
6+
argument "stage" is missing, with no default
7+
Code
8+
use_lifecycle_badge("eperimental")
9+
Error <rlang_error>
10+
`stage` must be one of "experimental", "stable", "superseded", or "deprecated".
11+
Did you mean "experimental"?
12+

tests/testthat/test-badge.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ test_that("use_[cran|bioc]_badge() don't error", {
66

77
test_that("use_lifecycle_badge() handles bad and good input", {
88
create_local_package()
9-
expect_error(use_lifecycle_badge(), "argument \"stage\" is missing")
10-
expect_error(use_lifecycle_badge("eperimental"), "'arg' should be one of ")
9+
10+
expect_snapshot(error = TRUE, {
11+
use_lifecycle_badge()
12+
use_lifecycle_badge("eperimental")
13+
})
14+
1115
expect_error_free(use_lifecycle_badge("stable"))
1216
})
1317

0 commit comments

Comments
 (0)