2023-01-05 16:08:40 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
//go:generate go run ./main.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2023-01-31 18:47:06 +01:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2023-01-05 16:08:40 +01:00
|
|
|
)
|
|
|
|
|
2023-01-31 18:47:06 +01:00
|
|
|
func findTests() []string {
|
|
|
|
rgBin, err := exec.LookPath("rg")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to find rg (ripgrep) binary")
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
"--regexp", "func (Test.+)\\(.*",
|
|
|
|
"../../integration/",
|
|
|
|
"--replace", "$1",
|
|
|
|
"--sort", "path",
|
|
|
|
"--no-line-number",
|
|
|
|
"--no-filename",
|
|
|
|
"--no-heading",
|
|
|
|
}
|
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
cmd := exec.Command(rgBin, args...)
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
err = cmd.Run()
|
2023-01-31 18:47:06 +01:00
|
|
|
if err != nil {
|
2024-03-02 22:36:38 +01:00
|
|
|
log.Fatalf("failed to run command: %s", err)
|
2023-01-31 18:47:06 +01:00
|
|
|
}
|
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
tests := strings.Split(strings.TrimSpace(out.String()), "\n")
|
2023-01-31 18:47:06 +01:00
|
|
|
return tests
|
|
|
|
}
|
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
func updateYAML(tests []string) {
|
|
|
|
testsForYq := fmt.Sprintf("[%s]", strings.Join(tests, ", "))
|
2023-01-05 16:08:40 +01:00
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
yqCommand := fmt.Sprintf(
|
|
|
|
"yq eval '.jobs.integration-test.strategy.matrix.test = %s' ../../.github/workflows/test-integration.yaml -i",
|
|
|
|
testsForYq,
|
|
|
|
)
|
|
|
|
cmd := exec.Command("bash", "-c", yqCommand)
|
2024-02-18 19:31:29 +01:00
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
var out bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to run yq command: %s", err)
|
|
|
|
}
|
2024-02-18 19:31:29 +01:00
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
fmt.Println("YAML file updated successfully")
|
|
|
|
}
|
2024-02-18 19:31:29 +01:00
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
func main() {
|
|
|
|
tests := findTests()
|
2024-02-18 19:31:29 +01:00
|
|
|
|
2024-03-02 22:36:38 +01:00
|
|
|
quotedTests := make([]string, len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
quotedTests[i] = fmt.Sprintf("\"%s\"", test)
|
2023-01-05 16:08:40 +01:00
|
|
|
}
|
2024-03-02 22:36:38 +01:00
|
|
|
|
|
|
|
updateYAML(quotedTests)
|
2023-01-05 16:08:40 +01:00
|
|
|
}
|