-
Notifications
You must be signed in to change notification settings - Fork 19
58 lines (53 loc) · 2.23 KB
/
pr-manipulation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: PR Comment Generation
on:
workflow_run:
workflows: ["Build and Test"]
types:
- completed
jobs:
comment_on_pr:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: 'Download artifact'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
...context.repo,
run_id: ${{github.event.workflow_run.id }},
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
const download = await github.rest.actions.downloadArtifact({
...context.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip
- name: 'Comment on PR'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const issueNumber = Number(fs.readFileSync('./NR'));
const summaryContent = fs.readFileSync('./step_summary.md', 'utf-8');
const existingCommentsOpts = github.rest.issues.listComments.endpoint.merge({
...context.repo, issue_number: issueNumber
});
const existingComments = await github.paginate(existingCommentsOpts);
const TAG = 'execution';
const tagPattern = `<!-- pr_asset_summary_comment "${TAG}" -->`;
const body = `${summaryContent}\n${tagPattern}`;
const preExistingComment = existingComments.find((comment) => comment.body?.includes(tagPattern));
if(preExistingComment) {
await github.rest.issues.updateComment({ ...context.repo, comment_id: preExistingComment.id, body });
} else {
await github.rest.issues.createComment({ ...context.repo, issue_number: issueNumber, body });
}