Skip to content

Commit 5c21bfb

Browse files
authored
create_gitops_prs: added a new bazel_flag argument (#61)
Signed-off-by: Vincent Composieux <[email protected]>
1 parent a814a45 commit 5c21bfb

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ The `--release_branch` specifies the value of the ***release_branch_prefix*** at
430430

431431
The `create_gitops_prs` tool will query all `gitops` targets which have set the ***deploy_branch*** attribute (see [k8s_deploy](#k8s_deploy)) and the ***release_branch_prefix*** attribute value that matches the `release_branch` parameter.
432432

433+
In case you need to specify a custom Bazel flag during the pull request process, you can add one `--bazel_flag` such as `--bazel_flag --config=ci` or multiple such as `--bazel_flag --config=ci --bazel_flag --color=no`.
434+
433435
The all discovered `gitops` targets are grouped by the value of ***deploy_branch*** attribute. The one deployment branch will accumulate the output of all corresponding `gitops` targets.
434436

435437
For example, we define two deployments: grafana and prometheus. Both deployments share the same namespace. The deployments a grouped by namespace.

gitops/gitops.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def __create_gitops_prs_impl(ctx):
1515
executables = src_by_train[deployment_branch]
1616
for exe in executables:
1717
params += "--resolved_binary {}:{} ".format(deployment_branch, exe.short_path)
18+
if ctx.attr.bazel_flag:
19+
params += "--bazel_flag {} ".format(ctx.attr.bazel_flag)
1820
for exe in trans_img_pushes:
1921
params += "--resolved_push {} ".format(exe.files_to_run.executable.short_path)
2022
if ctx.attr.release_branch:

gitops/prer/create_gitops_prs.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (i *SliceFlags) Set(value string) error {
5252
var (
5353
releaseBranch = flag.String("release_branch", "master", "filter gitops targets by release branch")
5454
bazelCmd = flag.String("bazel_cmd", "tools/bazel", "bazel binary to use")
55+
bazelFlags SliceFlags
5556
workspace = flag.String("workspace", "", "path to workspace root")
5657
repo = flag.String("git_repo", "", "git repo location")
5758
gitMirror = flag.String("git_mirror", "", "git mirror location, like /mnt/mirror/bitbucket.tubemogul.info/tm/repo.git for jenkins")
@@ -77,6 +78,7 @@ var (
7778
)
7879

7980
func init() {
81+
flag.Var(&bazelFlags, "bazel_flag", "bazel flag to pass during gitops phase. Can be specified multiple times. Default is empty")
8082
flag.Var(&gitopsKind, "gitops_dependencies_kind", "dependency kind(s) to run during gitops phase. Can be specified multiple times. Default is 'k8s_container_push'")
8183
flag.Var(&gitopsRuleName, "gitops_dependencies_name", "dependency name(s) to run during gitops phase. Can be specified multiple times. Default is empty")
8284
flag.Var(&gitopsRuleAttr, "gitops_dependencies_attr", "dependency attribute(s) to run during gitops phase. Use attribute=value format. Can be specified multiple times. Default is empty")
@@ -266,7 +268,20 @@ func main() {
266268
exec.Mustex("", bin)
267269
} else {
268270
log.Println("target", target, "is not a file, running as a command")
269-
exec.Mustex("", *bazelCmd, "run", target)
271+
272+
args := []string{"run"}
273+
274+
if len(bazelFlags) > 0 {
275+
for _, bazelFlag := range bazelFlags {
276+
bazelFlagArgs := strings.Split(bazelFlag, " ")
277+
278+
args = append(args, bazelFlagArgs...)
279+
}
280+
}
281+
282+
args = append(args, target)
283+
284+
exec.Mustex("", *bazelCmd, args...)
270285
}
271286
}
272287
}()

0 commit comments

Comments
 (0)