From fbaede656b66edf3118b1394af33dd82ebad7888 Mon Sep 17 00:00:00 2001 From: "weirui.kwr@alibaba-inc.com" Date: Fri, 12 Jan 2024 16:45:27 +0800 Subject: [PATCH] add cov report --- .github/workflows/unittest.yml | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 9a4d5c561..e41105082 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -29,4 +29,36 @@ jobs: coverage run tests/run.py - name: Generate coverage report run: | - coverage report -m + coverage report -m > coverage.txt + - name: Update or Post coverage report as PR comment + if: github.event_name == 'pull_request' + uses: actions/github-script@v3 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const fs = require('fs'); + const report = fs.readFileSync('coverage.txt', {encoding:'utf8', flag:'r'}); + const commentIdentifier = ''; + const commentBody = `${commentIdentifier}\nšŸ“Š **Coverage Report**:\n\`\`\`\n${report}\n\`\`\``; + + const issue_number = context.issue.number; + const comments = await github.issues.listComments({ + ...context.repo, + issue_number + }); + + const coverageComment = comments.data.find(comment => comment.body.includes(commentIdentifier)); + + if (coverageComment) { + await github.issues.updateComment({ + ...context.repo, + comment_id: coverageComment.id, + body: commentBody + }); + } else { + await github.issues.createComment({ + ...context.repo, + issue_number, + body: commentBody + }); + } \ No newline at end of file