Skip to content

Commit

Permalink
Support regional cloud build
Browse files Browse the repository at this point in the history
Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com>
  • Loading branch information
KeisukeYamashita committed Jan 14, 2022
1 parent 807b0b1 commit 74a9b51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down
9 changes: 6 additions & 3 deletions ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down

0 comments on commit 74a9b51

Please sign in to comment.