diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2369179..37bd8d34 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,7 +80,6 @@ jobs: path: main.breakdown if-no-files-found: error - # Post coverage report as comment - name: find pull request ID run: | PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ @@ -92,25 +91,16 @@ jobs: else echo "No open pull request found for this branch." fi - - name: find if coverage report is already present - if: env.pull_request_id - uses: peter-evans/find-comment@v3 - id: fc - with: - issue-number: ${{ env.pull_request_id }} - comment-author: 'github-actions[bot]' - body-includes: 'go-test-coverage report:' - name: post coverage report if: env.pull_request_id - uses: peter-evans/create-or-update-comment@v4 + uses: thollander/actions-comment-pull-request@v3 with: - token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ env.pull_request_id }} - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | + github-token: ${{ secrets.GITHUB_TOKEN }} + comment-tag: coverage-report + pr-number: ${{ env.pull_request_id }} + message: | go-test-coverage report: - ``` + ``` ${{ fromJSON(steps.coverage.outputs.report) }}``` - name: "finally check coverage" diff --git a/docs/github_action.md b/docs/github_action.md index cdf7bfa7..4d130353 100644 --- a/docs/github_action.md +++ b/docs/github_action.md @@ -108,39 +108,30 @@ Example of report is in [this PR](https://github.com/vladopajic/go-test-coverage continue-on-error: true # Should fail after coverage comment is posted with: config: ./.github/.testcoverage.yml - - # Post coverage report as comment (in 3 steps) + + # Post coverage report as comment (in 2 steps) - name: find pull request ID run: | PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open") + "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open") PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number') if [ "$PR_ID" != "null" ]; then - echo "pull_request_id=$PR_ID" >> $GITHUB_ENV + echo "pull_request_id=$PR_ID" >> $GITHUB_ENV else - echo "No open pull request found for this branch." + echo "No open pull request found for this branch." fi - - name: find if coverage report is already present - if: env.pull_request_id - uses: peter-evans/find-comment@v3 - id: fc - with: - issue-number: ${{ env.pull_request_id }} - comment-author: 'github-actions[bot]' - body-includes: 'go-test-coverage report:' - name: post coverage report if: env.pull_request_id - uses: peter-evans/create-or-update-comment@v4 + uses: thollander/actions-comment-pull-request@v3 with: - token: ${{ secrets.GITHUB_TOKEN }} - issue-number: ${{ env.pull_request_id }} - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | + github-token: ${{ secrets.GITHUB_TOKEN }} + comment-tag: coverage-report + pr-number: ${{ env.pull_request_id }} + message: | go-test-coverage report: ``` - ${{ fromJSON(steps.coverage.outputs.report) }} ``` + ${{ fromJSON(steps.coverage.outputs.report) }}``` - name: "finally check coverage" if: steps.coverage.outcome == 'failure'