mirror of
https://github.com/traefik/traefik.git
synced 2025-08-06 22:57:14 +02:00
feat: parallelise unit tests
This commit is contained in:
parent
cd16321dd9
commit
f174014d96
31
.github/workflows/test-unit.yaml
vendored
31
.github/workflows/test-unit.yaml
vendored
@ -14,8 +14,36 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
|
generate-packages:
|
||||||
|
name: List Go Packages
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Go ${{ env.GO_VERSION }}
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Generate matrix
|
||||||
|
id: set-matrix
|
||||||
|
run: |
|
||||||
|
matrix_output=$(go run ./internal/testsci/genmatrix.go)
|
||||||
|
echo "$matrix_output"
|
||||||
|
echo "$matrix_output" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
test-unit:
|
test-unit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: generate-packages
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
package: ${{ fromJson(needs.generate-packages.outputs.matrix) }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
@ -33,7 +61,8 @@ jobs:
|
|||||||
run: touch webui/static/index.html
|
run: touch webui/static/index.html
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: make test-unit
|
run: |
|
||||||
|
go test -v -parallel 8 ${{ matrix.package.group }}
|
||||||
|
|
||||||
test-ui-unit:
|
test-ui-unit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
66
internal/testsci/genmatrix.go
Normal file
66
internal/testsci/genmatrix.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/traefik/traefik/v2/pkg/log"
|
||||||
|
"golang.org/x/tools/go/packages"
|
||||||
|
)
|
||||||
|
|
||||||
|
const groupCount = 12
|
||||||
|
|
||||||
|
type group struct {
|
||||||
|
Group string `json:"group"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
logger := log.WithoutContext()
|
||||||
|
|
||||||
|
cfg := &packages.Config{
|
||||||
|
Mode: packages.NeedName,
|
||||||
|
Dir: ".",
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgs, err := packages.Load(cfg, "./cmd/...", "./pkg/...")
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalf("Loading packages: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var packageNames []string
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
if pkg.PkgPath != "" {
|
||||||
|
packageNames = append(packageNames, pkg.PkgPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total := len(packageNames)
|
||||||
|
perGroup := (total + groupCount - 1) / groupCount
|
||||||
|
|
||||||
|
fmt.Fprintf(os.Stderr, "Total packages: %d\n", total)
|
||||||
|
fmt.Fprintf(os.Stderr, "Packages per group: %d\n", perGroup)
|
||||||
|
|
||||||
|
var matrix []group
|
||||||
|
for i := range groupCount {
|
||||||
|
start := i * perGroup
|
||||||
|
end := start + perGroup
|
||||||
|
if start >= total {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if end > total {
|
||||||
|
end = total
|
||||||
|
}
|
||||||
|
g := strings.Join(packageNames[start:end], " ")
|
||||||
|
matrix = append(matrix, group{Group: g})
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(matrix)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalf("Failed to marshal matrix: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output for GitHub Actions
|
||||||
|
fmt.Printf("matrix=%s\n", string(jsonBytes))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user