Skip to content

Commit 09a08a5

Browse files
authored
chore: updated pull request pipeline to configure comments (#2487)
1 parent 08383cc commit 09a08a5

File tree

2 files changed

+153
-16
lines changed

2 files changed

+153
-16
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
}

.github/workflows/pull-request.yml

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,31 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: Download repository
15-
uses: actions/checkout@v3
14+
- name: Download repository
15+
uses: actions/checkout@v3
1616

17-
- name: Setup Java
18-
uses: actions/setup-java@v3
19-
with:
20-
distribution: 'adopt'
21-
java-version: '17'
17+
- name: Setup Java
18+
uses: actions/setup-java@v3
19+
with:
20+
distribution: 'adopt'
21+
java-version: '17'
2222

23-
- name: Build with Gradle
24-
run: |
25-
bash ./gradlew build --stacktrace
23+
- name: Build with Gradle
24+
run: |
25+
bash ./gradlew build --stacktrace
2626
27-
- name: Store APK file
28-
uses: actions/upload-artifact@v3
29-
with:
30-
name: apk-files
31-
path: |
32-
app/build/outputs/apk/debug/app-debug.apk
27+
- name: Store APK file
28+
uses: actions/upload-artifact@v3
29+
with:
30+
name: apk-files
31+
path: |
32+
app/build/outputs/apk/debug/app-debug.apk
33+
34+
- name: Save PR number
35+
run: |
36+
mkdir -p ./pr
37+
echo ${{ github.event.number }} > ./pr/NR
38+
- uses: actions/upload-artifact@v3
39+
with:
40+
name: pr
41+
path: pr/

0 commit comments

Comments
 (0)