Last active
October 1, 2020 07:57
-
-
Save mjudeikis/08582e888ad33c9f3a2a7fd9512f4053 to your computer and use it in GitHub Desktop.
job generation hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"strings" | |
"gopkg.in/yaml.v2" | |
) | |
// usage: | |
// go run jobs.go -f openshift-openshift-azure-infra-periodics.yaml,openshift-openshift-azure-master-periodics.yaml,openshift-openshift-azure-master-postsubmits.yaml,openshift-openshift-azure-master-presubmits.yaml,openshift-openshift-azure-release-v15-presubmits.yaml,openshift-openshift-azure-release-v16-presubmits.yaml,openshift-openshift-azure-release-v17-presubmits.yaml,openshift-openshift-azure-release-v19-presubmits.yaml,openshift-openshift-azure-release-v20-presubmits.yaml > jobs.txt | |
func main() { | |
fmt.Println("Parsing YAML file") | |
var filesName string | |
flag.StringVar(&filesName, "f", "", "YAML files to parse.") | |
flag.Parse() | |
if filesName == "" { | |
fmt.Println("Please provide yaml files by using -f option separate by ,") | |
return | |
} | |
files := strings.Split(filesName, ",") | |
for _, f := range files { | |
yamlFile, err := ioutil.ReadFile(f) | |
if err != nil { | |
fmt.Printf("Error reading YAML file: %s\n", err) | |
return | |
} | |
var yamlConfig map[string]interface{} | |
err = yaml.Unmarshal(yamlFile, &yamlConfig) | |
if err != nil { | |
fmt.Printf("Error parsing YAML file: %s\n", err) | |
} | |
if _, ok := yamlConfig["periodics"]; ok { | |
printName(yamlConfig["periodics"].([]interface{})) | |
} | |
if _, ok := yamlConfig["postsubmits"]; ok { | |
printName(yamlConfig["postsubmits"].(map[interface{}]interface{})["openshift/openshift-azure"].([]interface{})) | |
} | |
if _, ok := yamlConfig["presubmits"]; ok { | |
printName(yamlConfig["presubmits"].(map[interface{}]interface{})["openshift/openshift-azure"].([]interface{})) | |
} | |
} | |
} | |
func printName(jobs []interface{}) { | |
for _, job := range jobs { | |
j := job.(map[interface{}]interface{})["name"] | |
if j != "verify" { | |
fmt.Println(j) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment