Skip to content

Commit b3917d1

Browse files
committed
wip: switch to repository_dispatch
wip Signed-off-by: George Sapkin <[email protected]>
1 parent fc6233b commit b3917d1

File tree

3 files changed

+26
-161
lines changed

3 files changed

+26
-161
lines changed

.github/workflows/build-report.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/formal.yml

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
pull_request_target:
55

66
permissions:
7-
contents: read
7+
# for dispatch
8+
contents: write
89
pull-requests: write
910

1011
jobs:
@@ -21,49 +22,13 @@ jobs:
2122
if: always()
2223

2324
steps:
24-
- name: Post status comment
25-
uses: actions/github-script@v8
26-
env:
27-
RESULT: ${{ needs.formalities.result }}
25+
- name: Trigger build
26+
if: needs.formalities.result == 'success'
27+
uses: peter-evans/repository-dispatch@v3
2828
with:
29-
github-token: ${{ secrets.DEFAULT_TOKEN }}
30-
script: |
31-
const marker = "<!-- BUILD_LOOKUP -->";
32-
const result = process.env.RESULT;
33-
34-
const status = {
35-
build: result === 'success',
36-
timestamp: new Date().toISOString(),
37-
};
38-
39-
const body = `Build info<!-- ${JSON.stringify(status)} -->\n${marker}`;
40-
const { data: comments } = await github.rest.issues.listComments({
41-
owner: context.repo.owner,
42-
repo: context.repo.repo,
43-
issue_number: context.issue.number,
44-
});
45-
46-
const previousComment = comments.find(comment => comment.body.includes(marker));
47-
let commentId = null;
48-
if (previousComment != null) {
49-
await github.rest.issues.updateComment({
50-
owner: context.repo.owner,
51-
repo: context.repo.repo,
52-
comment_id: previousComment.id,
53-
body: body,
54-
});
55-
56-
commentId = previousComment.node_id;
57-
} else {
58-
const res = await github.rest.issues.createComment({
59-
owner: context.repo.owner,
60-
repo: context.repo.repo,
61-
issue_number: context.issue.number,
62-
body: body,
63-
});
64-
65-
commentId = res?.node_id;
66-
}
29+
repository: ${{ github.repository }}
30+
event-type: run-build
31+
client-payload: '{ "pull_request": { "number": ${{ github.event.pull_request.number }} } }'
6732

6833
- name: Add 'not following guidelines' label
6934
if: needs.formalities.result == 'failure'
Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,40 @@
11
name: Test and Build
22

33
on:
4-
issue_comment:
5-
types: [created, edited]
4+
repository_dispatch:
5+
types: [run-build]
66

77
permissions:
88
contents: read
99

1010
jobs:
11-
formalities:
12-
name: Check Formalities Result
13-
if: ${{ github.event.issue.pull_request }}
14-
runs-on: ubuntu-slim
15-
outputs:
16-
build: ${{ steps.parse.outputs.build }}
11+
prepare:
12+
name: Feeds Package Test Build
13+
runs-on: ubuntu-latest
1714
steps:
18-
- name: Get PR info
19-
id: get_pr
15+
- name: Extract PR Data
16+
id: get_pr_data
2017
uses: actions/github-script@v8
2118
with:
2219
script: |
20+
const prNumber = context.payload.client_payload.pull_request.number;
21+
if (!prNumber) {
22+
core.setFailed('Pull request number not found in the event payload.');
23+
return;
24+
}
25+
2326
const { data: pr } = await github.rest.pulls.get({
2427
owner: context.repo.owner,
2528
repo: context.repo.repo,
26-
pull_number: context.issue.number,
29+
pull_number: prNumber,
2730
});
28-
core.setOutput('sha', pr.head.sha);
31+
core.setOutput('head_sha', pr.head.sha);
2932
30-
- name: Checkout PR
33+
- name: Checkout PR Code
3134
uses: actions/checkout@v4
3235
with:
33-
ref: ${{ steps.get_pr.outputs.sha }}
34-
35-
- name: Parse comment for build status
36-
id: parse
37-
uses: actions/github-script@v8
38-
env:
39-
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
40-
with:
41-
script: |
42-
const allowedBot = process.env.BOT_USERNAME;
43-
if (!allowedBot || context.payload.sender.login.toLowerCase() !== allowedBot.toLowerCase()) {
44-
console.log(`Comment is not from the allowed bot ('${allowedBot}'). Sender was '${context.payload.sender.login}'. Skipping.`);
45-
core.setOutput('build', 'skip');
46-
return;
47-
}
48-
49-
const body = context.payload.comment.body;
50-
const marker = "<!-- BUILD_LOOKUP -->";
51-
52-
if (!body.includes(marker)) {
53-
console.log('Comment does not contain the build marker. Skipping.');
54-
core.setOutput('build', 'skip');
55-
return;
56-
}
57-
58-
const regex = /Build info<!-- (.*) -->/;
59-
const match = body.match(regex);
60-
61-
if (match && match[1]) {
62-
const { build } = JSON.parse(match[1]);
63-
core.setOutput('build', build.toString());
64-
}
65-
36+
ref: ${{ steps.get_pr_data.outputs.head_sha }}
6637
build:
6738
name: Feeds Package Test Build
68-
needs: formalities
69-
if: needs.formalities.outputs.build == 'true'
39+
needs: prepare
7040
uses: openwrt/actions-shared-workflows/.github/workflows/multi-arch-test-build.yml@main

0 commit comments

Comments
 (0)