Skip to content

Commit

Permalink
Merge pull request #101 from KeisukeYamashita/support-regional-cloudb…
Browse files Browse the repository at this point in the history
…uild

Support regional (=private pool) Cloud Build
  • Loading branch information
KeisukeYamashita authored Jan 17, 2022
2 parents 807b0b1 + 2c1c267 commit 4ada7e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 12 additions & 1 deletion ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"strings"
)

const (
defaultCloudBuildRegion = "global"
)

// CI represents a common information obtained from all CI platforms
type CI struct {
PR PullRequest
Expand Down Expand Up @@ -150,8 +154,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 = defaultCloudBuildRegion
}

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 4ada7e7

Please sign in to comment.