Skip to content

Commit

Permalink
Merge branch 'main' into helper-snap
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy authored Jun 27, 2024
2 parents e373436 + 1398d7b commit eee3b0e
Show file tree
Hide file tree
Showing 23 changed files with 133 additions and 50 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -25,17 +27,15 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -54,7 +54,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck, magick=?ignore-before-r=4.0.0
extra-packages: any::rcmdcheck
needs: check

- name: Configure Git User
Expand All @@ -64,8 +64,6 @@ jobs:
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: r-lib/actions/check-r-package@v2
env:
_R_CALLS_INVALID_NUMERIC_VERSION_: true
_R_CHECK_FORCE_SUGGESTS_: false
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
2 changes: 2 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:

name: pkgdown

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:

name: Commands

permissions: read-all

jobs:
document:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
Expand All @@ -23,7 +25,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: git config
Expand All @@ -33,18 +35,27 @@ jobs:
- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Description: Automate package and project setup tasks that are otherwise
License: MIT + file LICENSE
URL: https://usethis.r-lib.org, https://github.com/r-lib/usethis
BugReports: https://github.com/r-lib/usethis/issues
Depends:
Depends:
R (>= 3.6)
Imports:
Imports:
cli (>= 3.0.1),
clipr (>= 0.3.0),
crayon,
Expand All @@ -43,7 +43,7 @@ Imports:
whisker,
withr (>= 2.3.0),
yaml
Suggests:
Suggests:
covr,
knitr,
magick,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

