PavanMudigonda / jacoco-reporter

GitHub Action to Publish JaCoCo Format Code Coverage XML and attach it to the Workflow Run as a Check Run. Also can enforce Coverage Quality Gate.
https://linkedin.com/in/PavanMudigonda
MIT License
69 stars 7 forks source link

The actions fails when the generated report is greater than 65535 characters long #2

Closed gmetal closed 2 years ago

gmetal commented 2 years ago

Describe the bug If the action is used with a coverage report that produces an output greater than 65535 characters long, then the action fails,.

Steps to reproduce the behavior:

  1. Supply a coverage report that is large (I used it with a report that was about 1.3Mb)
  2. Attempt run the github action
  3. The coverage reporter fails

Expected behavior The report gets generated correctly

Screenshots The report produces the following (partially redacted) log:

/usr/bin/pwsh -f /home/runner/work/_actions/PavanMudigonda/jacoco-reporter/v2.4/action.ps1
Module [GitHubActions] not found, INSTALLING...
Running from [/home/runner/work/_actions/PavanMudigonda/jacoco-reporter/v2.4]

Creating test results space

/home/runner/work/*******/_TMP

Publishing Report to GH Workflow

Covered Lines: 1125
Missed Lines: 7888
-601%

Building human-readable code-coverage report

VERBOSE: Resolving XML file relative to current directory: /home/runner/work/******//app/build/reports/kover/project-xml/report.xml
VERBOSE: Resolving default XSL file: /home/runner/work/_actions/PavanMudigonda/jacoco-reporter/v2.4/jacoco-report/jacocoxml2md.xsl
VERBOSE: Loaded XSL transformer
VERBOSE: Transforming XML to MD
Publishing Report to GH Workflow

Resolving REF

Resolving PR REF

Resolved REF as 56ff9c6acff80bd6a0077cdf30966a15c8a452ec

Resolve Repo Full Name as **********

Adding Check Run

Invoke-WebRequest: /home/runner/work/_actions/PavanMudigonda/jacoco-reporter/v2.4/action.ps1:112
Line |
 112 |      Invoke-WebRequest -Headers $hdr $url -Method Post -Body ($bdy | C …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"message":"Invalid request.\n\nOnly 65535 characters are
     | allowed; 76386 were
     | supplied.","documentation_url":"https://docs.github.com/rest/reference/checks#create-a-check-run"}

Error: The process '/usr/bin/pwsh' failed with exit code 1
PavanMudigonda commented 2 years ago

@gmetal Github REST API has a limit of 65K chars for creating checkrun. Its limitation on Microsoft/Github side. I will take this request as enhancement and i will look in to using GitHub GraphQL API instead but i can't promise any timeline since i happened to be busy at moment.

PavanMudigonda commented 2 years ago

@gmetal I tried to solve it by using GitHub Graph API but i got the same error....GitHub has hard limit on how many characters that can be posted as CheckRun. I will find a way to slim down report or only publish summary.

gmetal commented 2 years ago

@PavanMudigonda I think that publishing a summary would a safer approach. It would also cover most scenarios I believe.

PavanMudigonda commented 2 years ago

@gmetal Please try again with your report that is about 1.3Mb). Use below parameters.

uses: PavanMudigonda/jacoco-reporter@v2.6,
publish_only_summary: true

- name: JaCoCo Code Coverage Report
  id: jacoco_reporter
  uses: PavanMudigonda/jacoco-reporter@v2.6
  with:
    coverage_results_path: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
    coverage_report_name: Coverage
    coverage_report_title: JaCoCo
    github_token: ${{ secrets.GITHUB_TOKEN }}
    skip_check_run: false
    minimum_coverage: 80
    fail_below_threshold: false
    publish_only_summary: true

image

PavanMudigonda commented 2 years ago

You should see 12.48 %

Covered Lines: 1125 Missed Lines: 7888 Total Lines: 9013 Coverage % : 12.48 %

PavanMudigondaTR commented 2 years ago

@gmetal

I have made another workaround for this 65k problem. Please see below with this i do skip check run and then generate markdown file and upload to GitHub assets which you can download and view offline using VS Code. I hope this helps you and your team !

https://github.com/PavanMudigonda/jacoco-playground/actions/runs/2173239744

jobs: test: runs-on: ubuntu-latest steps:

  # generates coverage-report.md and publishes as checkrun
  - name: JaCoCo Code Coverage Report
    id: jacoco_reporter
    uses: PavanMudigonda/jacoco-reporter@v2.7
    with:
      coverage_results_path: jacoco-report/test.xml
      coverage_report_name: Coverage
      coverage_report_title: JaCoCo
      github_token: ${{ secrets.GITHUB_TOKEN }}
      skip_check_run: true
      minimum_coverage: 80
      fail_below_threshold: false
      publish_only_summary: false

  # uploads the coverage-report.md artifact    
  - name: Upload Code Coverage Artifacts
    uses: actions/upload-artifact@v2
    with:
      name: code-coverage-report
      path: */coverage-results.md 
      retention-days: 1  
gmetal commented 2 years ago

@PavanMudigonda I tried the 2.6 version (the summary version) and it worked fine. I also gave 2.7 a go as per your instructions, but I got the original error.

PavanMudigondaTR commented 2 years ago

@PavanMudigonda I tried the 2.6 version (the summary version) and it worked fine. I also gave 2.7 a go as per your instructions, but I got the original error.

@gmetal Could you try v3.0 as i have fixed few other problems.

Scenario# 1:- Generate summary report as checkrun

generates coverage-report.md and publishes as checkrun

Scenario# 2 Generate full report and view offline by downloading coverage artifact

generates coverage-report.md and publishes as checkrun

gmetal commented 2 years ago

@PavanMudigonda Hello, I had a go at version 3 of the action. When using the skip_check_run: true, then no artifacts get generated. If that is set to false, then the coverage-results.md is not generated. With skip_check_run:false and the publish_only_summary: false the I run into the 65k problem again.

PavanMudigondaTR commented 2 years ago

@gmetal I have fully fixed it in v4.3 and well tested in https://github.com/PavanMudigonda/jacoco-playground/actions you are welcome to try out as per my https://github.com/PavanMudigonda/jacoco-reporter/blob/main/README.md

gmetal commented 2 years ago

@PavanMudigondaTR I can confirm that it is now working properly (v4.3). With:

          skip_check_run: true
          publish_only_summary: false

the coverage-results.md file is generated properly and I can archive it, with something like the following:

      - name: Upload Code Coverage Artifacts
        uses: actions/upload-artifact@v2
        with:
          name: code-coverage-report
          path: "*/coverage-results.md"
          retention-days: 1