From 36221b4ac8ac06e09fa49e6d651a8f10520e5ea5 Mon Sep 17 00:00:00 2001 From: Young Bu Park Date: Sat, 30 Mar 2024 11:07:17 -0700 Subject: [PATCH 1/5] 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: From a00f9d13fb6ebc19ee1d4700c00b0c27c578fd3f Mon Sep 17 00:00:00 2001 From: Young Bu Park Date: Sat, 30 Mar 2024 11:42:14 -0700 Subject: [PATCH 2/5] add codecov.yml Signed-off-by: Young Bu Park --- codecov.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..4714d83ed9 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,23 @@ +codecov: + require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "65...100" + status: + project: + default: + target: auto + threshold: 1% + +comment: + layout: "reach,diff,flags,tree" + behavior: default + require_changes: no + +ignore: + - "**/*mock*" + - "pkg/armrpc/rpctest/*" + - "pkg/datamodel/*.go" + - "**/zz_*" From 681e335c2341fe9b83028bca6547d9e2529cb081 Mon Sep 17 00:00:00 2001 From: Young Bu Park Date: Mon, 1 Apr 2024 07:26:14 -0700 Subject: [PATCH 3/5] remove cache Signed-off-by: Young Bu Park --- .github/workflows/build.yaml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d8cdf55c41..1696526b0d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -88,11 +88,6 @@ jobs: with: go-version: ${{ env.GOVER }} cache-dependency-path: go.sum - - name: Restore the previous coverage - uses: actions/cache/restore@v3 - 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 @@ -101,14 +96,14 @@ 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: | 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 + file: ./dist/unit_test/ut_coverage.out flags: unittests fail_ci_if_error: false - name: Process Unit Test Results From a18065b7dd153f60a7b0eff57a865f81d7cc9a5d Mon Sep 17 00:00:00 2001 From: Young Bu Park Date: Mon, 1 Apr 2024 09:06:09 -0700 Subject: [PATCH 4/5] wip Signed-off-by: Young Bu Park --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1696526b0d..fc047be931 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -98,6 +98,7 @@ jobs: GOTESTSUM_OPTS: '--junitfile ./dist/unit_test/results.xml' 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 From ba9f384db15f55ae387e4af72b29e0a5a7118b7b Mon Sep 17 00:00:00 2001 From: Young Bu Park Date: Mon, 1 Apr 2024 10:09:19 -0700 Subject: [PATCH 5/5] add comments Signed-off-by: Young Bu Park --- codecov.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/codecov.yml b/codecov.yml index 4714d83ed9..b14376cfa1 100644 --- a/codecov.yml +++ b/codecov.yml @@ -4,7 +4,7 @@ codecov: coverage: precision: 2 round: down - range: "65...100" + range: "50...100" status: project: default: @@ -17,7 +17,6 @@ comment: require_changes: no ignore: - - "**/*mock*" - - "pkg/armrpc/rpctest/*" - - "pkg/datamodel/*.go" - - "**/zz_*" + - "**/mock_*" # ignore all mock files + - "pkg/armrpc/rpctest/*" # ignore all test helpers in rpctest + - "**/zz_*" # ignore autogenerated files from autorest