|
| 1 | +# |
| 2 | +# Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. |
| 3 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | +# |
| 5 | +# This code is free software; you can redistribute it and/or modify it |
| 6 | +# under the terms of the GNU General Public License version 2 only, as |
| 7 | +# published by the Free Software Foundation. Alibaba designates this |
| 8 | +# particular file as subject to the "Classpath" exception as provided |
| 9 | +# by Oracle in the LICENSE file that accompanied this code. |
| 10 | +# |
| 11 | +# This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | +# version 2 for more details (a copy is included in the LICENSE file that |
| 15 | +# accompanied this code). |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License version |
| 18 | +# 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | +# |
| 21 | + |
| 22 | +name: Cov Report Comment |
| 23 | + |
| 24 | +on: |
| 25 | + workflow_run: |
| 26 | + workflows: ["Ubuntu 22.04 (llvm cov)"] |
| 27 | + types: |
| 28 | + - completed |
| 29 | + |
| 30 | +jobs: |
| 31 | + comment: |
| 32 | + runs-on: ubuntu-22.04 |
| 33 | + permissions: write-all |
| 34 | + steps: |
| 35 | + - name: 'Download artifact' |
| 36 | + uses: actions/github-script@v6 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + run_id: context.payload.workflow_run.id, |
| 43 | + }); |
| 44 | + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { |
| 45 | + return artifact.name == "action_msg" |
| 46 | + })[0]; |
| 47 | + let download = await github.rest.actions.downloadArtifact({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + artifact_id: matchArtifact.id, |
| 51 | + archive_format: 'zip', |
| 52 | + }); |
| 53 | + let fs = require('fs'); |
| 54 | + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/action_msg.zip`, Buffer.from(download.data)); |
| 55 | + - name: 'Comment' |
| 56 | + run: | |
| 57 | + unzip action_msg.zip |
| 58 | + pr_id=`grep 'pr_id' action_msg | cut -d '=' -f 2` |
| 59 | + action_id=`grep 'action_id' action_msg | cut -d '=' -f 2` |
| 60 | + content=$(echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${action_id}) download Artifacts \`base-ylt-cov-report\`(base commit coverage report) and \`ylt-cov-report\`(current pull request coverage report)") |
| 61 | + curl -L -X POST "https://api.github.com/repos/${{github.repository}}/issues/${pr_id}/comments" -H "Authorization: Bearer ${{github.token}}" -H 'Content-Type: application/json' -d "{\"body\": \"$content\"}" |
| 62 | + shell: bash |
0 commit comments