Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Or Shoval <oshoval@redhat.com>
  • Loading branch information
oshoval committed Dec 13, 2023
1 parent 9bb2a11 commit 195ecbe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
2 changes: 2 additions & 0 deletions releng/release-tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ go_library(
deps = [
"@com_github_google_go_github_v32//github:go_default_library",
"@com_github_masterminds_semver//:go_default_library",
"@in_gopkg_yaml_v3//:go_default_library",
"@io_k8s_test_infra//prow/config:go_default_library",
"@org_golang_x_oauth2//:go_default_library",
],
)
Expand Down
61 changes: 58 additions & 3 deletions releng/release-tool/release-tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
"strings"
"time"

"golang.org/x/oauth2"

"github.com/Masterminds/semver"
"github.com/google/go-github/v32/github"
"golang.org/x/oauth2"
"gopkg.in/yaml.v3"

"k8s.io/test-infra/prow/config"
)

type blockerListCacheEntry struct {
Expand Down Expand Up @@ -414,8 +416,11 @@ func (r *releaseData) forkProwJobs() error {

// create new prow configs if they don't already exist
if _, err := os.Stat(fullOutputConfig); err != nil && os.IsNotExist(err) {
updateJobConfig, err := updatePhase2Jobs(r.org, r.repo, fullJobConfig)
defer os.Remove(updateJobConfig)

log.Printf("Creating new prow yaml at path %s", fullOutputConfig)
cmd := exec.Command("/usr/bin/config-forker", "--job-config", fullJobConfig, "--version", version, "--output", fullOutputConfig)
cmd := exec.Command("/usr/bin/config-forker", "--job-config", updateJobConfig, "--version", version, "--output", fullOutputConfig)
bytes, err := cmd.CombinedOutput()
if err != nil {
log.Printf("ERROR: config-forker command output: %s : %s ", string(bytes), err)
Expand Down Expand Up @@ -1271,3 +1276,53 @@ func main() {
}
}
}

func updatePhase2Jobs(org, repo, fullJobConfig string) (string, error) {
prowConfigTmp, err := createEmptyTmpFile()
if err != nil {
return "", err
}
defer os.Remove(prowConfigTmp)

pc, err := config.Load(prowConfigTmp, fullJobConfig, nil, "")
if err != nil {
return "", err
}

orgRepo := org + "/" + repo
for key, jobs := range pc.PresubmitsStatic {
if key != orgRepo {
continue
}
for i, job := range jobs {
if job.AlwaysRun == false &&
job.Optional == false &&
job.RegexpChangeMatcher.RunIfChanged == "" &&
job.RegexpChangeMatcher.SkipIfOnlyChanged == "" {
pc.PresubmitsStatic[key][i].AlwaysRun = true
}
}
}

yamlData, err := yaml.Marshal(pc)
if err != nil {
return "", err
}

updateJobConfig := os.TempDir() + "/job-config.yaml"
err = ioutil.WriteFile(updateJobConfig, yamlData, 0644)
if err != nil {
return "", err
}
return updateJobConfig, err
}

func createEmptyTmpFile() (string, error) {
tmpFile, err := os.CreateTemp("", "dummy-config")
if err != nil {
return "", err
}
defer tmpFile.Close()

return tmpFile.Name(), nil
}

0 comments on commit 195ecbe

Please sign in to comment.