Skip to content

Commit fa9b1ab

Browse files
committed
CI: Only build for PRs and BEs for master
1 parent b50a18a commit fa9b1ab

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

.github/workflows/build.yml .github/workflows/build_pr.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
name: Basic build
1+
name: Build PR
22

33
on:
4-
push:
5-
branches-ignore:
6-
- master # For master, we use special BE build workflow
74
pull_request:
5+
branches:
6+
- master
87

98
jobs:
109
build:

.github/workflows/comment_pr.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Comment on pull request
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Build PR']
6+
types: [completed]
7+
8+
jobs:
9+
pr_comment:
10+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/github-script@v5
14+
with:
15+
# This snippet is public-domain, taken from
16+
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
17+
script: |
18+
async function upsertComment(owner, repo, issue_number, purpose, body) {
19+
const {data: comments} = await github.rest.issues.listComments(
20+
{owner, repo, issue_number});
21+
22+
const marker = `<!-- bot: ${purpose} -->`;
23+
body = marker + "\n" + body;
24+
25+
const existing = comments.filter((c) => c.body.includes(marker));
26+
if (existing.length > 0) {
27+
const last = existing[existing.length - 1];
28+
core.info(`Updating comment ${last.id}`);
29+
await github.rest.issues.updateComment({
30+
owner, repo,
31+
body,
32+
comment_id: last.id,
33+
});
34+
} else {
35+
core.info(`Creating a comment in issue / PR #${issue_number}`);
36+
await github.rest.issues.createComment({issue_number, body, owner, repo});
37+
}
38+
}
39+
40+
const {owner, repo} = context.repo;
41+
const run_id = ${{github.event.workflow_run.id}};
42+
43+
const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }};
44+
if (!pull_requests.length) {
45+
return core.error("This workflow doesn't match any pull requests!");
46+
}
47+
48+
const artifacts = await github.paginate(
49+
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
50+
if (!artifacts.length) {
51+
return core.error(`No artifacts found`);
52+
}
53+
let body = `Download the artifacts for this pull request:\n`;
54+
for (const art of artifacts) {
55+
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
56+
}
57+
58+
core.info("Review thread message body:", body);
59+
60+
for (const pr of pull_requests) {
61+
await upsertComment(owner, repo, pr.number,
62+
"nightly-link", body);
63+
}

0 commit comments

Comments
 (0)