From 74a9b51f0bb512e22e0c5be47e2db806e8a4e368 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Fri, 14 Jan 2022 22:34:32 +0900 Subject: [PATCH] Support regional cloud build Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- ci.go | 9 ++++++++- ci_test.go | 9 ++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ci.go b/ci.go index f77cc03..ecfb455 100644 --- a/ci.go +++ b/ci.go @@ -150,8 +150,15 @@ func githubActions() (ci CI, err error) { func cloudbuild() (ci CI, err error) { ci.PR.Number = 0 ci.PR.Revision = os.Getenv("COMMIT_SHA") + + region := os.Getenv("REGION") + if region == "" { + region = "global" + } + ci.URL = fmt.Sprintf( - "https://console.cloud.google.com/cloud-build/builds/%s?project=%s", + "https://console.cloud.google.com/cloud-build/builds;region=%s/%s?project=%s", + region, os.Getenv("BUILD_ID"), os.Getenv("PROJECT_ID"), ) diff --git a/ci_test.go b/ci_test.go index 7d0eac9..9313e11 100644 --- a/ci_test.go +++ b/ci_test.go @@ -766,6 +766,7 @@ func TestCloudBuild(t *testing.T) { "BUILD_ID", "PROJECT_ID", "_PR_NUMBER", + "REGION", } saveEnvs := make(map[string]string) for _, key := range envs { @@ -790,13 +791,14 @@ func TestCloudBuild(t *testing.T) { os.Setenv("BUILD_ID", "build-id") os.Setenv("PROJECT_ID", "gcp-project-id") os.Setenv("_PR_NUMBER", "123") + os.Setenv("REGION", "asia-northeast1") }, ci: CI{ PR: PullRequest{ Revision: "abcdefg", Number: 123, }, - URL: "https://console.cloud.google.com/cloud-build/builds/build-id?project=gcp-project-id", + URL: "https://console.cloud.google.com/cloud-build/builds;region=asia-northeast1/build-id?project=gcp-project-id", }, ok: true, }, @@ -806,13 +808,14 @@ func TestCloudBuild(t *testing.T) { os.Setenv("BUILD_ID", "build-id") os.Setenv("PROJECT_ID", "gcp-project-id") os.Setenv("_PR_NUMBER", "") + os.Setenv("REGION", "") }, ci: CI{ PR: PullRequest{ Revision: "", Number: 0, }, - URL: "https://console.cloud.google.com/cloud-build/builds/build-id?project=gcp-project-id", + URL: "https://console.cloud.google.com/cloud-build/builds;region=global/build-id?project=gcp-project-id", }, ok: true, }, @@ -828,7 +831,7 @@ func TestCloudBuild(t *testing.T) { Revision: "", Number: 0, }, - URL: "https://console.cloud.google.com/cloud-build/builds/build-id?project=gcp-project-id", + URL: "https://console.cloud.google.com/cloud-build/builds;region=global/build-id?project=gcp-project-id", }, ok: false, },