From d71d129e4ae5c2957dc0c11951b3e2fbfdd72de1 Mon Sep 17 00:00:00 2001 From: alanjino Date: Thu, 20 Jun 2024 22:03:59 +0530 Subject: [PATCH] unit-testcase execution in pr build --- .github/workflows/agent-container-pr.yml | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/agent-container-pr.yml b/.github/workflows/agent-container-pr.yml index e34509fb..cfec6621 100644 --- a/.github/workflows/agent-container-pr.yml +++ b/.github/workflows/agent-container-pr.yml @@ -49,3 +49,35 @@ jobs: build-args: | "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" + test_and_coverage: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.22 + + - name: Run tests with coverage + run: | + go test -coverprofile=coverage.out -covermode=count "./agent/kubviz/plugins/ketall" "./agent/kubviz/plugins/kubescore" "./agent/kubviz/plugins/kuberhealthy" "./agent/kubviz/plugins/outdated" "./agent/kubviz/plugins/rakkess" "./agent/kubviz/plugins/trivy" + go tool cover -func=coverage.out + + - name: Upload coverage report + uses: actions/upload-artifact@v2 + with: + name: coverage-report + path: report/cover.out + + - name: Analyze coverage + run: | + coverage=$(go tool cover -func=report/cover.out | grep total | awk '{print $3}' | sed 's/%//') + if [ $(echo "$coverage < 60" | bc) -eq 1 ]; then + echo "Coverage is below 60% threshold: $coverage%" + exit 1 + else + echo "Coverage is above 60% threshold: $coverage%" + fi \ No newline at end of file