-
Notifications
You must be signed in to change notification settings - Fork 26
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
added cr_buildtrigger_build #186
base: master
Are you sure you want to change the base?
added cr_buildtrigger_build #186
Conversation
Some example code of checking the same trigger where same_trigger = function(buildtrigger, name, project) {
suppressMessages({
res = try({
googleCloudRunner::cr_buildtrigger_get(
triggerId = name,
projectId = project)
}, silent = TRUE)
})
if (!inherits(res, "try-error") && !is.null(res)) {
bt = googleCloudRunner:::as.buildTriggerResponse(buildtrigger)
res$id = res$createTime = NULL
if (is.null(res$disabled)) {
res$disabled = FALSE
}
# do this if you don't care about description
# !! Important - if you do care and you use a timestamped description - they are always different!
res$description = bt$description = NULL
all_names = union(names(bt), names(res))
if (all(all_names %in% names(bt)) &&
all(all_names %in% names(res))) {
bt = bt[all_names]
res = res[all_names]
}
if (isTRUE(all.equal(res, bt))) {
message("trigger: ", name, " already exists and same as ",
"the one being created, \nreturning the current trigger ",
"instead of overwriting")
return(TRUE)
}
}
return(FALSE)
} |
I think this use case is better served via # existing trigger?
present <- cr_buildtrigger_get("targets-scheduled-demo")
# not there
if(is.null(present)){
# create trigger via cr_buildtrigger()
trig <- cr_buildtrigger(...)
return(trig)
}
#already exisit - modify
cr_buildtrigger_edit(...) But let me know what the above doesn't cover.
This broke builds in the past, does the existing change pass tests? If you can't run the tests, it may help a lot if you have the ability to run them - the cloudbuild file for them are in
I don't see this change? Was that another pull? |
Agreed - no YAML argument. Do you know what happens when a trigger is edited if it stays tied to specific builds? |
Yes, it's like editing them in the UI - the underlying triggerId remains intact, which is not the case if the buildtrigger is overwritten. |
Point of this PR:
cr_buildtrigger_build
, which alllows us to construct buildtrigger objects. This is crucial when running the same code, but you don't want to replace a buildtrigger but it already exists. If you delete a buildtrigger, then any builds that were triggered from the previous trigger are not indicated to "Unknown". Now you can usecr_buildtrigger_build(...)
and compare it tocr_buildtrigger_get()
to see if the exact (or exact enough) buildtrigger already exists.gcs_sources
if they exist in the build