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
11 changes: 0 additions & 11 deletions .github/workflows/release-generate-ci-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /usr/local/lib/android || true
sudo rm -rf /opt/ghc || true
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
- name: Checkout openshift-knative/hack
uses: actions/checkout@v4
with:
Expand All @@ -42,16 +41,6 @@ jobs:
- name: Install yq
run: go install github.com/mikefarah/yq/v3@latest

- name: Install skopeo
run: go install -tags="exclude_graphdriver_btrfs containers_image_openpgp" github.com/containers/skopeo/cmd/skopeo@v1.16.1

- name: Install YAML2JSON
run: go install github.com/bronze1man/yaml2json@latest

- name: Convert configurations to JSON
working-directory: ./src/github.com/openshift-knative/hack
run: find config/*.yaml | xargs -I{} sh -c "yaml2json < {} > {}.json"

- name: Checkout openshift/release
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/release-generate-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ jobs:
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /usr/local/lib/android || true
sudo rm -rf /opt/ghc || true
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
- name: Checkout openshift-knative/hack
uses: actions/checkout@v4
with:
Expand All @@ -139,13 +138,6 @@ jobs:
uses: ./src/github.com/openshift-knative/hack/actions/setup-go
- name: Install yq
run: go install github.com/mikefarah/yq/v3@latest
- name: Install skopeo
run: go install -tags="exclude_graphdriver_btrfs containers_image_openpgp" github.com/containers/skopeo/cmd/skopeo@v1.16.1
- name: Install YAML2JSON
run: go install github.com/bronze1man/yaml2json@latest
- name: Convert configurations to JSON
working-directory: ./src/github.com/openshift-knative/hack
run: find config/*.yaml | xargs -I{} sh -c "yaml2json < {} > {}.json"
- name: Checkout openshift/release
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions actions/setup-go/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ runs:
uses: actions/setup-go@v6
with:
go-version: ${{ inputs.go-version || '1.25' }}
cache-dependency-path: '**/go.sum'
4 changes: 2 additions & 2 deletions pkg/prowgen/prowgen_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ func gitClone(ctx context.Context, r Repository, mirror bool) error {
remoteRepo := fmt.Sprintf("https://github.com/%s/%s.git", r.Org, r.Repo)
if mirror {
log.Println("Mirroring repository", r.RepositoryDirectory())
if _, err := runNoRepo(ctx, "git", "clone", "--mirror", remoteRepo, filepath.Join(r.RepositoryDirectory(), ".git")); err != nil {
if _, err := runNoRepo(ctx, "git", "clone", "--bare", "--no-tags", remoteRepo, filepath.Join(r.RepositoryDirectory(), ".git")); err != nil {
return fmt.Errorf("[%s] failed to clone repository: %w", r.RepositoryDirectory(), err)
}
if _, err := Run(ctx, r, "git", "config", "--bool", "core.bare", "false"); err != nil {
return fmt.Errorf("[%s] failed to set config for repository: %w", r.RepositoryDirectory(), err)
}
} else {
log.Println("Cloning repository", r.RepositoryDirectory())
if _, err := runNoRepo(ctx, "git", "clone", remoteRepo, r.RepositoryDirectory()); err != nil {
if _, err := runNoRepo(ctx, "git", "clone", "--no-tags", remoteRepo, r.RepositoryDirectory()); err != nil {
return fmt.Errorf("[%s] failed to clone repository: %w", r.RepositoryDirectory(), err)
}
}
Expand Down
104 changes: 69 additions & 35 deletions pkg/prowgen/prowgen_konflux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"slices"
"strconv"
"strings"
"sync"

"github.com/openshift-knative/hack/pkg/dependabotgen"
soversion "github.com/openshift-knative/hack/pkg/soversion"
Expand Down Expand Up @@ -41,8 +40,12 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
return err
}

soVersions, err := precomputeSOVersions(ctx, configs)
if err != nil {
return fmt.Errorf("failed to pre-compute SO versions: %w", err)
}

eg := &errgroup.Group{}
soMutex := &sync.Mutex{}

for _, config := range configs {
config := config
Expand All @@ -52,12 +55,9 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [

// Special case serverless-operator
if r.IsServerlessOperator() {
soMutex.Lock()
if err := GenerateKonfluxServerlessOperator(ctx, openshiftRelease, r, config); err != nil {
soMutex.Unlock()
return fmt.Errorf("failed to generate konflux for %q: %w", r.RepositoryDirectory(), err)
}
soMutex.Unlock()
continue
}

Expand Down Expand Up @@ -112,38 +112,12 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [

log.Printf("targetBranch: %s, soBranchName: %s, soVersion: %s\n", targetBranch, soBranchName, soVersion)

soMutex.Lock()
// Checkout s-o to get the right release version from project.yaml (e.g. 1.34.1)
soRepo := Repository{Org: "openshift-knative", Repo: "serverless-operator"}
if err := GitMirror(ctx, soRepo); err != nil {
return err
}

versionLabel := soBranchName
var buildArgs []string
if err := GitCheckout(ctx, soRepo, soBranchName); err != nil {
if !strings.Contains(err.Error(), "failed to run git [checkout") {
soMutex.Unlock()
return err
}
// For non-existent branches we use the `.0` patch version if soVersion is set.
if soVersion != nil {
versionLabel = soVersion.String()
}
// For non-existent branches we keep going and use downstreamVersion for versionLabel.
} else {
soProjectYamlPath := filepath.Join(soRepo.RepositoryDirectory(),
"olm-catalog", "serverless-operator", "project.yaml")
soMetadata, err := project.ReadMetadataFile(soProjectYamlPath)
if err != nil {
soMutex.Unlock()
return err
}

versionLabel = soMetadata.Project.Version
versionLabel, ok := soVersions[soBranchName]
if !ok {
return fmt.Errorf("no pre-computed SO version for branch %q", soBranchName)
}
soMutex.Unlock()
log.Println("Version label:", versionLabel)
var buildArgs []string
buildArgs = append(buildArgs, fmt.Sprintf("VERSION=%s", versionLabel))

soConfig, loadErr := LoadConfig("config/serverless-operator.yaml")
Expand Down Expand Up @@ -278,6 +252,66 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
return nil
}

// precomputeSOVersions mirrors the serverless-operator repo and extracts
// the version label for each SO branch. Returns a map from soBranchName
// (e.g. "release-1.35") to versionLabel (e.g. "1.35.1").
// The "main" key maps to the version from SO's main branch project.yaml.
func precomputeSOVersions(ctx context.Context, configs []*Config) (map[string]string, error) {
soRepo := Repository{Org: "openshift-knative", Repo: "serverless-operator"}
if err := GitMirror(ctx, soRepo); err != nil {
return nil, fmt.Errorf("failed to mirror serverless-operator: %w", err)
}

// Collect all unique soBranchNames needed across all configs.
needed := make(map[string]*semver.Version) // soBranchName -> soVersion (nil for "main")
for _, config := range configs {
for _, r := range config.Repositories {
if r.IsServerlessOperator() {
continue
}
for branchName, b := range config.Config.Branches {
if b.Konflux == nil || !b.Konflux.Enabled {
continue
}
if branchName == "release-next" {
needed["main"] = nil
} else {
soVersion := soversion.FromUpstreamVersion(branchName)
soBranchName := soversion.BranchName(soVersion)
needed[soBranchName] = soVersion
}
}
}
}

// Resolve each SO branch to its version label.
versions := make(map[string]string, len(needed))
for soBranchName, soVersion := range needed {
versionLabel := soBranchName
if err := GitCheckout(ctx, soRepo, soBranchName); err != nil {
if !strings.Contains(err.Error(), "failed to run git [checkout") {
return nil, fmt.Errorf("failed to checkout %s: %w", soBranchName, err)
}
// Branch doesn't exist — use the .0 patch version if available.
if soVersion != nil {
versionLabel = soVersion.String()
}
} else {
soProjectYamlPath := filepath.Join(soRepo.RepositoryDirectory(),
"olm-catalog", "serverless-operator", "project.yaml")
soMetadata, err := project.ReadMetadataFile(soProjectYamlPath)
if err != nil {
return nil, fmt.Errorf("failed to read project.yaml for %s: %w", soBranchName, err)
}
versionLabel = soMetadata.Project.Version
}
versions[soBranchName] = versionLabel
log.Printf("Pre-computed SO version: %s -> %s\n", soBranchName, versionLabel)
}

return versions, nil
}

func writeDependabotConfig(ctx context.Context, dependabotConfig *dependabotgen.DependabotConfig, r Repository) error {
if dependabotConfig.Updates != nil && len(*dependabotConfig.Updates) > 0 {
if err := GitMirror(ctx, r); err != nil {
Expand Down