Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/images
decorate: true
decoration_config:
Expand Down Expand Up @@ -50,7 +51,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/unit
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/rhel-images
decorate: true
decoration_config:
Expand Down Expand Up @@ -52,7 +53,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/rhel-unit
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/images
decorate: true
decoration_config:
Expand Down Expand Up @@ -50,7 +51,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/unit
decorate: true
decoration_config:
Expand Down
5 changes: 5 additions & 0 deletions pkg/jobconfig/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const (
PeriodicPrefix = "periodic"
)

// SimpleBranchRegexp matches a branch name that does not appear to be a regex (lacks wildcard,
// group, or other modifiers). For instance, `master` is considered simple, `master-.*` would
// not.
var SimpleBranchRegexp = regexp.MustCompile(`^[\w\-.]+$`)

// Info describes the metadata for a Prow job configuration file
type Info struct {
Org string
Expand Down
28 changes: 16 additions & 12 deletions pkg/prowgen/prowgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func generatePresubmitForTest(name string, info *ProwgenInfo, podSpec *corev1.Po
return &prowconfig.Presubmit{
JobBase: base,
AlwaysRun: true,
Brancher: prowconfig.Brancher{Branches: []string{info.Branch}},
Brancher: prowconfig.Brancher{Branches: sets.NewString(exactlyBranch(info.Branch), featureBranch(info.Branch)).List()},
Reporter: prowconfig.Reporter{
Context: fmt.Sprintf("ci/prow/%s", shortName),
},
Expand All @@ -458,7 +458,7 @@ func generatePostsubmitForTest(name string, info *ProwgenInfo, podSpec *corev1.P
base := generateJobBase(name, jc.PostsubmitPrefix, info, podSpec, false, pathAlias, jobRelease, skipCloning)
return &prowconfig.Postsubmit{
JobBase: base,
Brancher: prowconfig.Brancher{Branches: []string{makeBranchExplicit(info.Branch)}},
Brancher: prowconfig.Brancher{Branches: []string{exactlyBranch(info.Branch)}},
}
}

Expand Down Expand Up @@ -613,21 +613,25 @@ func generateJobBase(name, prefix string, info *ProwgenInfo, podSpec *corev1.Pod
return base
}

// simpleBranchRegexp matches a branch name that does not appear to be a regex (lacks wildcard,
// group, or other modifiers). For instance, `master` is considered simple, `master-.*` would
// not.
var simpleBranchRegexp = regexp.MustCompile(`^[\w\-.]+$`)

// makeBranchExplicit updates the provided branch to prevent wildcard matches to the given branch
// if the branch value does not appear to contain an explicit regex pattern. I.e. 'master'
// is turned into '^master$'.
func makeBranchExplicit(branch string) string {
if !simpleBranchRegexp.MatchString(branch) {
// exactlyBranch returns a regex string that matches exactly the given branch name: I.e. returns
// '^master$' for 'master'. If the given branch name already looks like a regex, return it unchanged.
func exactlyBranch(branch string) string {
if !jc.SimpleBranchRegexp.MatchString(branch) {
return branch
}
return fmt.Sprintf("^%s$", regexp.QuoteMeta(branch))
}

// featureBranch returns a regex string that matches feature branch prefixes for the given branch name:
// I.e. returns '^master-' for 'master'. If the given branch name already looks like a regex,
// return it unchanged.
func featureBranch(branch string) string {
if !jc.SimpleBranchRegexp.MatchString(branch) {
return branch
}
return fmt.Sprintf("^%s-", regexp.QuoteMeta(branch))
}

// IsGenerated returns true if the job was generated using prowgen
func IsGenerated(job prowconfig.JobBase) bool {
_, generated := job.Labels[prowJobLabelGenerated]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/images
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/also-testname
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/testname
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/testname
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
agent: kubernetes
always_run: true
branches:
- branch
- ^branch$
- ^branch-
context: ci/prow/testname
decorate: true
labels:
Expand Down
23 changes: 16 additions & 7 deletions pkg/rehearse/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@ func NewCMClient(clusterConfig *rest.Config, namespace string, dry bool) (corecl
// and we know that `\` is an invalid character in Git branch names, so any
// that exist in the name have been placed there by regexp.QuoteMeta() and
// can simply be removed as well.
// Iterates over all branches and returns an empty string when no branch
// is a simple branch name after the stripping
func BranchFromRegexes(branches []string) string {
return strings.ReplaceAll(strings.TrimPrefix(strings.TrimSuffix(branches[0], "$"), "^"), "\\", "")
for i := range branches {
branch := strings.ReplaceAll(strings.TrimPrefix(strings.TrimSuffix(branches[i], "$"), "^"), "\\", "")
if branch != "" && jobconfig.SimpleBranchRegexp.MatchString(branch) {
return branch
}
}

return ""
}

func makeRehearsalPresubmit(source *prowconfig.Presubmit, repo string, prNumber int, refs *pjapi.Refs) (*prowconfig.Presubmit, error) {
Expand Down Expand Up @@ -196,11 +205,6 @@ func filterPresubmits(changedPresubmits map[string][]prowconfig.Presubmit, logge
continue
}

if len(job.Branches) != 1 {
jobLogger.Warn("cannot rehearse jobs that run over multiple branches")
continue
}

presubmits.Add(repo, job, config.GetSourceType(job.Labels))
}
}
Expand Down Expand Up @@ -440,10 +444,15 @@ func (jc *JobConfigurer) ConfigurePresubmitRehearsals(presubmits config.Presubmi
if len(splitOrgRepo) != 2 {
jobLogger.WithError(fmt.Errorf("failed to identify org and repo from string %s", orgrepo)).Warn("Failed to inline ci-operator-config into rehearsal presubmit job")
}
branch := BranchFromRegexes(job.Branches)
if branch == "" {
jobLogger.Warn("failed to extract a simple branch name for a presubmit")
continue
}
metadata := api.Metadata{
Org: splitOrgRepo[0],
Repo: splitOrgRepo[1],
Branch: BranchFromRegexes(job.Branches),
Branch: branch,
Variant: VariantFromLabels(job.Labels),
}
testname := metadata.TestNameFromJobName(job.Name, jobconfig.PresubmitPrefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/unit
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/e2e
decorate: true
decoration_config:
Expand Down Expand Up @@ -84,7 +85,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/images
decorate: true
decoration_config:
Expand Down Expand Up @@ -140,7 +142,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/unit
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/test
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/ci-index
decorate: true
decoration_config:
Expand Down Expand Up @@ -50,7 +51,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/ci-index-my-bundle
decorate: true
decoration_config:
Expand Down Expand Up @@ -97,7 +99,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/e2e
decorate: true
decoration_config:
Expand Down Expand Up @@ -170,7 +173,8 @@ presubmits:
- agent: kubernetes
always_run: false
branches:
- master
- ^master$
- ^master-
context: ci/prow/images
decorate: true
decoration_config:
Expand Down Expand Up @@ -232,7 +236,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/lint
decorate: true
decoration_config:
Expand Down Expand Up @@ -279,7 +284,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/steps
decorate: true
decoration_config:
Expand Down Expand Up @@ -333,7 +339,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/unit
decorate: true
decoration_config:
Expand Down Expand Up @@ -380,7 +387,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/variant-images
decorate: true
decoration_config:
Expand Down Expand Up @@ -431,7 +439,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master
- ^master$
- ^master-
context: ci/prow/variant-unit
decorate: true
decoration_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ presubmits:
- agent: kubernetes
always_run: true
branches:
- master-removed-promotion
- ^master-removed-promotion$
- ^master-removed-promotion-
context: ci/prow/images
decorate: true
decoration_config:
Expand Down
Loading