Skip to content

Commit

Permalink
Merge pull request #139 from carpentries/update-deployments
Browse files Browse the repository at this point in the history
Add ci_bundle_pr_artifacts()
  • Loading branch information
zkamvar committed Aug 11, 2021
2 parents 3a8e005 + 391e224 commit 6dfb668
Show file tree
Hide file tree
Showing 16 changed files with 694 additions and 161 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.0.0.9035
Version: 0.0.0.9036
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down Expand Up @@ -40,6 +40,7 @@ Imports:
tools
Suggests:
testthat (>= 3.0.0),
brio,
covr,
withr,
jsonlite,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export(template_license)
export(template_links)
export(template_pkgdown)
export(template_placeholder)
export(template_pr_diff)
export(template_setup)
export(update_varnish)
importFrom(assertthat,validate_that)
Expand Down
14 changes: 13 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# sandpaper 0.0.0.9036

MISC
----

- Documentation for `git_worktree_setup()` has been added for future versions
of the maintainer and future contributors.
- `ci_bundle_pr_artifacts()` is a new internal function that will create
artifacts for GitHub to upload upon receipt of a pull request. This will
replace clunky shell code that lived inside a YAML configuration file.
(@zkamvar, #139)

# sandpaper 0.0.0.9035

MISC
----

- Tests for git operations were added to be more robust (@zkamvar, #137)
- A new test fixture for a local remote repository was added to aid the above
- new test fixtures for a local remote repository was added to aid the above
git tests.

# sandpaper 0.0.0.9034
Expand Down
2 changes: 1 addition & 1 deletion R/ci_build_markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ ci_build_markdown <- function(path = ".", branch = "md-outputs", remote = "origi
del_md <- git_worktree_setup(path, built,
branch = branch, remote = remote
)
on.exit(eval(del_md), add = TRUE)

build_markdown(path = path, quiet = TRUE, rebuild = FALSE)

github_worktree_commit(built,
message_source("markdown source builds", current, dir = path),
remote, branch
)
return(del_md)
}

ci_build_site <- function(path = ".", branch = "gh-pages", md = "md-outputs", remote = "origin") {
Expand Down
4 changes: 3 additions & 1 deletion R/ci_deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ ci_deploy <- function(path = ".", md_branch = "md-outputs", site_branch = "gh-pa

built <- path_built(path)
html <- fs::path(path_site(path), "docs")
has_withr <- requireNamespace("withr", quietly = TRUE)

if (requireNamespace("withr", quietly = TRUE)) { withr::with_dir(path, {
if (has_git() && has_withr) { withr::with_dir(path, {
# Set up the worktrees and make sure to remove them when the function exits
# (gracefully or ungracefully so)
# ------------ markdown worktree
Expand Down Expand Up @@ -57,5 +58,6 @@ ci_deploy <- function(path = ".", md_branch = "md-outputs", site_branch = "gh-pa
remote, site_branch
)
})}
invisible()
}

4 changes: 4 additions & 0 deletions R/template.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ template_pkgdown <- generate_template_function("pkgdown-yaml")
#' @export
template_placeholder <- generate_template_function("placeholder")

#' @rdname template
#' @export
template_pr_diff <- generate_template_function("pr_diff")

24 changes: 23 additions & 1 deletion R/test-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,33 @@ setup_local_remote <- function(repo, remote = tempfile(), name = "sandpaper-loca
fs::dir_create(remote)
}
gert::git_clone(repo, path = remote, bare = TRUE)
gert::git_remote_remove(remote = "origin", repo = remote)
gert::git_remote_add(remote, name, repo = repo)
gert::git_push(remote = name, set_upstream = TRUE, repo = repo, verbose = FALSE)
gert::git_push(remote = name, set_upstream = TRUE, repo = repo, verbose = verbose)
return(invisible(repo))
}

# create and clean branches in the local and remote repositories
make_branch <- function(repo, branch, remote_name = "sandpaper-local", verbose = FALSE) {
this_branch <- gert::git_branch(repo = repo)
on.exit(gert::git_branch_checkout(this_branch, repo = repo))
gert::git_branch_create(branch, repo = repo, checkout = TRUE)
gert::git_push(remote = remote_name, repo = repo, verbose = verbose)
}

clean_branch <- function(repo, nu_branch = NULL, remote_name = "sandpaper-local", verbose = FALSE) {
this_branch <- gert::git_branch(repo)
if (is.null(nu_branch) || this_branch == nu_branch) {
gert::git_branch_checkout("main", repo = repo)
}
gert::git_branch_delete(nu_branch, repo = repo)
rmt_url <- gert::git_remote_list(repo)
rmt_url <- rmt_url$url[rmt_url$name == remote_name]
if (length(rmt_url) > 0) {
gert::git_branch_delete(nu_branch, repo = rmt_url)
}
}

#' @rdname fixtures
#' @return (`remove_local_remote()`) FALSE indicating an error or a string
#' indicating the path to the remote
Expand Down
Loading

0 comments on commit 6dfb668

Please sign in to comment.