mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-26 08:53:05 +00:00
Remove all tests before generating new ones
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
ce587d2421
commit
00fbd8dd93
1 changed files with 23 additions and 2 deletions
|
@ -8,11 +8,14 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
githubWorkflowPath = "../../.github/workflows/"
|
||||||
jobFileNameTemplate = `test-integration-v2-%s.yaml`
|
jobFileNameTemplate = `test-integration-v2-%s.yaml`
|
||||||
jobTemplate = template.Must(
|
jobTemplate = template.Must(
|
||||||
template.New("jobTemplate").
|
template.New("jobTemplate").
|
||||||
|
@ -79,6 +82,22 @@ jobs:
|
||||||
|
|
||||||
const workflowFilePerm = 0o600
|
const workflowFilePerm = 0o600
|
||||||
|
|
||||||
|
func removeTests() {
|
||||||
|
glob := fmt.Sprintf(jobFileNameTemplate, "*")
|
||||||
|
|
||||||
|
files, err := filepath.Glob(filepath.Join(githubWorkflowPath, glob))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to find test files")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
err := os.Remove(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to remove: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func findTests() []string {
|
func findTests() []string {
|
||||||
rgBin, err := exec.LookPath("rg")
|
rgBin, err := exec.LookPath("rg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -121,6 +140,8 @@ func main() {
|
||||||
|
|
||||||
tests := findTests()
|
tests := findTests()
|
||||||
|
|
||||||
|
removeTests()
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
log.Printf("generating workflow for %s", test)
|
log.Printf("generating workflow for %s", test)
|
||||||
|
|
||||||
|
@ -132,9 +153,9 @@ func main() {
|
||||||
log.Fatalf("failed to render template: %s", err)
|
log.Fatalf("failed to render template: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
path := "../../.github/workflows/" + fmt.Sprintf(jobFileNameTemplate, test)
|
testPath := path.Join(githubWorkflowPath, fmt.Sprintf(jobFileNameTemplate, test))
|
||||||
|
|
||||||
err := os.WriteFile(path, content.Bytes(), workflowFilePerm)
|
err := os.WriteFile(testPath, content.Bytes(), workflowFilePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to write github job: %s", err)
|
log.Fatalf("failed to write github job: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue