Skip to content

Commit

Permalink
Merge branch 'main' into test-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy authored Jun 27, 2024
2 parents 31d68a2 + 1398d7b commit 875aa50
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 56 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
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# usethis (development version)

* `use_test_helper()` is a new function to create testthat helpers (@olivroy, #1822).
* `use_test_helper()` is a new function to create testthat helper files (@olivroy, #1822).

* 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).
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
2 changes: 1 addition & 1 deletion R/directory.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ directory_has_files <- function(x) {

check_directory_is_empty <- function(x) {
if (directory_has_files(x)) {
ui_abort("{.path {pth(path)}} exists and is not an empty directory.")
ui_abort("{.path {pth(x)}} exists and is not an empty directory.")
}
invisible(x)
}
4 changes: 4 additions & 0 deletions R/documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
#' @export
use_package_doc <- function(open = rlang::is_interactive()) {
check_is_package("use_package_doc()")
use_directory("R")
use_template(
"packagename-package.R",
package_doc_path(),
open = open
)
ui_bullets(c(
"_" = "Run {.run devtools::document()} to update package-level documentation."
))
}

package_doc_path <- function() {
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
5 changes: 3 additions & 2 deletions R/roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use_roxygen_md <- function(overwrite = FALSE) {
the conversion process."
))
}
ui_bullets(c("v" = "Run {.run devtools::document()} when you're done."))
ui_bullets(c("_" = "Run {.run devtools::document()} when you're done."))

return(invisible())
}
Expand Down 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."
))
}
2 changes: 1 addition & 1 deletion R/tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' * Prepare the roxygen directive necessary to import at least one function
#' from tibble:
#' - If possible, the directive is inserted into existing package-level
#' documentation, i.e. the roxygen snippet created by [use_package_doc()]
#' documentation, i.e. the roxygen snippet created by [use_package_doc()]
#' - Otherwise, we issue advice on where the user should add the directive
#'
#' This is necessary when your package returns a stored data object that has
Expand Down
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
2 changes: 1 addition & 1 deletion man/use_tibble.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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="" />

1 change: 1 addition & 0 deletions tests/testthat/_snaps/roxygen.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use_package_doc()
Message
v Writing 'R/{TESTPKG}-package.R'.
[ ] Run `devtools::document()` to update package-level documentation.

---

Expand Down
Loading

0 comments on commit 875aa50

Please sign in to comment.