MishaKav / jest-coverage-comment

Comments a pull request or commit with the jest code coverage badge, full report and tests summary
MIT License
80 stars 34 forks source link

Cant get outputs when using mono-repo functionality & pull_request_review action trigger #71

Closed JacobStenson1 closed 1 year ago

JacobStenson1 commented 1 year ago

I am not getting any values when I try and access output variables. I can see the values being displayed in action logs but cant access them when using outputs.coverage for some reason, see below.

on:
  pull_request_review:
    types: [submitted]
jobs:
  ...
  test-reporter:
    name: test-reporter
    runs-on: ubuntu-latest
    steps:
      - name: Jest Coverage
        id: coverageComment
        if: success() || failure()
        uses: MishaKav/jest-coverage-comment@main
        with:
          multiple-files: |
            parcel-helper, ./packages/parcel-helper/test/coverage/coverage-summary.json
            parcel-helper-common, ./packages/parcel-helper-common/test/coverage/coverage-summary.json
          multiple-junitxml-files: |
            parcel-helper, ./packages/parcel-helper/test/coverage/jest.xml
            parcel-helper-common, ./packages/parcel-helper-common/test/coverage/jest.xml
          title: UV Migration Test Coverage
          summary-title: Coverage Summary
          badge-title: Coverage
          hide-comment: false
          create-new-comment: false
          hide-summary: false
      - name: Check the output coverage
        run: |
          echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
          echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
          echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}"

image

I'm trying to get the output variables so that I can pass them to another action to create a comment on my PR for me as this action cannot add a comment when the action trigger is from a PR review.

Thanks in advance.

MishaKav commented 1 year ago

You only have the outputs.coverage or outputs.color when you use a single report. When you use a multiple-files - it can't give you an output for a single file. You can path the filePath that you want as output here: coverage-summary-path.

JacobStenson1 commented 1 year ago

Thank you. I've used that to fix my implementation.

I've changed my jest-coverage-comment to now do this (just incase anyone else comes across this)

- name: parcel-helper Jest Coverage
  id: coverageComment
  if: success() || failure()
  uses: MishaKav/jest-coverage-comment@main
  with:
    coverage-summary-path: ./packages/parcel-helper/test/coverage/coverage-summary.json
    hide-comment: true
- name: parcel-helper-common Jest Coverage
  id: commonCoverageComment
  if: success() || failure()
  uses: MishaKav/jest-coverage-comment@main
  with:
    coverage-summary-path: ./packages/parcel-helper-common/test/coverage/coverage-summary.json
    hide-comment: true

- name: Create/update coverage comment
  uses: peter-evans/create-or-update-comment@v3
  with:
    issue-number: ${{ github.event.pull_request.number }}
    body: |
      UV Migration Test Coverage
      :package: parcel-helper Summary HTML:
      ${{ steps.coverageComment.outputs.summaryHtml }}
      :link: parcel-helper-common Summary HTML:
      ${{ steps.commonCoverageComment.outputs.summaryHtml }}

image