r-lib/usethis

The latest release of r-lib/actions "broke" use_github_action()

maelle opened this issue ยท 5 comments

Reported by @SunnyTseng ๐Ÿ™

Error we observe, with the backtrace hinting at pick_tag() being the problem:

> usethis::use_github_action()
Which action do you want to add? (0 to exit)
(See <https://github.com/r-lib/actions/tree/v2/examples> for other options) 

1: check-standard: Run `R CMD check` on Linux, macOS, and Windows
2: test-coverage: Compute test coverage and report to https://about.codecov.io
3: pr-commands: Add /document and /style commands for pull requests

Selection: 1
Error: invalid version specification โ€˜โ€™
Backtrace:
 1. usethis::use_github_action()
 3. usethis:::latest_release()
 4. usethis:::pick_tag(tag_names)
 5. base::numeric_version(sub("^[^0-9]*", "", dat$nm))
 6. base::.make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version)

use_github_action() finds the ref part of the URL to the workflow by picking the latest release of the r-lib/actions repository.

ref <- ref %||% latest_release()

In latest_release(), the release names are extracted via GitHub API:

usethis/R/github-actions.R

Lines 260 to 270 in 9e64daf

raw_releases <- gh::gh(
"/repos/{owner}/{repo}/releases",
owner = spec_owner(parsed$repo_spec),
repo = spec_repo(parsed$repo_spec),
.api_url = parsed$host,
.limit = Inf
)
tag_names <- purrr::discard(
map_chr(raw_releases, "tag_name"),
map_lgl(raw_releases, "prerelease")
)

Today these names are c("v2", "sysreqs", "v1"). (Yesterday there was a new release of the r-lib/actions repo called "sysreqs". https://github.com/r-lib/actions/releases)

In pick_tag(), the line below transforms each of the names to a numeric version

dat$version <- numeric_version(sub("^[^0-9]*", "", dat$nm))

With "sysreqs", it doesn't work:

numeric_version(sub("^[^0-9]*", "", "sysreqs"))
#> Error: invalid version specification ''

Created on 2024-03-26 with reprex v2.1.0

@gaborcsardi would it work to simply add a "0" at the end of the "sysreqs" release name? ๐Ÿ˜…

numeric_version(sub("^[^0-9]*", "", "sysreqs0"))
#> [1] '0'

Created on 2024-03-26 with reprex v2.1.0

In the meantime, a workaround is to manually add the ref to the usethis_github_action() call:

use_github_action(ref = "v2")

I'll delete the sysreqs tag in ~30 minutes, to give a chance to the currently running workflows to finish the setup-r step. After that this should be fixed.

Thank you!!

OK, deleted the tag, windows setup-r still works, all seem to be good. Thanks for the report and the investigation. It made the fix really easy on my part.