Skip to content

Fix code-coverage action - #5763

Open
gaiksaya wants to merge 1 commit into
opensearch-project:mainfrom
gaiksaya:fix-codeCoverage
Open

Fix code-coverage action#5763
gaiksaya wants to merge 1 commit into
opensearch-project:mainfrom
gaiksaya:fix-codeCoverage

Conversation

@gaiksaya

Copy link
Copy Markdown
Member

Description

Fix code-coverage action

Issues Resolved

opensearch-project/opensearch-build#6461

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
@gaiksaya gaiksaya added skip-changelog skip-diff-analyzer Maintainer to skip code-diff-analyzer check, after reviewing issues in AI analysis. labels Sep 11, 2026
@gaiksaya gaiksaya added the skip-diff-analyzer Maintainer to skip code-diff-analyzer check, after reviewing issues in AI analysis. label Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Artifact Name Collision

The artifact name 'jacoco-coverage-reports' is used without distinguishing between different matrix runs. If multiple jobs from the build-linux matrix (different Java versions or test types) run concurrently and all satisfy the condition 'matrix.test-type == unit && matrix.java == 21', they could overwrite each other's artifacts. The download step in 'upload-coverage' job will only retrieve the last uploaded artifact, potentially losing coverage data from other runs.

- name: Upload SQL Coverage Report Artifact
  if: ${{ !cancelled() && matrix.test-type == 'unit' && matrix.java == 21 }}
  uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
  with:
    name: jacoco-coverage-reports
    path: '**/build/reports/jacoco/test/jacocoTestReport.xml'
    retention-days: 1
    if-no-files-found: error
Missing Error Handling

The 'upload-coverage' job depends on 'build-linux' but does not check if 'build-linux' succeeded. If 'build-linux' fails, the job still runs due to '!cancelled()' condition, and the artifact download will fail with 'continue-on-error: true', silently skipping the coverage upload without any indication that coverage data was expected but missing.

upload-coverage:
  needs: build-linux
  name: Upload SQL coverage report to Codecov
  if: ${{ !cancelled() && github.repository == 'opensearch-project/sql' }}
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

    - name: Download coverage reports
      id: download-coverage
      continue-on-error: true
      uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
      with:
        name: jacoco-coverage-reports
        path: coverage

    - name: Upload SQL Coverage Report
      uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
      if: steps.download-coverage.outcome == 'success'
      with:
        flags: sql-engine
        directory: coverage
        token: ${{ secrets.CODECOV_TOKEN }}

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Check build-linux job success status

The job runs even if build-linux fails, which could lead to attempting to download
non-existent artifacts. Consider adding a success condition check for the
build-linux job to prevent unnecessary execution when the prerequisite job fails.

.github/workflows/sql-test-and-build-workflow.yml [104-107]

 upload-coverage:
   needs: build-linux
   name: Upload SQL coverage report to Codecov
-  if: ${{ !cancelled() && github.repository == 'opensearch-project/sql' }}
+  if: ${{ !cancelled() && needs.build-linux.result == 'success' && github.repository == 'opensearch-project/sql' }}
Suggestion importance[1-10]: 7

__

Why: Valid suggestion that prevents the upload-coverage job from running when build-linux fails. The current !cancelled() condition allows execution even on failure, which could waste resources attempting to download non-existent artifacts. Adding needs.build-linux.result == 'success' improves workflow efficiency.

Medium
Validate downloaded coverage reports exist

The download-artifact step may fail silently if the artifact doesn't exist (e.g.,
when the build-linux job is skipped or fails). Consider adding a validation step to
verify the artifact was created in the previous job before attempting to download
it, or check if the build-linux job completed successfully.

.github/workflows/sql-test-and-build-workflow.yml [112-118]

 - name: Download coverage reports
   id: download-coverage
   continue-on-error: true
   uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
   with:
     name: jacoco-coverage-reports
     path: coverage
+    
+- name: Verify coverage reports exist
+  if: steps.download-coverage.outcome == 'success'
+  run: |
+    if [ ! -f coverage/**/jacocoTestReport.xml ]; then
+      echo "Error: No coverage reports found"
+      exit 1
+    fi
Suggestion importance[1-10]: 3

__

Why: The suggestion adds validation for coverage reports, but the workflow already handles missing artifacts through continue-on-error: true and the conditional check if: steps.download-coverage.outcome == 'success' on the upload step. The additional validation provides minimal value since the workflow gracefully handles the absence of artifacts.

Low

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.75%. Comparing base (6116c33) to head (7664629).
⚠️ Report is 1651 commits behind head on main.

❌ Your project check has failed because the head coverage (62.75%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (6116c33) and HEAD (7664629). Click for more details.

HEAD has 5 uploads less than BASE
Flag BASE (6116c33) HEAD (7664629)
sql-engine 6 1
Additional details and impacted files
@@              Coverage Diff              @@
##               main    #5763       +/-   ##
=============================================
- Coverage     98.40%   62.75%   -35.65%     
- Complexity     2746     8767     +6021     
=============================================
  Files           266      937      +671     
  Lines          6758    40101    +33343     
  Branches        426     4512     +4086     
=============================================
+ Hits           6650    25166    +18516     
- Misses          107    14153    +14046     
- Partials          1      782      +781     
Flag Coverage Δ
sql-engine 62.75% <ø> (-35.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog skip-diff-analyzer Maintainer to skip code-diff-analyzer check, after reviewing issues in AI analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant