Skip to content

Commit ad4d383

Browse files
author
Hector Vido
committed
Respecting always_run from config file
1 parent dc25f3d commit ad4d383

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

cmd/ci-operator-prowgen/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
prowgen
2+
=======
3+
4+
Prowgen is a tool that converts [ci-operator configuration](https://docs.ci.openshift.org/docs/architecture/ci-operator/)
5+
into [Prowjobs](https://docs.prow.k8s.io/docs/jobs/).
6+
7+
The objetive is to avoid tailored `Prowjobs` and made `ci-operator configuration` the only
8+
source of truth for jobs created based on configurations inside `openshift/ci-operator/config/`.
9+
10+
Prowgen is normally executed by `make update/make jobs` inside `openshift/release` folder.
11+
12+
Testing
13+
-------
14+
15+
`Prowgen` is hardcoded to use `GOPATH` + `src/github.com/openshift/release`, if you want to test it on your machine
16+
you can use a symbolic link ponting to your `openshift/release` clone:
17+
18+
```bash
19+
# generally GOPATH=~/go
20+
ln -s ~/cloned-repos/openshift/release ~/go/src/github.com/openshift/release
21+
```
22+
23+
Then you can execute `ci-operator-prowgen`:
24+
25+
```bash
26+
ci-operator-prowgen \
27+
--from-release-repo \
28+
--to-release-repo \
29+
--known-infra-file infra-build-farm-periodics.yaml \
30+
--known-infra-file infra-periodics.yaml \
31+
--known-infra-file infra-image-mirroring.yaml \
32+
--known-infra-file infra-periodics-origin-release-images.yam
33+
```

cmd/ci-operator-prowgen/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func writeToDir(dir string, c map[string]*prowconfig.JobConfig) error {
195195
errCh := make(chan error)
196196
map_ := func() error {
197197
for x := range ch {
198-
i := strings.Index(x.k, "/")
199-
org, repo := x.k[:i], x.k[i+1:]
198+
i := strings.Split(x.k, "/")
199+
org, repo := i[0], i[1]
200200
if err := jc.WriteToDir(dir, org, repo, x.v, prowgen.Generator, nil); err != nil {
201201
errCh <- err
202202
}

pkg/jobconfig/files.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func WriteToDir(jobDir, org, repo string, jobConfig *prowconfig.JobConfig, gener
365365
return nil
366366
}
367367

368-
// Given two JobConfig, merge jobs from the `source` one to to `destination`
368+
// Given two JobConfig, merge jobs from the `source` one to `destination`
369369
// one. Jobs are matched by name. All jobs from `source` will be present in
370370
// `destination` - if there were jobs with the same name in `destination`, they
371371
// will be updated. All jobs in `destination` that are not overwritten this
@@ -471,7 +471,6 @@ func mergeJobConfig(destination, source *prowconfig.JobConfig, allJobs sets.Set[
471471
func mergePresubmits(old, new *prowconfig.Presubmit) prowconfig.Presubmit {
472472
merged := *new
473473

474-
merged.AlwaysRun = old.AlwaysRun
475474
merged.RunIfChanged = old.RunIfChanged
476475
merged.SkipIfOnlyChanged = old.SkipIfOnlyChanged
477476
merged.MaxConcurrency = old.MaxConcurrency

pkg/prowgen/prowgen.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ type generatePresubmitOptions struct {
216216
disableRehearsal bool
217217
}
218218

219+
func (opts *generatePresubmitOptions) shouldAlwaysRun() bool {
220+
return opts.runIfChanged == "" && opts.skipIfOnlyChanged == "" && !opts.defaultDisable && opts.pipelineRunIfChanged == ""
221+
}
222+
219223
type generatePresubmitOption func(options *generatePresubmitOptions)
220224

221225
func generatePresubmitForTest(jobBaseBuilder *prowJobBaseBuilder, name string, info *ProwgenInfo, options ...generatePresubmitOption) *prowconfig.Presubmit {
@@ -240,7 +244,7 @@ func generatePresubmitForTest(jobBaseBuilder *prowJobBaseBuilder, name string, i
240244
}
241245
pj := &prowconfig.Presubmit{
242246
JobBase: base,
243-
AlwaysRun: opts.runIfChanged == "" && opts.skipIfOnlyChanged == "" && !opts.defaultDisable && opts.pipelineRunIfChanged == "",
247+
AlwaysRun: opts.shouldAlwaysRun(),
244248
Brancher: prowconfig.Brancher{Branches: sets.List(sets.New[string](jc.ExactlyBranch(info.Branch), jc.FeatureBranch(info.Branch)))},
245249
Reporter: prowconfig.Reporter{
246250
Context: fmt.Sprintf("ci/prow/%s", shortName),

0 commit comments

Comments
 (0)