From 36221b4ac8ac06e09fa49e6d651a8f10520e5ea5 Mon Sep 17 00:00:00 2001 From: Young Bu Park Date: Sat, 30 Mar 2024 11:07:17 -0700 Subject: [PATCH] enable codecov Signed-off-by: Young Bu Park --- .github/workflows/build.yaml | 76 +++--------------------------------- 1 file changed, 6 insertions(+), 70 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4f386eb4c0..d8cdf55c41 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -105,6 +105,12 @@ jobs: run: | go install gotest.tools/gotestsum@v${{ env.GOTESTSUMVERSION }} make test + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./dist/ut_coverage_orig.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. @@ -135,76 +141,6 @@ jobs: path: | ./dist/${{ matrix.target_os}}_${{ matrix.target_arch}}/release/rad ./dist/${{ matrix.target_os}}_${{ matrix.target_arch}}/release/rad.exe - - 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@v3 - 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 }} - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: