Skip to content

Commit ca12533

Browse files
committed
Remove all tests before generating new ones
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
1 parent ce587d2 commit ca12533

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

  • cmd/gh-action-integration-generator

cmd/gh-action-integration-generator/main.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import (
88
"log"
99
"os"
1010
"os/exec"
11+
"path"
12+
"path/filepath"
1113
"strings"
1214
"text/template"
1315
)
1416

1517
var (
18+
githubWorkflowPath = "../../.github/workflows/"
1619
jobFileNameTemplate = `test-integration-v2-%s.yaml`
1720
jobTemplate = template.Must(
1821
template.New("jobTemplate").
@@ -79,6 +82,22 @@ jobs:
7982

8083
const workflowFilePerm = 0o600
8184

85+
func removeTests() {
86+
glob := fmt.Sprintf(jobFileNameTemplate, "*")
87+
88+
files, err := filepath.Glob(filepath.Join(githubWorkflowPath, glob))
89+
if err != nil {
90+
log.Fatalf("failed to find test files")
91+
}
92+
93+
for _, file := range files {
94+
err := os.Remove(file)
95+
if err != nil {
96+
log.Printf("failed to remove: %s", err)
97+
}
98+
}
99+
}
100+
82101
func findTests() []string {
83102
rgBin, err := exec.LookPath("rg")
84103
if err != nil {
@@ -121,6 +140,8 @@ func main() {
121140

122141
tests := findTests()
123142

143+
removeTests()
144+
124145
for _, test := range tests {
125146
log.Printf("generating workflow for %s", test)
126147

@@ -132,9 +153,9 @@ func main() {
132153
log.Fatalf("failed to render template: %s", err)
133154
}
134155

135-
path := "../../.github/workflows/" + fmt.Sprintf(jobFileNameTemplate, test)
156+
testPath := path.Join(githubWorkflowPath, fmt.Sprintf(jobFileNameTemplate, test))
136157

137-
err := os.WriteFile(path, content.Bytes(), workflowFilePerm)
158+
err := os.WriteFile(testPath, content.Bytes(), workflowFilePerm)
138159
if err != nil {
139160
log.Fatalf("failed to write github job: %s", err)
140161
}

0 commit comments

Comments
 (0)