diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index e70625f5e..ac926a0d5 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -13,11 +13,28 @@ on: - "LICENSE" jobs: + # Generate matrix of tags for all permutations of the tests + generate-matrix: + runs-on: ubuntu-latest + outputs: + tags: ${{ steps.generate.outputs.tags }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Generate tag combinations + id: generate + run: | + go run mage.go tags-matrix > tags.json + echo "::set-output name=tags::$(cat tags.json)" + shell: bash test: + needs: generate-matrix strategy: matrix: go-version: [1.22.x, 1.23.x] os: [ubuntu-latest] + build-flag: ${{ fromJson(needs.generate-matrix.outputs.tags) }} runs-on: ${{ matrix.os }} steps: - name: Checkout code @@ -28,7 +45,12 @@ jobs: go-version: ${{ matrix.go-version }} cache: true - name: Tests and coverage - run: go run mage.go coverage + run: | + mkdir build + go test -race -coverprofile=build/${{ matrix.build-flag }}.txt -covermode=atomic -coverpkg=./... ${{ matrix.build-flag }} ./... + go test -race -coverprofile=build/${{ matrix.build-flag }}-examples.txt -covermode=atomic -coverpkg=./... ${{ matrix.build-flag }} ./examples/http-server + go test -coverprofile=build/${{ matrix.build-flag }}-ftw.txt -covermode=atomic -coverpkg=./... ${{ matrix.build-flag }} ./testing/coreruleset + go tool cover -html=build/coverage.txt -o build/coverage.html" - name: "Codecov: General" uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4 if: ${{ matrix.go-version == '1.22.x' }} diff --git a/magefile.go b/magefile.go index 2bc87e1af..7b1d1d192 100644 --- a/magefile.go +++ b/magefile.go @@ -7,12 +7,14 @@ package main import ( + "encoding/json" "errors" "fmt" "io" "os" "os/exec" "path/filepath" + "strings" "github.com/magefile/mage/mg" "github.com/magefile/mage/sh" @@ -228,3 +230,42 @@ func Precommit() error { func Check() { mg.SerialDeps(Lint, Test) } + +// combinations generates all possible combinations of build tags +func combinations(tags []string) []string { + var result []string + n := len(tags) + for i := 0; i < (1 << n); i++ { + var combo []string + for j := 0; j < n; j++ { + if i&(1< 0 { + result = append(result, "-tags="+strings.Join(combo, ",")) + } else { + result = append(result, "") + } + } + return result +} + +// Generates a JSON output to stdout which contains all permutations of build tags for the project. +func TagsMatrix() error { + tags := []string{ + "coraza.rule.case_sensitive_args_keys", + "memoize_builders", + "coraza.rule.multiphase_valuation", + } + combos := combinations(tags) + + jsonData, err := json.Marshal(combos) + if err != nil { + fmt.Println("Error generating JSON:", err) + return nil + } + + fmt.Println(string(jsonData)) + return nil +}