gorgonia.org/gorgonia@v0.9.17/.github/workflows/main.go (about) 1 package main 2 3 import ( 4 "io" 5 "os" 6 "strings" 7 "text/template" 8 ) 9 10 const ( 11 latestGo = "1.16.x" 12 previousGo = "1.15.x" 13 ) 14 15 func main() { 16 workflowLinux, err := os.OpenFile("runner-github-ubuntu-amd64.yml", os.O_RDWR|os.O_CREATE, 0660) 17 if err != nil { 18 panic(err) 19 } 20 defer workflowLinux.Close() 21 workflowMac, err := os.OpenFile("runner-github-macos-amd64.yml", os.O_RDWR|os.O_CREATE, 0660) 22 if err != nil { 23 panic(err) 24 } 25 defer workflowMac.Close() 26 workflowSelf, err := os.OpenFile("runner-self-hosted.yml", os.O_RDWR|os.O_CREATE, 0660) 27 if err != nil { 28 panic(err) 29 } 30 defer workflowSelf.Close() 31 32 err = generateWorkflow(workflowLinux, "Build and Tests on Linux/amd64", "Linux/amd64", "ubuntu-latest", map[string]bool{ 33 "none": false, 34 "avx": false, 35 "sse": false, 36 }, true) 37 if err != nil { 38 panic(err) 39 } 40 err = generateWorkflow(workflowMac, "Build and Tests on MacOS/amd64", "MacOS/amd64", "macos-latest", map[string]bool{ 41 "none": false, 42 "avx": false, 43 "sse": false, 44 }, false) 45 if err != nil { 46 panic(err) 47 } 48 err = generateWorkflow(workflowSelf, "Build and Tests on Self-Hosted (arm)", "Self-Hosted", "self-hosted", map[string]bool{ 49 "none": false, 50 }, false) 51 if err != nil { 52 panic(err) 53 } 54 55 } 56 57 func generateWorkflow(w io.Writer, workflowName, runnerName, runsOn string, tags map[string]bool, withRace bool) error { 58 tmpl, err := template.New("workflow").Funcs(template.FuncMap{ 59 "mapToList": mapToList, 60 "hasExperimental": hasExperimental, 61 }).Parse(workflowTmpl) 62 if err != nil { 63 panic(err) 64 } 65 66 return tmpl.Execute(w, workflow{ 67 WorkflowName: workflowName, 68 Jobs: []job{ 69 { 70 JobID: "stable-go", 71 JobName: "Build and test on latest stable Go release - " + runnerName, 72 RunsOn: runsOn, 73 GoVersion: latestGo, 74 Tags: tags, 75 WithRace: withRace, 76 }, 77 { 78 JobID: "previous-go", 79 JobName: "Build and test on previous stable Go release - " + runnerName, 80 RunsOn: runsOn, 81 GoVersion: previousGo, 82 Tags: tags, 83 WithRace: withRace, 84 }, 85 }, 86 }) 87 } 88 89 func mapToList(m map[string]bool) string { 90 var b strings.Builder 91 for tag := range m { 92 b.WriteString(tag) 93 b.WriteString(",") 94 } 95 s := b.String() // no copying 96 s = s[:b.Len()-1] // no copying (removes trailing ", ") 97 return s 98 99 } 100 101 func hasExperimental(m map[string]bool) bool { 102 for _, ok := range m { 103 if ok { 104 return true 105 } 106 } 107 return false 108 }