2023-01-05 08:08:40 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
//go:generate go run ./main.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2023-01-31 10:47:06 -07:00
|
|
|
"os/exec"
|
2023-02-02 09:02:27 -07:00
|
|
|
"path"
|
|
|
|
"path/filepath"
|
2023-01-31 10:47:06 -07:00
|
|
|
"strings"
|
2023-01-05 08:08:40 -07:00
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-02-02 09:02:27 -07:00
|
|
|
githubWorkflowPath = "../../.github/workflows/"
|
2023-01-05 08:08:40 -07:00
|
|
|
jobFileNameTemplate = `test-integration-v2-%s.yaml`
|
2023-01-31 10:47:25 -07:00
|
|
|
jobTemplate = template.Must(
|
|
|
|
template.New("jobTemplate").
|
|
|
|
Parse(`# DO NOT EDIT, generated with cmd/gh-action-integration-generator/main.go
|
2023-01-05 08:08:40 -07:00
|
|
|
# To regenerate, run "go generate" in cmd/gh-action-integration-generator/
|
|
|
|
|
|
|
|
name: Integration Test v2 - {{.Name}}
|
|
|
|
|
|
|
|
on: [pull_request]
|
|
|
|
|
2023-01-30 02:20:08 -07:00
|
|
|
concurrency:
|
|
|
|
group: {{ "${{ github.workflow }}-$${{ github.head_ref || github.run_id }}" }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
2023-01-05 08:08:40 -07:00
|
|
|
jobs:
|
2023-08-29 00:33:33 -06:00
|
|
|
{{.Name}}:
|
2023-01-05 08:08:40 -07:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 2
|
|
|
|
|
2023-06-28 04:56:35 -06:00
|
|
|
- uses: DeterminateSystems/nix-installer-action@main
|
|
|
|
- uses: DeterminateSystems/magic-nix-cache-action@main
|
|
|
|
- uses: satackey/action-docker-layer-caching@main
|
|
|
|
continue-on-error: true
|
|
|
|
|
2023-01-05 08:08:40 -07:00
|
|
|
- name: Get changed files
|
|
|
|
id: changed-files
|
|
|
|
uses: tj-actions/changed-files@v34
|
|
|
|
with:
|
|
|
|
files: |
|
|
|
|
*.nix
|
|
|
|
go.*
|
|
|
|
**/*.go
|
|
|
|
integration_test/
|
|
|
|
config-example.yaml
|
|
|
|
|
2023-08-29 00:33:33 -06:00
|
|
|
- name: Run {{.Name}}
|
2023-01-05 08:08:40 -07:00
|
|
|
if: steps.changed-files.outputs.any_changed == 'true'
|
|
|
|
run: |
|
|
|
|
nix develop --command -- docker run \
|
|
|
|
--tty --rm \
|
|
|
|
--volume ~/.cache/hs-integration-go:/go \
|
|
|
|
--name headscale-test-suite \
|
|
|
|
--volume $PWD:$PWD -w $PWD/integration \
|
|
|
|
--volume /var/run/docker.sock:/var/run/docker.sock \
|
2023-01-30 02:20:08 -07:00
|
|
|
--volume $PWD/control_logs:/tmp/control \
|
2023-01-05 08:08:40 -07:00
|
|
|
golang:1 \
|
2023-05-10 04:10:33 -06:00
|
|
|
go run gotest.tools/gotestsum@latest -- ./... \
|
2023-01-05 08:08:40 -07:00
|
|
|
-tags ts2019 \
|
|
|
|
-failfast \
|
|
|
|
-timeout 120m \
|
|
|
|
-parallel 1 \
|
2023-01-06 07:40:03 -07:00
|
|
|
-run "^{{.Name}}$"
|
2023-01-30 02:20:08 -07:00
|
|
|
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
|
|
if: always() && steps.changed-files.outputs.any_changed == 'true'
|
|
|
|
with:
|
|
|
|
name: logs
|
|
|
|
path: "control_logs/*.log"
|
2023-04-27 08:57:11 -06:00
|
|
|
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
|
|
if: always() && steps.changed-files.outputs.any_changed == 'true'
|
|
|
|
with:
|
|
|
|
name: pprof
|
|
|
|
path: "control_logs/*.pprof.tar"
|
2023-01-31 10:47:06 -07:00
|
|
|
`),
|
|
|
|
)
|
2023-01-05 08:08:40 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const workflowFilePerm = 0o600
|
|
|
|
|
2023-02-02 09:02:27 -07:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 10:47:06 -07: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",
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("executing: %s %s", rgBin, strings.Join(args, " "))
|
|
|
|
|
|
|
|
ripgrep := exec.Command(
|
|
|
|
rgBin,
|
|
|
|
args...,
|
|
|
|
)
|
|
|
|
|
|
|
|
result, err := ripgrep.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("out: %s", result)
|
|
|
|
log.Fatalf("failed to run ripgrep: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := strings.Split(string(result), "\n")
|
|
|
|
tests = tests[:len(tests)-1]
|
|
|
|
|
|
|
|
return tests
|
|
|
|
}
|
|
|
|
|
2023-01-05 08:08:40 -07:00
|
|
|
func main() {
|
|
|
|
type testConfig struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
2023-01-31 10:47:06 -07:00
|
|
|
tests := findTests()
|
2023-01-05 08:08:40 -07:00
|
|
|
|
2023-02-02 09:02:27 -07:00
|
|
|
removeTests()
|
|
|
|
|
2023-01-05 08:08:40 -07:00
|
|
|
for _, test := range tests {
|
2023-01-31 10:47:06 -07:00
|
|
|
log.Printf("generating workflow for %s", test)
|
|
|
|
|
2023-01-05 08:08:40 -07:00
|
|
|
var content bytes.Buffer
|
|
|
|
|
|
|
|
if err := jobTemplate.Execute(&content, testConfig{
|
|
|
|
Name: test,
|
|
|
|
}); err != nil {
|
|
|
|
log.Fatalf("failed to render template: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-02-02 09:02:27 -07:00
|
|
|
testPath := path.Join(githubWorkflowPath, fmt.Sprintf(jobFileNameTemplate, test))
|
2023-01-05 08:08:40 -07:00
|
|
|
|
2023-02-02 09:02:27 -07:00
|
|
|
err := os.WriteFile(testPath, content.Bytes(), workflowFilePerm)
|
2023-01-05 08:08:40 -07:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to write github job: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|