Skip to content

Commit 1cb2da9

Browse files
[ci] replace pull_request_target with pull_request (#833)
1 parent 9c5b69c commit 1cb2da9

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

.github/workflows/comment.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

.github/workflows/linux_llvm_cov.yml

+13-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
name: Ubuntu 22.04 (llvm cov)
2323

2424
on:
25-
pull_request_target:
25+
pull_request:
2626
branches:
2727
- main
2828
- fix_coverage_show
@@ -34,6 +34,7 @@ concurrency:
3434
jobs:
3535
prerequisites:
3636
runs-on: ubuntu-22.04
37+
permissions: write-all
3738
outputs:
3839
id: ${{ steps.get-base-commit.outputs.id }}
3940
steps:
@@ -44,14 +45,21 @@ jobs:
4445
base_commit_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .base.sha)
4546
echo "::set-output name=id::$base_commit_id"
4647
shell: bash
48+
- name: 'Store Message'
49+
run: |
50+
mkdir -p ./msg
51+
echo "action_id=${{github.run_id}}" >> ./msg/action_msg
52+
echo "pr_id=${{github.event.pull_request.number}}" >> ./msg/action_msg
53+
shell: bash
54+
- name: 'Upload Action Message'
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: action_msg
58+
path: msg/
4759

4860
base-cov-test:
4961
needs: prerequisites
5062
runs-on: ubuntu-22.04
51-
permissions:
52-
contents: read
53-
issues: write
54-
pull-requests: write
5563
outputs:
5664
data: ${{ steps.base-cov.outputs.data }}
5765
steps:
@@ -66,10 +74,6 @@ jobs:
6674
cov-test:
6775
needs: prerequisites
6876
runs-on: ubuntu-22.04
69-
permissions:
70-
contents: read
71-
issues: write
72-
pull-requests: write
7377
outputs:
7478
data: ${{ steps.cov.outputs.data }}
7579
steps:
@@ -87,11 +91,6 @@ jobs:
8791
- cov-test
8892
runs-on: ubuntu-22.04
8993
steps:
90-
- name: 'Create comment'
91-
run: |
92-
content=$(echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{github.run_id}}) download Artifacts \`base-ylt-cov-report\`(base commit coverage report) and \`ylt-cov-report\`(current pull request coverage report)")
93-
curl -L -X POST "https://api.github.com/repos/${{github.repository}}/issues/${{github.event.pull_request.number}}/comments" -H "Authorization: Bearer ${{github.token}}" -H 'Content-Type: application/json' -d "{\"body\": \"$content}\""
94-
shell: bash
9594
- name: 'Compare data'
9695
run: |
9796
sudo apt install -y bc

0 commit comments

Comments
 (0)