Skip to content

Commit

Permalink
generator
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Aug 29, 2024
1 parent 66e0888 commit c8e6d06
Show file tree
Hide file tree
Showing 7 changed files with 988 additions and 131 deletions.
902 changes: 833 additions & 69 deletions .github/workflows/test.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ settings.json
.idea
.DS_Store
kubeconfig
.hack/chainsaw-matrix/chainsaw-matrix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kyverno/policies/hack/chainsaw-matrix

go 1.22.2
go 1.23.0

require github.com/kyverno/chainsaw v0.2.8

Expand Down
File renamed without changes.
97 changes: 97 additions & 0 deletions .hack/chainsaw-matrix/main.go
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)
}
}
56 changes: 56 additions & 0 deletions .hack/chainsaw-matrix/workflow.yaml
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 }}" }}
61 changes: 0 additions & 61 deletions hack/chainsaw-matrix/main.go

This file was deleted.

0 comments on commit c8e6d06

Please sign in to comment.