Repository navigation
137 lines (119 loc) · 4.95 KB
/
Copy pathcomment.yml
File metadata and controls
137 lines (119 loc) · 4.95 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Posts one build-status comment on a pull request and rewrites it in place on
# every new commit. It runs on workflow_run rather than pull_request so it still
# has write access on pull requests from forks. It never checks out the branch,
# it only reads the artifact the build uploaded.
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
id: results
continue-on-error: true
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
if: steps.results.outcome == 'success'
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 marker = '<!-- moonfin-build-result -->';
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.payload.workflow_run.id}`;
// The build fails the run when any of these fails, so every one has to
// be reported or a red run can carry a green comment. A build from
// before a step existed reports no outcome, which is not a failure.
const STEPS = [
['Jellyfin build', outcomes.backend_build, 'backend-build.log'],
['Emby build', outcomes.emby_build, 'emby-build.log'],
['Jellyfin tests', outcomes.tests, 'tests.log'],
['Jellyfin salvage tests', outcomes.salvage_tests, 'salvage-tests.log'],
['Emby tests', outcomes.emby_tests, 'emby-tests.log'],
];
const failed = STEPS.filter(
([, outcome]) => outcome !== undefined && outcome !== 'success');
const lines = [marker];
if (!failed.length) {
lines.push(
'## Build Successful',
'',
'Both plugins compiled against **.NET 8**, and both test suites passed.',
);
} else {
lines.push(
'## Build Failed',
'',
`The following step(s) failed: **${failed.map(([name]) => name).join('**, **')}**`,
);
for (const [name, , logFile] of failed) {
let log;
try {
log = fs.readFileSync(`build-results/${logFile}`, 'utf8')
.split('\n').slice(-50).join('\n');
} catch { log = '_Log file not available._'; }
lines.push(
'',
`<details><summary>${name} log (last 50 lines)</summary>`,
'',
'```',
log,
'```',
'',
'</details>',
);
}
}
lines.push(
'',
`| Property | Value |`,
`|---|---|`,
`| **Commit** | \`${sha.substring(0, 7)}\` |`,
);
if (outcomes.jellyfin_abi) lines.push(`| **Jellyfin ABI** | \`${outcomes.jellyfin_abi}\` |`);
if (outcomes.emby_version) lines.push(`| **Emby version** | \`${outcomes.emby_version}\` |`);
lines.push(`| **Workflow** | [Build #${context.payload.workflow_run.run_number}](${runUrl}) |`);
const body = lines.join('\n');
// Paginated because the marker falls off the first page once a pull
// request collects more than 30 comments, which would post a second
// comment instead of updating the first.
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
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,
});
}