2021-01-06 17:25:50 +03:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Vitess Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
workflowConfigDir = "../.github/workflows"
|
|
|
|
|
|
|
|
unitTestTemplate = "templates/unit_test.tpl"
|
2021-04-14 22:58:04 +03:00
|
|
|
unitTestDatabases = "percona56, mysql57, mysql80, mariadb101, mariadb103"
|
2021-01-06 17:25:50 +03:00
|
|
|
|
2021-02-05 23:21:39 +03:00
|
|
|
clusterTestTemplate = "templates/cluster_endtoend_test.tpl"
|
2021-03-02 12:56:44 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
clusterList = []string{
|
|
|
|
"11",
|
|
|
|
"12",
|
|
|
|
"13",
|
|
|
|
"14",
|
|
|
|
"15",
|
|
|
|
"16",
|
|
|
|
"17",
|
|
|
|
"18",
|
|
|
|
"19",
|
|
|
|
"20",
|
|
|
|
"21",
|
|
|
|
"22",
|
|
|
|
"23",
|
|
|
|
"24",
|
|
|
|
"26",
|
|
|
|
"27",
|
|
|
|
"vreplication_basic",
|
|
|
|
"vreplication_multicell",
|
|
|
|
"vreplication_cellalias",
|
|
|
|
"vreplication_v2",
|
|
|
|
"onlineddl_ghost",
|
|
|
|
"onlineddl_vrepl",
|
|
|
|
"onlineddl_vrepl_stress",
|
2021-03-03 08:18:21 +03:00
|
|
|
"vreplication_migrate",
|
2021-03-07 10:39:46 +03:00
|
|
|
"onlineddl_revert",
|
2021-03-18 14:42:54 +03:00
|
|
|
"onlineddl_declarative",
|
2021-03-07 13:04:25 +03:00
|
|
|
"tabletmanager_throttler",
|
|
|
|
"tabletmanager_throttler_custom_config",
|
2021-03-02 12:56:44 +03:00
|
|
|
}
|
2021-01-07 00:46:42 +03:00
|
|
|
// TODO: currently some percona tools including xtrabackup are installed on all clusters, we can possibly optimize
|
|
|
|
// this by only installing them in the required clusters
|
|
|
|
clustersRequiringXtraBackup = clusterList
|
2021-03-02 12:56:44 +03:00
|
|
|
clustersRequiringMakeTools = []string{
|
|
|
|
"18",
|
|
|
|
"24",
|
|
|
|
}
|
2021-01-06 17:25:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type unitTest struct {
|
2021-02-05 23:05:29 +03:00
|
|
|
Name, Platform string
|
2021-01-06 17:25:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type clusterTest struct {
|
|
|
|
Name, Shard string
|
|
|
|
MakeTools, InstallXtraBackup bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func mergeBlankLines(buf *bytes.Buffer) string {
|
|
|
|
var out []string
|
|
|
|
in := strings.Split(buf.String(), "\n")
|
|
|
|
lastWasBlank := false
|
|
|
|
for _, line := range in {
|
|
|
|
if strings.TrimSpace(line) == "" {
|
|
|
|
if lastWasBlank {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lastWasBlank = true
|
|
|
|
} else {
|
|
|
|
lastWasBlank = false
|
|
|
|
}
|
|
|
|
|
|
|
|
out = append(out, line)
|
|
|
|
}
|
|
|
|
return strings.Join(out, "\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
generateUnitTestWorkflows()
|
|
|
|
generateClusterWorkflows()
|
|
|
|
}
|
|
|
|
|
2021-03-02 12:56:44 +03:00
|
|
|
func canonnizeList(list []string) []string {
|
|
|
|
var output []string
|
|
|
|
for _, item := range list {
|
|
|
|
item = strings.TrimSpace(item)
|
|
|
|
if item != "" {
|
|
|
|
output = append(output, item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|
2021-01-06 17:25:50 +03:00
|
|
|
func parseList(csvList string) []string {
|
|
|
|
var list []string
|
|
|
|
for _, item := range strings.Split(csvList, ",") {
|
|
|
|
list = append(list, strings.TrimSpace(item))
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateClusterWorkflows() {
|
2021-03-02 12:56:44 +03:00
|
|
|
clusters := canonnizeList(clusterList)
|
2021-01-06 17:25:50 +03:00
|
|
|
for _, cluster := range clusters {
|
|
|
|
test := &clusterTest{
|
|
|
|
Name: fmt.Sprintf("Cluster (%s)", cluster),
|
|
|
|
Shard: cluster,
|
|
|
|
}
|
2021-03-02 12:56:44 +03:00
|
|
|
makeToolClusters := canonnizeList(clustersRequiringMakeTools)
|
2021-01-06 17:25:50 +03:00
|
|
|
for _, makeToolCluster := range makeToolClusters {
|
|
|
|
if makeToolCluster == cluster {
|
|
|
|
test.MakeTools = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-03-02 12:56:44 +03:00
|
|
|
xtraBackupClusters := canonnizeList(clustersRequiringXtraBackup)
|
2021-01-06 17:25:50 +03:00
|
|
|
for _, xtraBackupCluster := range xtraBackupClusters {
|
|
|
|
if xtraBackupCluster == cluster {
|
|
|
|
test.InstallXtraBackup = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path := fmt.Sprintf("%s/cluster_endtoend_%s.yml", workflowConfigDir, cluster)
|
|
|
|
generateWorkflowFile(clusterTestTemplate, path, test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateUnitTestWorkflows() {
|
2021-01-11 00:42:47 +03:00
|
|
|
platforms := parseList(unitTestDatabases)
|
2021-01-06 17:25:50 +03:00
|
|
|
for _, platform := range platforms {
|
|
|
|
test := &unitTest{
|
|
|
|
Name: fmt.Sprintf("Unit Test (%s)", platform),
|
2021-02-05 23:05:29 +03:00
|
|
|
Platform: platform,
|
2021-01-06 17:25:50 +03:00
|
|
|
}
|
|
|
|
path := fmt.Sprintf("%s/unit_test_%s.yml", workflowConfigDir, platform)
|
|
|
|
generateWorkflowFile(unitTestTemplate, path, test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateWorkflowFile(templateFile, path string, test interface{}) {
|
|
|
|
tpl, err := template.ParseFiles(templateFile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error: %s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
err = tpl.Execute(buf, test)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error: %s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := os.Create(path)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Error creating file: ", err)
|
|
|
|
return
|
|
|
|
}
|
2021-02-07 02:46:39 +03:00
|
|
|
f.WriteString("# DO NOT MODIFY: THIS FILE IS GENERATED USING \"make generate_ci_workflows\"\n\n")
|
2021-01-06 17:25:50 +03:00
|
|
|
f.WriteString(mergeBlankLines(buf))
|
|
|
|
fmt.Printf("Generated %s\n", path)
|
|
|
|
|
|
|
|
}
|