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 d71d129 commit 486b5d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/agent-container-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,3 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:pr-${{ github.event.pull_request.number }}
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
32 changes: 32 additions & 0 deletions .github/workflows/agent-kubviz-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,36 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ github.repository }}/kubviz-agent:pr-${{ github.event.pull_request.number }}
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 486b5d8

Please sign in to comment.