Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable codecov #7421

Merged
merged 8 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 8 additions & 76 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ jobs:
with:
go-version: ${{ env.GOVER }}
cache-dependency-path: go.sum
- name: Restore the previous coverage
uses: actions/cache/restore@v4
with:
path: ./dist/cache
key: radius-coverage-
- name: Parse release version and set environment variables
run: python ./.github/scripts/get_release_version.py
- name: Make build
Expand All @@ -101,10 +96,17 @@ jobs:
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
env:
GOTESTSUM_OPTS: '--junitfile ./dist/unit_test/results.xml'
GOTEST_OPTS: '-race -coverprofile ./dist/ut_coverage_orig.out'
GOTEST_OPTS: '-race -coverprofile ./dist/unit_test/ut_coverage.out'
run: |
mkdir -p ./dist/unit_test
go install gotest.tools/gotestsum@v${{ env.GOTESTSUMVERSION }}
make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./dist/unit_test/ut_coverage.out
flags: unittests
fail_ci_if_error: false
- name: Process Unit Test Results
uses: ./.github/actions/process-test-results
# Always is required here to make sure this target runs even when tests fail.
Expand All @@ -128,76 +130,6 @@ jobs:
with:
name: rad_cli_${{ matrix.target_os}}_${{ matrix.target_arch}}
path: ${{ env.RELEASE_PATH }}
- name: Generate unit-test coverage files
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
run: |
# Remove mock, generated files, and datamodels from original coverage output.
cat ./dist/ut_coverage_orig.out | grep -v "mock" | grep -v "zz_" | grep -v "armrpc/rpctest" | grep -v '/datamodel/[A-za-z0-9_]*.go' > $COVERAGE_FILE
# Generate reports.
$GO_TOOL_COVER -func=$COVERAGE_FILE -o ./dist/ut_coverage.txt
$GO_TOOL_COVER -html=$COVERAGE_FILE -o ./dist/ut_coverage.html
# Parse total coverage rate from report.
UT_COVERAGE=`cat ./dist/ut_coverage.txt | grep total: | grep -Eo '[0-9]+\.[0-9]+'`
echo "Test coverage : $UT_COVERAGE"

echo "ut_coverage=$UT_COVERAGE" >> $GITHUB_ENV

mkdir -p ./dist/cache
MAIN_COVERAGE=0
if [ -f "./dist/cache/ut_coverage.txt" ]; then
MAIN_COVERAGE=$(cat ./dist/cache/ut_coverage.txt | grep total: | grep -Eo '[0-9]+\.[0-9]+')
fi
echo "main_coverage=$MAIN_COVERAGE" >> $GITHUB_ENV

if (( $(echo "$UT_COVERAGE < $MAIN_COVERAGE" | bc -l) )) ; then
COLOR=red
else
COLOR=green
fi

DIFF_RATE=$(echo "$UT_COVERAGE-$MAIN_COVERAGE" | bc -l)
echo "diff_coverage=$DIFF_RATE" >> $GITHUB_ENV

echo "coverage_img=https://img.shields.io/badge/coverage-$UT_COVERAGE%25-$COLOR" >> $GITHUB_ENV
# copy coverage to cache
cp ./dist/ut_coverage.txt ./dist/cache/
env:
COVERAGE_FILE: ./dist/ut_coverage.out
GO_TOOL_COVER: go tool cover
- name: Upload unit-test coverage artifact
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
uses: actions/upload-artifact@v4
with:
name: unit_test_coverage
path: |
./dist/coverage_orig.out
./dist/ut_coverage.out
./dist/ut_coverage.txt
./dist/ut_coverage.html
- name: Add coverage result comment
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux' && github.event.pull_request && github.event.pull_request.head.repo.full_name == github.repository
uses: marocchino/sticky-pull-request-comment@v2
with:
header: testcov-${{ github.run_id }}
number: ${{ github.event.pull_request.number }}
hide: true
hide_classify: OUTDATED
message: |
![${{ env.ut_coverage }}](${{ env.coverage_img }})

For the detailed report, please go to `Checks tab`, click `Build and Test`, and then download `unit_test_coverage` artifact at the bottom of build page.

* Your PR branch coverage: ${{ env.ut_coverage }} %
* main branch coverage: ${{ env.main_coverage }} %
* diff coverage: ${{ env.diff_coverage }} %

> The coverage result does not include the functional test coverage.
- name: Save coverage (only main push)
uses: actions/cache/save@v3
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux' && github.ref == 'refs/heads/main'
with:
path: ./dist/cache
key: radius-coverage-${{ github.sha }}-${{ github.run_number }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁👋 thank you for your service

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand Down
22 changes: 22 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "50...100"
Copy link
Author

@youngbupark youngbupark Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will increase starting percentage after this pr is merged.

status:
project:
default:
target: auto
threshold: 1%

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no

ignore:
- "**/mock_*" # ignore all mock files
- "pkg/armrpc/rpctest/*" # ignore all test helpers in rpctest
- "**/zz_*" # ignore autogenerated files from autorest
Loading