2023-01-05 10:08:40 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
//go:generate go run ./main.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2023-01-31 12:47:06 -05:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2023-01-05 10:08:40 -05:00
|
|
|
)
|
|
|
|
|
2023-01-31 12:47:06 -05: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 16:36:38 -05:00
|
|
|
cmd := exec.Command(rgBin, args...)
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
err = cmd.Run()
|
2023-01-31 12:47:06 -05:00
|
|
|
if err != nil {
|
2024-03-02 16:36:38 -05:00
|
|
|
log.Fatalf("failed to run command: %s", err)
|
2023-01-31 12:47:06 -05:00
|
|
|
}
|
|
|
|
|
2024-03-02 16:36:38 -05:00
|
|
|
tests := strings.Split(strings.TrimSpace(out.String()), "\n")
|
2023-01-31 12:47:06 -05:00
|
|
|
return tests
|
|
|
|
}
|
|
|
|
|
2024-03-02 16:36:38 -05:00
|
|
|
func updateYAML(tests []string) {
|
|
|
|
testsForYq := fmt.Sprintf("[%s]", strings.Join(tests, ", "))
|
2023-01-05 10:08:40 -05:00
|
|
|
|
2024-03-02 16:36:38 -05: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 13:31:29 -05:00
|
|
|
|
2024-03-02 16:36:38 -05: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 13:31:29 -05:00
|
|
|
|
2024-03-02 16:36:38 -05:00
|
|
|
fmt.Println("YAML file updated successfully")
|
|
|
|
}
|
2024-02-18 13:31:29 -05:00
|
|
|
|
2024-03-02 16:36:38 -05:00
|
|
|
func main() {
|
|
|
|
tests := findTests()
|
2024-02-18 13:31:29 -05:00
|
|
|
|
2024-03-02 16:36:38 -05:00
|
|
|
quotedTests := make([]string, len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
quotedTests[i] = fmt.Sprintf("\"%s\"", test)
|
2023-01-05 10:08:40 -05:00
|
|
|
}
|
2024-03-02 16:36:38 -05:00
|
|
|
|
|
|
|
updateYAML(quotedTests)
|
2023-01-05 10:08:40 -05:00
|
|
|
}
|