-
Notifications
You must be signed in to change notification settings - Fork 32
122 lines (106 loc) · 4.75 KB
/
pr-comment.yml
File metadata and controls
122 lines (106 loc) · 4.75 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# ─────────────────────────────────────────────────────────────
# Moonfin Smart-TV — PR Comment Workflow
# ─────────────────────────────────────────────────────────────
#
# Triggered by: workflow_run (after the Build workflow completes on a PR)
#
# Security:
# Runs in the context of the base repo with PR write access.
# NEVER checks out or executes code from the PR branch —
# only reads the build-results artifact uploaded by the
# (sandboxed) build workflow.
# ─────────────────────────────────────────────────────────────
name: PR Comment
on:
workflow_run:
workflows: [Build]
types: [completed]
permissions:
pull-requests: write
actions: read
jobs:
comment:
name: Post Build Results
runs-on: ubuntu-latest
if: >-
github.event.workflow_run.event == 'pull_request' &&
(github.event.workflow_run.conclusion == 'success' ||
github.event.workflow_run.conclusion == 'failure')
steps:
- name: Download build results
uses: actions/download-artifact@v4
with:
name: build-results
path: build-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Post PR comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const outcomes = JSON.parse(fs.readFileSync('build-results/outcomes.json', 'utf8'));
const prNumber = outcomes.pr_number;
const sha = outcomes.sha;
const webos = outcomes.webos;
const tizen = outcomes.tizen;
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.payload.workflow_run.id}`;
const artifactsUrl = `${runUrl}#artifacts`;
const icon = (r) => r === 'success' ? '✅' : r === 'failure' ? '❌' : '⚠️';
const label = (r) => r === 'success' ? 'Passed' : r === 'failure' ? 'Failed' : 'Skipped';
const overallSuccess = webos === 'success' && tizen === 'success';
const marker = '<!-- moonfin-build-result -->';
const lines = [marker];
if (overallSuccess) {
lines.push(
'## ✅ Build Successful',
'',
'All platform builds passed. You can download the test artifacts below.',
'',
`| Platform | Status | Artifact |`,
`|---|---|---|`,
`| **webOS** | ✅ Passed | [Moonfin_webOS_*.ipk](${artifactsUrl}) |`,
`| **Tizen Regular** | ✅ Passed | [Moonfin_Tizen_Regular_*.wgt](${artifactsUrl}) |`,
`| **Tizen Oblong** | ✅ Passed | [Moonfin_Tizen_Oblong_*.wgt](${artifactsUrl}) |`,
`| **Tizen Legacy** | ✅ Passed | [Moonfin_Tizen_Legacy_*.wgt](${artifactsUrl}) |`,
);
} else {
lines.push(
'## ❌ Build Failed',
'',
`| Platform | Status |`,
`|---|---|`,
`| **webOS** | ${icon(webos)} ${label(webos)} |`,
`| **Tizen** | ${icon(tizen)} ${label(tizen)} |`,
);
}
lines.push(
'',
`| Property | Value |`,
`|---|---|`,
`| **Commit** | \`${sha.substring(0, 7)}\` |`,
`| **Workflow run** | [Build #${context.payload.workflow_run.run_number}](${runUrl}) |`,
);
const body = lines.join('\n');
// Update existing comment or create a new one
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body?.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}