MishaKav / pytest-coverage-comment

Comments a pull request with the pytest code coverage badge and full report
MIT License
181 stars 60 forks source link

GitHub Action Step output for coverage is an object not a string? #103

Closed jrwagz closed 1 year ago

jrwagz commented 1 year ago

I have setup pytest with the following options:

https://github.com/jrwagz/cards-proj/blob/add-coverage-badge/pyproject.toml#L43

--cov-report html --cov-report xml:coverage.xml --cov=cards

And then I configured my actions as follows:

      - name: Publish Coverage Report as comment
        id: coverageComment
        if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
        uses: MishaKav/pytest-coverage-comment@v1.1.40
        with:
          pytest-xml-coverage-path: ./coverage.xml
          unique-id-for-comment: ${{ matrix.os }} ${{ matrix.python-version }}

https://github.com/jrwagz/cards-proj/blob/add-coverage-badge/.github/workflows/tests.yml#L32-L57

However, when I try get the coverage percentage as just a string, I get an object instead:

      - name: Check the output coverage
        if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
        run: |
          echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
          echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
  echo "Coverage Percentage - {"name":"TOTAL","stmts":182,"miss":100,"cover":"45%"}"
  echo "Coverage Color - orange"

Am I doing something wrong?

jrwagz commented 1 year ago

In this same exact workflow, the comment created seemed to be correct:

https://github.com/jrwagz/cards-proj/commit/e16995f5160d049ab189fbce890144297fa6a312#commitcomment-93994345

image
MishaKav commented 1 year ago

The output coverage was not supported for pytest-xml-coverage-path, I added support for this and release a new version, which you can use:

- name: Pytest Coverage Comment
  uses: MishaKav/pytest-coverage-comment@main
  with:
    pytest-xml-coverage-path: ./coverage.xml

or use a specific version

- name: Pytest Coverage Comment
  uses: MishaKav/pytest-coverage-comment@v1.1.41
  with:
    pytest-xml-coverage-path: ./coverage.xml
jrwagz commented 1 year ago

Fantastic work, thank you!