1+ name : Comment
2+
3+ on :
4+ workflow_run :
5+ workflows : [ Build ]
6+ types :
7+ - completed
8+
9+ jobs :
10+ comment :
11+ runs-on : ubuntu-latest
12+ if : >
13+ github.event.workflow_run.event == 'pull_request'
14+ steps :
15+ - name : Download artifact
16+ uses : actions/github-script@v6
17+ with :
18+ script : |
19+ var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
20+ owner: context.repo.owner,
21+ repo: context.repo.repo,
22+ run_id: ${{github.event.workflow_run.id }},
23+ });
24+ var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
25+ return artifact.name == "pr"
26+ })[0];
27+ var download = await github.rest.actions.downloadArtifact({
28+ owner: context.repo.owner,
29+ repo: context.repo.repo,
30+ artifact_id: matchArtifact.id,
31+ archive_format: 'zip',
32+ });
33+ var fs = require('fs');
34+ fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
35+ - run : unzip pr.zip
36+
37+ - name : Build success
38+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
39+ uses : actions/github-script@v6
40+ with :
41+ script : |
42+ var fs = require('fs')
43+ var issue_number = Number(fs.readFileSync('./NR'));
44+ const owner = context.repo.owner;
45+ const repo = context.repo.repo;
46+ var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
47+ owner,
48+ repo,
49+ run_id: ${{github.event.workflow_run.id }},
50+ });
51+ var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
52+ return artifact.name == "apk-files"
53+ })[0];
54+ const artifact_url = `https://github.com/${owner}/${repo}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${matchArtifact.id}`;
55+
56+ const comments = await github.rest.issues.listComments({
57+ owner,
58+ repo,
59+ issue_number
60+ });
61+
62+ let comment_id;
63+ for (const comment of comments.data) {
64+ if (comment.user.type === 'Bot') {
65+ comment_id = comment.id;
66+ break;
67+ }
68+ }
69+
70+ const body = `Build successful. APKs to test: ${artifact_url}`;
71+
72+ if (comment_id) {
73+ await github.rest.issues.updateComment({
74+ owner,
75+ repo,
76+ comment_id,
77+ body
78+ });
79+ } else {
80+ await github.rest.issues.createComment({
81+ owner,
82+ repo,
83+ issue_number,
84+ body
85+ });
86+ }
87+
88+ - name : Build failed
89+ if : ${{ github.event.workflow_run.conclusion == 'failure' }}
90+ uses : actions/github-script@v6
91+ with :
92+ script : |
93+ var fs = require('fs')
94+ var issue_number = Number(fs.readFileSync('./NR'));
95+ const owner = context.repo.owner;
96+ const repo = context.repo.repo;
97+
98+ const comments = await github.rest.issues.listComments({
99+ owner,
100+ repo,
101+ issue_number
102+ });
103+
104+ let comment_id;
105+ for (const comment of comments.data) {
106+ if (comment.user.type === 'Bot') {
107+ comment_id = comment.id;
108+ break;
109+ }
110+ }
111+
112+ const body = `Build failed`;
113+
114+ if (comment_id) {
115+ await github.rest.issues.updateComment({
116+ owner,
117+ repo,
118+ comment_id,
119+ body
120+ });
121+ } else {
122+ await github.rest.issues.createComment({
123+ owner,
124+ repo,
125+ issue_number,
126+ body
127+ });
128+ }
0 commit comments