5monkeys / cobertura-action

GitHub Action to report cobertura coverage
MIT License
63 stars 69 forks source link

`only_changed_files` option not working #88

Open PascalArdex opened 1 year ago

PascalArdex commented 1 year ago

I have a dotnet / C# project using 5monkeys/cobertura-action@v13, it works great with default values

Just tried to add the option only_changed_files: true as the project is getting bigger but it does not seem to have any effect. More precisely, the report is still created but only shows the header line for All files Screenshot 2023-09-04 at 13-36-14 epona_ github_workflows at main · ardextech_epona

Here is an extract of my GitHub workflow

  test:
    runs-on: ubuntu-latest
    permissions:
      statuses: write
      checks: write
      contents: write
      pull-requests: write
      actions: write
    steps:
    - uses: actions/checkout@v3
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 7.0.x
    - name: Test
      run: dotnet test --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage"
    - name: Coverage Report
      uses: 5monkeys/cobertura-action@v13
      with:
        path: backend-api/tests/TestResults/*/*.xml
        minimum_coverage: 70
        skip_covered: false
        show_line: true
        show_branch: true
        show_class_names: false
        only_changed_files: true

Action executes without any problem Screenshot 2023-09-04 at 14-23-38 EPN-34 Generate and Send New User Invite Email · ardextech_epona@9a3c2ae

arturs-at-levelpath commented 1 year ago

Having exactly the same problem.

PascalArdex commented 1 year ago

I found the following ugly workaround (since I don't really know how to debug GitHub actions)

    - name: Pre-processing Coverage Report
      run: sed -i 's#filename="#filename="backend-api/src/#g' tests/TestResults/*/*.xml
    - name: Coverage Report
      uses: 5monkeys/cobertura-action@v13
      ...

I backtracked to the following line https://github.com/5monkeys/cobertura-action/blob/18d911b62098eafd8b9db93d6c74194556cc3515/src/action.js#L172

In order to work as expected, the action needs to find an exact match between the filename found in the XML report and the list of files in the pull request.

Now a very likely structure for dotnet projects using XUnit is to have a top level solution file and two folders src and tests. In my case I am using a mono-repo structure so it is even more complex than that.

The filenames matching could be more complex. We can compute the absolute path to the filename attributes in the XML using the tag.

Anyway, just wanted to say this GitHub action is awesome!!! And I don't understand why Microsoft is not doing first class citizen actions for dotnet but that's another story....

arturs-at-levelpath commented 1 year ago

We are using monorepo as well on our end and it seems like this PR fixes all issues and it works fine.

https://github.com/5monkeys/cobertura-action/pull/74

Problem it seems is getting it in main branch 😞

LensArt commented 6 months ago

I encountered the same issue, is there a plan to fix this?

zwang1-godaddy commented 4 weeks ago

Hi team, any update?