-
Notifications
You must be signed in to change notification settings - Fork 921
/
it-flags.go
99 lines (86 loc) · 2.9 KB
/
it-flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package flags
import (
"flag"
"fmt"
"os/exec"
)
// Avoid making these vars public.
var (
dRegion string
dProject string
dArtifactBucket string
dStageBucket string
dHostIp string
dPrivateConnectivity string
dReleaseMode bool
dRetryFailures string
)
// Registers all common flags. Must be called before flag.Parse().
func RegisterItFlags() {
flag.StringVar(&dRegion, "it-region", "", "The GCP region to use for storing test artifacts")
flag.StringVar(&dProject, "it-project", "", "The GCP project to run the integration tests in")
flag.StringVar(&dArtifactBucket, "it-artifact-bucket", "", "A GCP bucket to store test artifacts")
flag.StringVar(&dStageBucket, "it-stage-bucket", "", "(optional) A GCP bucket to stage templates")
flag.StringVar(&dHostIp, "it-host-ip", "", "(optional) The ip that the gitactions runner is listening on")
flag.StringVar(&dPrivateConnectivity, "it-private-connectivity", "", "(optional) A GCP private connectivity endpoint")
flag.BoolVar(&dReleaseMode, "it-release", false, "(optional) Set if tests are being executed for a release")
flag.StringVar(&dRetryFailures, "it-retry-failures", "0", "Number of retries attempts for failing tests")
}
func Region() string {
return "-Dregion=" + dRegion
}
func Project() string {
return "-Dproject=" + dProject
}
func ArtifactBucket() string {
return "-DartifactBucket=" + dArtifactBucket
}
func StageBucket() string {
if dStageBucket == "" {
return "-DstageBucket=" + dArtifactBucket
}
return "-DstageBucket=" + dStageBucket
}
func HostIp() string {
if len(dHostIp) == 0 {
gcloudCmd := "gcloud compute instances list | grep $(hostname) | awk '{print $4}'"
if hostIP, err := exec.Command("bash", "-c", gcloudCmd).Output(); err != nil || len(hostIP) == 0 {
panic(fmt.Errorf("failed to get gitactions runner host ip: %v", err))
} else {
return "-DhostIp=" + string(hostIP)[:len(hostIP)-1]
}
}
return "-DhostIp=" + dHostIp
}
func PrivateConnectivity() string {
if dPrivateConnectivity != "" {
return "-DprivateConnectivity=" + dPrivateConnectivity
}
return ""
}
func FailureMode() string {
// Fail releases fast
if dReleaseMode {
return "-ff"
}
// Fail PRs at the end
return "-fae"
}
func RetryFailures() string {
return "-Dsurefire.rerunFailingTestsCount=" + dRetryFailures
}