Skip to content

Support Google Cloud Build #469

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

Merged
merged 7 commits into from
Jun 7, 2022
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ revdep/checks
revdep/library
docs/
script.R
.Rhistory
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Fix `parse_gcov` bug when package is stored in directory with regex special characters, see #459
* Error/warning thrown for, respectively, missing gcov or empty parsed gcov output (@stephematician, #448)

* Support Google Cloud Build uploading reports to Codecov.io (@MarkEdmondson1234 #469)

* covr is now licensed as MIT (#454)

# covr 3.5.1
Expand Down
33 changes: 32 additions & 1 deletion R/codecov.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ codecov <- function(...,
slug = slug,
commit = commit %||% Sys.getenv("GITHUB_SHA"))
# ---------
# Google Cloud Build
# ---------
} else if (nzchar(Sys.getenv("GCB_PROJECT_ID"))) {

# https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values
codecov_url <- paste0(base_url, "/upload/v2") # nolint

build_url <- sprintf("https://console.cloud.google.com/cloud-build/builds/%s?project=%s",
Sys.getenv("GCB_BUILD_ID"), Sys.getenv("GCB_PROJECT_ID"))

name <- NULL
pr <- NULL
if(nzchar(Sys.getenv("GCB_TAG_NAME"))) name <- Sys.getenv("GCB_TAG_NAME")
if(nzchar(Sys.getenv("GCB_PR_NUMBER"))) pr <- Sys.getenv("GCB_PR_NUMBER")

codecov_query <- list(
branch = branch %||% Sys.getenv("GCB_BRANCH_NAME"),
service = "custom",
build = Sys.getenv("GCB_BUILD_ID"),
build_url = build_url,
name = name,
pr = pr,
commit = commit %||% Sys.getenv("GCB_COMMIT_SHA")
)

# ---------
# Local GIT
# ---------
} else {
Expand All @@ -202,7 +228,12 @@ codecov <- function(...,

coverage_json <- to_codecov(coverage)

httr::content(httr::RETRY("POST", url = codecov_url, query = codecov_query, body = coverage_json, encode = "json", httr::config(http_version = curl_http_1_1())))
httr::content(httr::RETRY("POST",
url = codecov_url,
query = codecov_query,
body = coverage_json,
encode = "json",
httr::config(http_version = curl_http_1_1())))
}

curl_http_1_1 <- function() {
Expand Down