EnricoMi / publish-unit-test-result-action

GitHub Action to publish unit test results on GitHub
Apache License 2.0
615 stars 184 forks source link

Support per file `test_file_prefix` #588

Closed troex closed 7 months ago

troex commented 7 months ago

It would nice if it would be setup individual test_file_prefix per each file.

My use case is that I have multiple apps in a mono repository where each app has it's own directory and since all off them require same environment I do run tests for each of them in a single github job, as result I have 5 junit xml files but they are all prefixed with local relative path so in order to get annotations to show up properly I have to setup publish-unit-test-result-action 5 times like:

      - name: Publish RSpec Results (APP 1)
        uses: EnricoMi/publish-unit-test-result-action@v2
        if: always()
        with:
          check_name: 'RSpec / APP 1'
          comment_mode: errors
          test_file_prefix: "+app_1/"
          files: |
            test-results/rspec/app_1.xml

      - name: Publish RSpec Results (APP 2)
        uses: EnricoMi/publish-unit-test-result-action@v2
        if: always()
        with:
          check_name: 'RSpec / APP 2'
          comment_mode: errors
          test_file_prefix: "+app_2/"
          files: |
            test-results/rspec/app_2.xml
# ... and so on

This works but not optimal, and I have 5 annotations instead of one.

I also tried to change how my junit reporter (formatter) works but it was not something it's easy achievable there (ruby, rspec + rspec_junit_formatter)

troex commented 7 months ago

I've found a better solution - it appears all references to the files in xml start with file=". and as such it was easier to replace the paths in xml file with sed:

sed -i -E "s/(file=\")\./\1app1/g" test-results/rspec/app1.xml

replacing . after file=" with the folder name I needed