* `use_test()` and `use_r()` now work when you are in `tests/testthat/helper-{foo}.R` or `tests/testthat/_snaps/{foo}.md` (@olivroy, #1988).

* The URLs baked into the badge generated by `use_coverage(type = "codecov")`
no longer specify a branch (#2008).

* The `ui_*()` functions have been marked as
[superseded](https://lifecycle.r-lib.org/articles/stages.html#superseded).
External users of these functions are encouraged to use the
Expand All @@ -15,6 +18,9 @@
usethis no longer uses the `ui_*()` functions internally, in favor of new
cli-based helpers that are not exported.

* `usethis::use_version()` now tolerates empty / blank lines preceding the
first section title in the package NEWS file. (#1976)

# usethis 2.2.3

* Patch release with changes to `.Rd` files requested by CRAN.
Expand Down
4 changes: 2 additions & 2 deletions R/badge.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use_badge <- function(badge_name, href, src) {
if (is.null(path)) {
ui_bullets(c(
"!" = "Can't find a README for the current project.",
"i" = "See {.help usethis::use_readme_rmd} for help creating this file.",
"i" = "See {.fun usethis::use_readme_rmd} for help creating this file.",
"i" = "Badge link will only be printed to screen."
))
path <- "README"
Expand All @@ -60,7 +60,7 @@ use_badge <- function(badge_name, href, src) {

if (changed && path_ext(path) == "Rmd") {
ui_bullets(c(
"_" = "Re-knit {.path {pth(path)}} with {.fun devtools::build_readme}."
"_" = "Re-knit {.path {pth(path)}} with {.run devtools::build_readme()}."
))
}
invisible(changed)
Expand Down
5 changes: 2 additions & 3 deletions R/coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ use_covr_ignore <- function(files) {
}

use_codecov_badge <- function(repo_spec) {
default_branch <- git_default_branch()
url <- glue("https://app.codecov.io/gh/{repo_spec}?branch={default_branch}")
img <- glue("https://codecov.io/gh/{repo_spec}/branch/{default_branch}/graph/badge.svg")
url <- glue("https://codecov.io/gh/{repo_spec}")
img <- glue("https://codecov.io/gh/{repo_spec}/graph/badge.svg")
use_badge("Codecov test coverage", url, img)
}

Expand Down
5 changes: 3 additions & 2 deletions R/logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
use_logo <- function(img, geometry = "240x278", retina = TRUE) {
check_is_package("use_logo()")

logo_path <- proj_path("man", "figures", "logo", ext = path_ext(img))
ext <- tolower(path_ext(img))
logo_path <- proj_path("man", "figures", "logo", ext = ext)
create_directory(path_dir(logo_path))
if (!can_overwrite(logo_path)) {
return(invisible(FALSE))
}

if (path_ext(img) == "svg") {
if (ext == "svg") {
logo_path <- path("man", "figures", "logo.svg")
file_copy(img, proj_path(logo_path), overwrite = TRUE)
ui_bullets(c("v" = "Copied {.path {pth(img)}} to {.path {logo_path}}."))
Expand Down
13 changes: 9 additions & 4 deletions R/news.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ use_news_heading <- function(version) {
}

news <- read_utf8(news_path)
title <- glue("# {project_name()} {version}")
idx <- match(TRUE, grepl("[^[:space:]]", news))

if (is.na(idx)) {
return(news)
}

if (title == news[[1]]) {
title <- glue("# {project_name()} {version}")
if (title == news[[idx]]) {
return(invisible())
}

development_title <- glue("# {project_name()} (development version)")
if (development_title == news[[1]]) {
news[[1]] <- title
if (development_title == news[[idx]]) {
news[[idx]] <- title

ui_bullets(c("v" = "Replacing development heading in {.path NEWS.md}."))
return(write_utf8(news_path, news))
Expand Down
4 changes: 2 additions & 2 deletions R/proj.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ proj_set <- function(path = ".", force = FALSE) {
if (is.null(new_project)) {
ui_abort(c(
"Path {.path {pth(path)}} does not appear to be inside a project or package.",
"Read more in the help for {.help usethis::proj_get}."
"Read more in the help for {.fun usethis::proj_get}."
))
}
proj_set(path = new_project, force = TRUE)
Expand Down Expand Up @@ -227,7 +227,7 @@ check_is_project <- function() {
if (!possibly_in_proj()) {
ui_abort(c(
"We do not appear to be inside a valid project or package.",
"Read more in the help for {.help usethis::proj_get}."
"Read more in the help for {.fun usethis::proj_get}."
))
}
}
Expand Down
3 changes: 2 additions & 1 deletion R/roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ check_uses_roxygen <- function(whos_asking) {
return(invisible())
}

whos_asking_fn <- sub("()", "", whos_asking, fixed = TRUE)
ui_abort(c(
"Package {.pkg {project_name()}} does not use roxygen2.",
"{.fun {whos_asking}} can not work without it.",
"{.fun {whos_asking_fn}} can not work without it.",
"You might just need to run {.run devtools::document()} once, then try again."
))
}
5 changes: 3 additions & 2 deletions R/use_import_from.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ check_has_package_doc <- function(whos_asking) {
return(invisible(TRUE))
}

whos_asking_fn <- sub("()", "", whos_asking, fixed = TRUE)
msg <- c(
"!" = "{.fun {whos_asking}} requires package-level documentation.",
"!" = "{.fun {whos_asking_fn}} requires package-level documentation.",
" " = "Would you like to add it now?"
)
if (is_interactive() && ui_yep(msg)) {
use_package_doc()
} else {
ui_abort(c(
"{.fun {whos_asking}} requires package-level documentation.",
"{.fun {whos_asking_fn}} requires package-level documentation.",
"You can add it by running {.run usethis::use_package_doc()}."
))
}
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-lib/usethis/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/usethis?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![.github/workflows/R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-lib/usethis/graph/badge.svg)](https://codecov.io/gh/r-lib/usethis)
<!-- badges: end -->

usethis is a workflow package: it automates repetitive tasks that arise during project setup and development, both for R packages and non-package projects.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<!-- badges: start -->

[![R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/r-lib/usethis/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/usethis?branch=main)
[![CRAN
status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis)
[![Lifecycle:
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![.github/workflows/R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/.github/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/r-lib/usethis/graph/badge.svg)](https://codecov.io/gh/r-lib/usethis)
<!-- badges: end -->

usethis is a workflow package: it automates repetitive tasks that arise
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# we use specific URLs in a codecov badge

Code
use_codecov_badge("OWNER/REPO")
Message
! Can't find a README for the current project.
i See `usethis::use_readme_rmd()` for help creating this file.
i Badge link will only be printed to screen.
[ ] Copy and paste the following lines into 'README':
<!-- badges: start -->
[![Codecov test coverage](https://codecov.io/gh/OWNER/REPO/graph/badge.svg)](https://codecov.io/gh/OWNER/REPO)
<!-- badges: end -->

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/logo.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
[ ] Add logo to 'README.md' with the following html:
# {TESTPKG} <img src="man/figures/logo.png" align="right" height="90" alt="" />

# use_logo() writes a file in lowercase and it knows that

Code
use_logo("LoGo.PNG")
Message
v Creating 'man/figures/'.
v Resized 'LoGo.PNG' to 240x278.
[ ] Add logo to your README with the following html:
# {TESTPKG} <img src="man/figures/logo.png" align="right" height="90" alt="" />

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/tibble.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# use_tibble() Imports tibble
# use_tibble() Imports tibble and imports tibble::tibble()

Code
use_tibble()
Expand Down
22 changes: 11 additions & 11 deletions tests/testthat/_snaps/utils-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@
ui_code_snippet(
"\n options(\n warnPartialMatchArgs = TRUE,\n warnPartialMatchDollar = TRUE,\n warnPartialMatchAttr = TRUE\n )")
Message
[36moptions[39m[33m([39m
warnPartialMatchArgs = [34mTRUE[39m,
warnPartialMatchDollar = [34mTRUE[39m,
warnPartialMatchAttr = [34mTRUE[39m
[1moptions[22m[33m([39m
warnPartialMatchArgs = [35mTRUE[39m,
warnPartialMatchDollar = [35mTRUE[39m,
warnPartialMatchAttr = [35mTRUE[39m
)

# ui_code_snippet() with vector input [plain]
Expand All @@ -167,10 +167,10 @@
ui_code_snippet(c("options(", " warnPartialMatchArgs = TRUE,",
" warnPartialMatchDollar = TRUE,", " warnPartialMatchAttr = TRUE", ")"))
Message
[36moptions[39m[33m([39m
warnPartialMatchArgs = [34mTRUE[39m,
warnPartialMatchDollar = [34mTRUE[39m,
warnPartialMatchAttr = [34mTRUE[39m
[1moptions[22m[33m([39m
warnPartialMatchArgs = [35mTRUE[39m,
warnPartialMatchDollar = [35mTRUE[39m,
warnPartialMatchAttr = [35mTRUE[39m
)

# ui_code_snippet() when language is not R [plain]
Expand Down Expand Up @@ -199,7 +199,7 @@
Code
ui_code_snippet("if (1) {true_val} else {false_val}")
Message
[31mif[39m [33m([39m[34m1[39m[33m)[39m [34mTRUE[39m [31melse[39m [33m'FALSE'[39m
[33mif[39m [33m([39m[35m1[39m[33m)[39m [35mTRUE[39m [33melse[39m [36m'FALSE'[39m

# ui_code_snippet() can NOT interpolate [plain]

Expand All @@ -217,11 +217,11 @@
Code
ui_code_snippet("foo <- function(x){x}", interpolate = FALSE)
Message
foo [32m<-[39m [31mfunction[39m[33m([39mx[33m)[39m[33m{[39mx[33m}[39m
foo [33m<-[39m [33mfunction[39m[33m([39mx[33m)[39m[33m{[39mx[33m}[39m
Code
ui_code_snippet("foo <- function(x){{x}}", interpolate = TRUE)
Message
foo [32m<-[39m [31mfunction[39m[33m([39mx[33m)[39m[33m{[39mx[33m}[39m
foo [33m<-[39m [33mfunction[39m[33m([39mx[33m)[39m[33m{[39mx[33m}[39m

# bulletize() works

Expand Down
Loading

0 comments on commit eee3b0e

Please sign in to comment.