Skip to content

Commit

Permalink
unit-testcase execution in pr build
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjino committed Jun 20, 2024
1 parent 4bd9013 commit d71d129
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/agent-container-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d71d129

Please sign in to comment.