Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,14 @@ type TestStepConfiguration struct {
// Only applicable to presubmits; postsubmits always run on every merge.
SkipIfOnlyChanged string `json:"skip_if_only_changed,omitempty"`

// SkipBranches is a list of branch name regex patterns. Branches matching
// any of these patterns will be excluded from running this presubmit job.
// This maps directly to the upstream Prow Brancher.SkipBranches field and
// is useful to prevent feature branch inheritance (e.g. preventing a
// presubmit configured for "main" from also running on "main-*" branches).
// Only applicable to presubmit tests.
SkipBranches []string `json:"skip_branches,omitempty"`

// PipelineSkipIfOnlyChanged is a regex that will result in the test being skipped in second
// stage of the pipeline run if all changed files match that regex.
PipelineSkipIfOnlyChanged string `json:"pipeline_skip_if_only_changed,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion pkg/prowgen/prowgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func handlePresubmit(g *prowJobBaseBuilder, element cioperatorapi.TestStepConfig
options.Capabilities = element.Capabilities
options.runIfChanged = element.RunIfChanged
options.skipIfOnlyChanged = element.SkipIfOnlyChanged
options.skipBranches = element.SkipBranches
options.defaultDisable = element.AlwaysRun != nil && !*element.AlwaysRun
options.optional = element.Optional
options.disableRehearsal = disableRehearsal
Expand All @@ -244,6 +245,7 @@ type generatePresubmitOptions struct {
Capabilities []string
runIfChanged string
skipIfOnlyChanged string
skipBranches []string
defaultDisable bool
optional bool
disableRehearsal bool
Expand Down Expand Up @@ -307,7 +309,10 @@ func generatePresubmitForTest(jobBaseBuilder *prowJobBaseBuilder, name string, i
pj := &prowconfig.Presubmit{
JobBase: base,
AlwaysRun: opts.shouldAlwaysRun(),
Brancher: prowconfig.Brancher{Branches: sets.List(sets.New[string](jc.ExactlyBranch(info.Branch), jc.FeatureBranch(info.Branch)))},
Brancher: prowconfig.Brancher{
Branches: sets.List(sets.New[string](jc.ExactlyBranch(info.Branch), jc.FeatureBranch(info.Branch))),
SkipBranches: opts.skipBranches,
},
Reporter: prowconfig.Reporter{
Context: fmt.Sprintf("ci/prow/%s", shortName),
},
Expand Down
23 changes: 22 additions & 1 deletion pkg/prowgen/prowgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ func TestGeneratePresubmitForTest(t *testing.T) {
options.maxConcurrency = 4
},
},
{
description: "presubmit with skip_branches",
test: "testname",
repoInfo: &ciop.Metadata{Org: "org", Repo: "repo", Branch: "branch"},
generateOption: func(options *generatePresubmitOptions) {
options.skipBranches = []string{"^branch-foo$", "^branch-bar$"}
},
},
}
for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
Expand Down Expand Up @@ -935,8 +943,21 @@ func TestGenerateJobs(t *testing.T) {
Branch: "branch",
},
},
{
id: "presubmit with per-test skip_branches",
keep: true,
config: &ciop.ReleaseBuildConfiguration{
Tests: []ciop.TestStepConfiguration{
{As: "derTest", SkipBranches: []string{"^branch-foo$", "^branch-bar$"}, ContainerTestConfiguration: &ciop.ContainerTestConfiguration{From: "from"}},
},
},
repoInfo: &ciop.Metadata{
Org: "organization",
Repo: "repository",
Branch: "branch",
},
},
}

for _, tc := range tests {
t.Run(tc.id, func(t *testing.T) {
jobConfig, err := GenerateJobs(tc.config, tc.repoInfo)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
presubmits:
organization/repository:
- agent: kubernetes
always_run: true
branches:
- ^branch$
- ^branch-
context: ci/prow/derTest
decorate: true
decoration_config:
skip_cloning: true
labels:
pj-rehearse.openshift.io/can-be-rehearsed: "true"
name: pull-ci-organization-repository-branch-derTest
rerun_command: /test derTest
skip_branches:
- ^branch-foo$
- ^branch-bar$
spec:
containers:
- args:
- --gcs-upload-secret=/secrets/gcs/service-account.json
- --image-import-pull-secret=/etc/pull-secret/.dockerconfigjson
- --report-credentials-file=/etc/report/credentials
- --target=derTest
command:
- ci-operator
image: quay-proxy.ci.openshift.org/openshift/ci:ci_ci-operator_latest
imagePullPolicy: Always
name: ""
resources:
requests:
cpu: 10m
volumeMounts:
- mountPath: /secrets/gcs
name: gcs-credentials
readOnly: true
- mountPath: /secrets/manifest-tool
name: manifest-tool-local-pusher
readOnly: true
- mountPath: /etc/pull-secret
name: pull-secret
readOnly: true
- mountPath: /etc/report
name: result-aggregator
readOnly: true
serviceAccountName: ci-operator
volumes:
- name: manifest-tool-local-pusher
secret:
secretName: manifest-tool-local-pusher
- name: pull-secret
secret:
secretName: registry-pull-credentials
- name: result-aggregator
secret:
secretName: result-aggregator
trigger: (?m)^/test( | .* )derTest,?($|\s.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
agent: kubernetes
always_run: true
branches:
- ^branch$
- ^branch-
context: ci/prow/testname
decorate: true
decoration_config:
skip_cloning: true
labels:
pj-rehearse.openshift.io/can-be-rehearsed: "true"
name: pull-ci-org-repo-branch-testname
rerun_command: /test testname
skip_branches:
- ^branch-foo$
- ^branch-bar$
trigger: (?m)^/test( | .* )testname,?($|\s.*)