Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT - feedback needed] Sync crate and R package versions #307

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ export(rust_eval)
export(rust_function)
export(rust_sitrep)
export(rust_source)
export(sync_version)
export(to_toml)
export(use_extendr)
export(use_version)
export(write_license_note)
importFrom(dplyr,"%>%")
importFrom(dplyr,mutate)
Expand Down
70 changes: 70 additions & 0 deletions R/use-version.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

#' Modify Package Version
#' @export
use_version <- function(which = c("major", "minor", "patch")) {

# check if the cargo-bump crate is available
if (!cargo_command_available(c("bump", "--help"))) {
cli::cli_abort(
c(
"The {.code cargo bump} command is required to run the {.fun use_version} function.",
"*" = "Please install cargo-bump ({.url https://crates.io/crates/cargo-bump}) first.",
i = "Run {.code cargo install cargo-bump} from your terminal."
),
class = "rextendr_error"
)
}

v_type <- match.arg(which)

# increment version
usethis::use_version(v_type)

# defer to sync version
sync_version()
}

#' @rdname use_version
#' @export
sync_version <- function(path = ".") {

# check if the cargo-bump crate is available
if (!cargo_command_available(c("bump", "--help"))) {
cli::cli_abort(
c(
"The {.code cargo bump} command is required to run the {.fun use_version} function.",
"*" = "Please install cargo-bump ({.url https://crates.io/crates/cargo-bump}) first.",
i = "Run {.code cargo install cargo-bump} from your terminal."
),
class = "rextendr_error"
)
}

# read description
x <- desc::desc(rprojroot::find_package_root_file("DESCRIPTION", path = path))

# get manifest
manifest_file <- rprojroot::find_package_root_file("src", "rust", "Cargo.toml", path = path)

# get the new version from the description file
new_v <- x$get_version()

# check if there is a version such as 0.1.0.9000
# these are not supported by rust
if (length(new_v) > 3) {
rlang::abort("Package must be a semantic version following `major.minor.patch`")
}

# assign to object to prevent printing anything
res <- processx::run(
"cargo",
c(
"bump",
as.character(new_v),
"--manifest-path",
manifest_file
)
)

}

14 changes: 14 additions & 0 deletions man/use_version.Rd

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