-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
66e0888
commit c8e6d06
Showing
7 changed files
with
988 additions
and
131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ settings.json | |
.idea | ||
.DS_Store | ||
kubeconfig | ||
.hack/chainsaw-matrix/chainsaw-matrix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"maps" | ||
"os" | ||
"path/filepath" | ||
"slices" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/kyverno/chainsaw/pkg/discovery" | ||
) | ||
|
||
const chunkSize = 12 | ||
|
||
type testSuite struct { | ||
Name string | ||
Pattern string | ||
Folder string | ||
Required bool | ||
} | ||
|
||
type values struct { | ||
TestSuites []testSuite | ||
} | ||
|
||
type payload struct { | ||
Values values | ||
} | ||
|
||
func main() { | ||
tests, err := discovery.DiscoverTests("chainsaw-test.yaml", nil, false, "../..") | ||
if err != nil { | ||
panic(err) | ||
} | ||
var paths []string | ||
for _, test := range tests { | ||
path, err := filepath.Rel("../..", test.BasePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
parts := strings.Split(path, "/") | ||
if len(parts) < 3 { | ||
panic("not enough folder parts: " + path) | ||
} | ||
if strings.HasSuffix(parts[0], "-cel") { | ||
continue | ||
} | ||
parts = parts[:len(parts)-1] | ||
paths = append(paths, strings.Join(parts, "/")) | ||
} | ||
suites := map[string][]string{} | ||
for _, path := range paths { | ||
parts := strings.Split(path, "/") | ||
root := strings.Join(parts[:len(parts)-1], "/") | ||
suites[root] = append(suites[root], parts[len(parts)-1]) | ||
} | ||
var ts []testSuite | ||
for _, key := range slices.Sorted(maps.Keys(suites)) { | ||
root := "" | ||
for _, part := range strings.Split(key, "/") { | ||
root += "^" + part + "$" + "/" | ||
} | ||
slices.Sort(suites[key]) | ||
for i := 0; i < len(suites[key]); i += chunkSize { | ||
end := i + chunkSize | ||
if end > len(suites[key]) { | ||
end = len(suites[key]) | ||
} | ||
pattern := root + "^" + "(" + strings.Join(suites[key][i:end], "|") + ")" + "$" | ||
name := strings.ReplaceAll(key, "/", "_") | ||
if i >= chunkSize { | ||
name = fmt.Sprintf("%s-%d", name, i) | ||
} | ||
ts = append(ts, testSuite{ | ||
Required: true, | ||
Name: name, | ||
Folder: key, | ||
Pattern: pattern, | ||
}) | ||
} | ||
} | ||
var tmplFile = "workflow.yaml" | ||
tmpl, err := template.New(tmplFile).ParseFiles(tmplFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = tmpl.Execute(os.Stdout, payload{ | ||
Values: values{ | ||
TestSuites: ts, | ||
}, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | ||
|
||
name: E2E Tests | ||
|
||
permissions: {} | ||
|
||
on: | ||
workflow_dispatch: {} | ||
pull_request: | ||
branches: | ||
- 'main' | ||
|
||
concurrency: | ||
group: {{ print "${{ github.workflow }}-${{ github.ref }}" }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
{{- range .Values.TestSuites }} | ||
{{ .Name }}: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
k8s-version: [ v1.28.13, v1.29.8, v1.30.4, v1.31.0 ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
- name: Setup Environment | ||
uses: ./.github/actions/setup-env | ||
with: | ||
k8s-version: {{ print "${{ matrix.k8s-version }}" }} | ||
- name: Run Tests | ||
uses: ./.github/actions/run-tests | ||
with: | ||
tests: {{ .Pattern }} | ||
{{- end }} | ||
e2e-required-success: | ||
name: e2e-required | ||
needs: | ||
{{- range .Values.TestSuites }} | ||
- {{ .Name }} | ||
{{- end }} | ||
runs-on: ubuntu-latest | ||
if: {{ print "${{ success() }}" }} | ||
steps: | ||
- run: {{ print "${{ true }}" }} | ||
e2e-required-failure: | ||
name: e2e-required | ||
needs: | ||
{{- range .Values.TestSuites }} | ||
- {{ .Name }} | ||
{{- end }} | ||
runs-on: ubuntu-latest | ||
if: {{ print "${{ failure() || cancelled() }}" }} | ||
steps: | ||
- run: {{ print "${{ false }}" }} |
This file was deleted.
Oops, something went wrong.