From 6fb305e868b4950afe044ac11fd14a2674f629c3 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Tue, 19 Dec 2023 13:10:12 +0100 Subject: [PATCH] ci(tests): run each test as a separate job --- .github/workflows/tests.yml | 20 ++++++++++++++++---- Makefile | 2 +- tests/suite_test.go | 7 +++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a21a1782d..de9f8a5c0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,19 +4,31 @@ on: workflow_dispatch: {} jobs: + list: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.list.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - id: list + run: | + echo "matrix=$(LIST_ONLY=1 go test ./tests/... -list=. | grep Test | jq -cnR '[inputs | select(length>0)]')" >> $GITHUB_OUTPUT test: runs-on: ubuntu-latest + needs: list strategy: + max-parallel: 5 matrix: - k8s-version: - - 1.24.10 + name: ${{ fromJson(needs.list.outputs.matrix) }} steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version-file: go.mod - - run: make test + - run: make test -run="^${{ matrix.name }}$" env: AIVEN_TOKEN: ${{ secrets.AIVEN_TOKEN }} AIVEN_PROJECT_NAME: ${{ secrets.AIVEN_PROJECT_NAME }} - ENVTEST_K8S_VERSION: ${{ matrix.k8s-version }} diff --git a/Makefile b/Makefile index db8619eb5..d883f331a 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ endif IMG ?= aivenoy/aiven-operator:${IMG_TAG} IMG_TAG ?= $(shell git rev-parse HEAD) # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.24.2 +ENVTEST_K8S_VERSION ?= 1.24.10 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) diff --git a/tests/suite_test.go b/tests/suite_test.go index 66f91993a..5d25b4f6c 100644 --- a/tests/suite_test.go +++ b/tests/suite_test.go @@ -37,6 +37,13 @@ const ( ) func TestMain(m *testing.M) { + if os.Getenv("LIST_ONLY") != "" { + // For go test ./... -list=. + // to get test names + m.Run() + return + } + err := setupSuite() if err != nil { log.Fatal(err)