Skip to content

Commit 1c79d5b

Browse files
committed
ci: add workflow for pr comment
Signed-off-by: smrpn <samarpan_d@pp.iitr.ac.in>
1 parent 97d71e3 commit 1c79d5b

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

.github/workflows/commentPR.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Comment on the pull request
2+
3+
# read-write repo token
4+
# access to secrets
5+
on:
6+
workflow_run:
7+
workflows: ["Benchmarks"]
8+
types:
9+
- completed
10+
11+
jobs:
12+
upload:
13+
runs-on: ubuntu-latest
14+
if: >
15+
${{ github.event.workflow_run.event == 'pull_request' &&
16+
github.event.workflow_run.conclusion == 'success' }}
17+
steps:
18+
- name: 'Download artifact'
19+
uses: actions/github-script@v3.1.0
20+
with:
21+
script: |
22+
var artifacts = await github.actions.listWorkflowRunArtifacts({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
run_id: ${{github.event.workflow_run.id }},
26+
});
27+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
28+
return artifact.name == "pr"
29+
})[0];
30+
var download = await github.actions.downloadArtifact({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
artifact_id: matchArtifact.id,
34+
archive_format: 'zip',
35+
});
36+
var fs = require('fs');
37+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
38+
- run: unzip pr.zip
39+
40+
- name: 'Comment on PR'
41+
uses: actions/github-script@v3
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
script: |
45+
var file = "benchResults.txt"
46+
if (file) {
47+
var fs = require('fs');
48+
var issue_number = Number(fs.readFileSync('./NR'));
49+
await github.issues.createComment({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
issue_number: issue_number,
53+
body: (fs.readFileSync('./benchResults.txt')).toString('utf8')
54+
});
55+
}
56+

.github/workflows/pull_request.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ jobs:
2323
with:
2424
cwd: benches
2525
token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
28+
- name: Save PR number
29+
run: |
30+
mkdir -p ./pr
31+
echo ${{ github.event.number }} > ./pr/NR
32+
- uses: actions/upload-artifact@v2
33+
with:
34+
name: pr
35+
path: pr/
2636

0 commit comments

Comments
 (0)