Skip to content

Commit a0e0360

Browse files
committed
Test
1 parent d5e89c2 commit a0e0360

File tree

8 files changed

+128
-0
lines changed

8 files changed

+128
-0
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
^rv\.git\.pkgA\.Rproj$
22
^\.Rproj\.user$
33
^LICENSE\.md$
4+
rproject.toml

.Rprofile

Whitespace-only changes.

.github/workflows/release.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: R Release
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Setup R
20+
uses: r-lib/actions/setup-r@v2
21+
22+
- name: Install the latest version of rv
23+
uses: a2-ai/setup-rv@main
24+
25+
- name: sync
26+
run: rv sync
27+
28+
- name: get library path
29+
id: library
30+
run: |
31+
OUTPUT=$(rv library)
32+
echo "result=$OUTPUT" >> $GITHUB_OUTPUT
33+
echo $GITHUB_OUTPUT
34+
35+
- name: Run R Releaser
36+
id: releaser
37+
uses: A2-ai/r-releaser/build-src@main
38+
with:
39+
library: ${{ steps.library.outputs.result }}
40+
resave-data: false
41+
42+
- name: echo output
43+
run: |
44+
echo ${{ steps.releaser.outputs.tarball_path }}
45+
echo ${{ steps.releaser.outputs.tarball_name }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.Rproj.user
2+
rv/

rproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[project]
2+
name = "rv.git.pkgA"
3+
r_version = "4.5"
4+
5+
# any CRAN-type repository, order matters. Additional ability to force source package installation
6+
# Example: {alias = "CRAN", url = "https://cran.r-project.org", force_source = true}
7+
repositories = [
8+
{alias = "CRAN", url = "https://cran.r-project.org", force_source = true}
9+
]
10+
11+
# package to install and any specifications. Any descriptive dependency can have the `install_suggestions` specification
12+
# Examples:
13+
# "dplyr",
14+
# {name = "dplyr", repository = "CRAN", force_source = true},
15+
# {name = "dplyr", git = "https://github.com/tidyverse/dplyr.git", tag = "v1.1.4"},
16+
# {name = "dplyr", path = "/path/to/local/dplyr"},
17+
dependencies = [
18+
"R6"
19+
]
20+

rv/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
library
2+
__rv__staging

rv/scripts/activate.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
local({
2+
rv_info <- system2("rv", c("info", "--library", "--r-version", "--repositories"), stdout = TRUE)
3+
if (!is.null(attr(rv_info, "status"))) {
4+
# if system2 fails it'll add a status attribute with the error code
5+
warning("failed to run rv info, check your console for messages")
6+
} else {
7+
# extract library, r-version, and repositories from rv
8+
rv_lib <- sub("library: (.+)", "\\1", grep("^library:", rv_info, value = TRUE))
9+
rv_r_ver <- sub("r-version: (.+)", "\\1", grep("^r-version:", rv_info, value = TRUE))
10+
repo_str <- sub("repositories: ", "", grep("^repositories:", rv_info, value = TRUE))
11+
repo_entries <- gsub("[()]", "", strsplit(repo_str, "), (", fixed = TRUE)[[1]])
12+
repo_list <- trimws(sub(".*, ", "", repo_entries)) # Extract URL
13+
names(repo_list) <- trimws(sub(", .*", "", repo_entries)) # Extract Name
14+
# this might not yet exist, so we'll normalize it but not force it to exist
15+
# and we create it below as needed
16+
rv_lib <- normalizePath(rv_lib, mustWork = FALSE)
17+
if (!dir.exists(rv_lib)) {
18+
message("creating rv library: ", rv_lib)
19+
dir.create(rv_lib, recursive = TRUE)
20+
}
21+
.libPaths(rv_lib, include.site = FALSE)
22+
options(repos = repo_list)
23+
24+
if (interactive()) {
25+
message("rv libpaths active!\nlibrary paths: \n", paste0(" ", .libPaths(), collapse = "\n"), "\n")
26+
message("rv repositories active!\nrepositories: \n", paste0(" ", names(getOption("repos")), ": ", getOption("repos"), collapse = "\n"))
27+
sys_r <- sprintf("%s.%s", R.version$major, R.version$minor)
28+
if (!grepl(paste0("^", rv_r_ver), sys_r)) {
29+
message(sprintf("\nWARNING: R version specified in config (%s) does not match session version (%s)", rv_r_ver, sys_r))
30+
}
31+
}
32+
}
33+
})

rv/scripts/rvr.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.rv <- new.env()
2+
.rv$config_path <- file.path(normalizePath(getwd()), "rproject.toml")
3+
.rv$summary <- function(json = FALSE) {
4+
command <- c("summary")
5+
if (json) { command <- c(command, "--json") }
6+
.rv$command(command)
7+
}
8+
.rv$plan <- function() { .rv$command("plan") }
9+
.rv$sync <- function() { .rv$command("sync") }
10+
.rv$add <- function(..., dry_run = FALSE) {
11+
dots <- unlist(list(...))
12+
command <- c("add", dots)
13+
if (dry_run) { command <- c(command, "--dry-run") }
14+
.rv$command(command)
15+
}
16+
17+
.rv$command <- function(command) {
18+
# underlying system calls to rv
19+
args <- c(command, "-c", .rv$config_path)
20+
res <- system2("rv", args, stdout = TRUE)
21+
if (!is.null(attr(res, "status"))) {
22+
warning(sprintf("failed to run `rv %s`, check your console for messages", paste(args, collapse = " ")))
23+
} else {
24+
message(paste(res, collapse = "\n"))
25+
}
26+
}

0 commit comments

Comments
 (0)