From 9ba33c7bf3c3e99dc9b57d32c1f0ad764ece9286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 19 Feb 2025 09:13:42 +0100 Subject: [PATCH 1/4] cI: report comment --- .github/workflows/test.yml | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2369179..995afbf3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,37 +80,15 @@ 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 }}" \ - "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 - 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 + if: always() + 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 + message: | go-test-coverage report: - ``` + ``` ${{ fromJSON(steps.coverage.outputs.report) }}``` - name: "finally check coverage" From 06631f4713186b7217600af055d30d4095a6dfc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 19 Feb 2025 09:23:15 +0100 Subject: [PATCH 2/4] fix var name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 995afbf3..9a04f26d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,7 +84,7 @@ jobs: if: always() uses: thollander/actions-comment-pull-request@v3 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} comment-tag: coverage-report message: | go-test-coverage report: From 52a97b1d08a7f2eeffea6c39cffa895334e5e5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 19 Feb 2025 09:36:58 +0100 Subject: [PATCH 3/4] test --- .github/workflows/test.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a04f26d..37bd8d34 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,12 +80,24 @@ jobs: path: main.breakdown if-no-files-found: error + - 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") + PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number') + + if [ "$PR_ID" != "null" ]; then + echo "pull_request_id=$PR_ID" >> $GITHUB_ENV + else + echo "No open pull request found for this branch." + fi - name: post coverage report - if: always() + if: env.pull_request_id uses: thollander/actions-comment-pull-request@v3 with: github-token: ${{ secrets.GITHUB_TOKEN }} comment-tag: coverage-report + pr-number: ${{ env.pull_request_id }} message: | go-test-coverage report: ``` From 1bd342b21c7b702e9ebecd9dcf89293c48714da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 19 Feb 2025 09:42:18 +0100 Subject: [PATCH 4/4] docs: update --- docs/github_action.md | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) 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'