@@ -11,7 +11,6 @@ import (
1111 "slices"
1212 "strconv"
1313 "strings"
14- "sync"
1514
1615 "github.com/openshift-knative/hack/pkg/dependabotgen"
1716 soversion "github.com/openshift-knative/hack/pkg/soversion"
@@ -41,8 +40,12 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
4140 return err
4241 }
4342
43+ soVersions , err := precomputeSOVersions (ctx , configs )
44+ if err != nil {
45+ return fmt .Errorf ("failed to pre-compute SO versions: %w" , err )
46+ }
47+
4448 eg := & errgroup.Group {}
45- soMutex := & sync.Mutex {}
4649
4750 for _ , config := range configs {
4851 config := config
@@ -52,12 +55,9 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
5255
5356 // Special case serverless-operator
5457 if r .IsServerlessOperator () {
55- soMutex .Lock ()
5658 if err := GenerateKonfluxServerlessOperator (ctx , openshiftRelease , r , config ); err != nil {
57- soMutex .Unlock ()
5859 return fmt .Errorf ("failed to generate konflux for %q: %w" , r .RepositoryDirectory (), err )
5960 }
60- soMutex .Unlock ()
6161 continue
6262 }
6363
@@ -112,38 +112,12 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
112112
113113 log .Printf ("targetBranch: %s, soBranchName: %s, soVersion: %s\n " , targetBranch , soBranchName , soVersion )
114114
115- soMutex .Lock ()
116- // Checkout s-o to get the right release version from project.yaml (e.g. 1.34.1)
117- soRepo := Repository {Org : "openshift-knative" , Repo : "serverless-operator" }
118- if err := GitMirror (ctx , soRepo ); err != nil {
119- return err
120- }
121-
122- versionLabel := soBranchName
123- var buildArgs []string
124- if err := GitCheckout (ctx , soRepo , soBranchName ); err != nil {
125- if ! strings .Contains (err .Error (), "failed to run git [checkout" ) {
126- soMutex .Unlock ()
127- return err
128- }
129- // For non-existent branches we use the `.0` patch version if soVersion is set.
130- if soVersion != nil {
131- versionLabel = soVersion .String ()
132- }
133- // For non-existent branches we keep going and use downstreamVersion for versionLabel.
134- } else {
135- soProjectYamlPath := filepath .Join (soRepo .RepositoryDirectory (),
136- "olm-catalog" , "serverless-operator" , "project.yaml" )
137- soMetadata , err := project .ReadMetadataFile (soProjectYamlPath )
138- if err != nil {
139- soMutex .Unlock ()
140- return err
141- }
142-
143- versionLabel = soMetadata .Project .Version
115+ versionLabel , ok := soVersions [soBranchName ]
116+ if ! ok {
117+ return fmt .Errorf ("no pre-computed SO version for branch %q" , soBranchName )
144118 }
145- soMutex .Unlock ()
146119 log .Println ("Version label:" , versionLabel )
120+ var buildArgs []string
147121 buildArgs = append (buildArgs , fmt .Sprintf ("VERSION=%s" , versionLabel ))
148122
149123 soConfig , loadErr := LoadConfig ("config/serverless-operator.yaml" )
@@ -278,6 +252,66 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
278252 return nil
279253}
280254
255+ // precomputeSOVersions mirrors the serverless-operator repo and extracts
256+ // the version label for each SO branch. Returns a map from soBranchName
257+ // (e.g. "release-1.35") to versionLabel (e.g. "1.35.1").
258+ // The "main" key maps to the version from SO's main branch project.yaml.
259+ func precomputeSOVersions (ctx context.Context , configs []* Config ) (map [string ]string , error ) {
260+ soRepo := Repository {Org : "openshift-knative" , Repo : "serverless-operator" }
261+ if err := GitMirror (ctx , soRepo ); err != nil {
262+ return nil , fmt .Errorf ("failed to mirror serverless-operator: %w" , err )
263+ }
264+
265+ // Collect all unique soBranchNames needed across all configs.
266+ needed := make (map [string ]* semver.Version ) // soBranchName -> soVersion (nil for "main")
267+ for _ , config := range configs {
268+ for _ , r := range config .Repositories {
269+ if r .IsServerlessOperator () {
270+ continue
271+ }
272+ for branchName , b := range config .Config .Branches {
273+ if b .Konflux == nil || ! b .Konflux .Enabled {
274+ continue
275+ }
276+ if branchName == "release-next" {
277+ needed ["main" ] = nil
278+ } else {
279+ soVersion := soversion .FromUpstreamVersion (branchName )
280+ soBranchName := soversion .BranchName (soVersion )
281+ needed [soBranchName ] = soVersion
282+ }
283+ }
284+ }
285+ }
286+
287+ // Resolve each SO branch to its version label.
288+ versions := make (map [string ]string , len (needed ))
289+ for soBranchName , soVersion := range needed {
290+ versionLabel := soBranchName
291+ if err := GitCheckout (ctx , soRepo , soBranchName ); err != nil {
292+ if ! strings .Contains (err .Error (), "failed to run git [checkout" ) {
293+ return nil , fmt .Errorf ("failed to checkout %s: %w" , soBranchName , err )
294+ }
295+ // Branch doesn't exist — use the .0 patch version if available.
296+ if soVersion != nil {
297+ versionLabel = soVersion .String ()
298+ }
299+ } else {
300+ soProjectYamlPath := filepath .Join (soRepo .RepositoryDirectory (),
301+ "olm-catalog" , "serverless-operator" , "project.yaml" )
302+ soMetadata , err := project .ReadMetadataFile (soProjectYamlPath )
303+ if err != nil {
304+ return nil , fmt .Errorf ("failed to read project.yaml for %s: %w" , soBranchName , err )
305+ }
306+ versionLabel = soMetadata .Project .Version
307+ }
308+ versions [soBranchName ] = versionLabel
309+ log .Printf ("Pre-computed SO version: %s -> %s\n " , soBranchName , versionLabel )
310+ }
311+
312+ return versions , nil
313+ }
314+
281315func writeDependabotConfig (ctx context.Context , dependabotConfig * dependabotgen.DependabotConfig , r Repository ) error {
282316 if dependabotConfig .Updates != nil && len (* dependabotConfig .Updates ) > 0 {
283317 if err := GitMirror (ctx , r ); err != nil {
0 commit comments