-
Notifications
You must be signed in to change notification settings - Fork 6
147 lines (127 loc) · 5.32 KB
/
comment.yml
File metadata and controls
147 lines (127 loc) · 5.32 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
138
139
140
141
142
143
144
145
146
147
# ─────────────────────────────────────────────────────────────
# Moonfin Plugin — PR Comment Workflow
# ─────────────────────────────────────────────────────────────
#
# Triggered by: workflow_run (after the Build workflow completes)
#
# Security:
# This workflow runs in the context of the base repo and has
# write access to PRs. It NEVER checks out or executes code
# from the PR — it only reads the build-results artifact
# uploaded by the (read-only) 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');
// Read outcomes metadata
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}`;
const steps = {
'Frontend Install': outcomes.frontend_install,
'Frontend Build': outcomes.frontend_build,
'Backend Build': outcomes.backend_build,
};
const failed = Object.entries(steps).filter(([, v]) => v === 'failure');
const skipped = Object.entries(steps).filter(([, v]) => v === 'skipped');
const success = failed.length === 0 && skipped.length === 0;
const lines = [marker];
if (success) {
lines.push(
'## ✅ Build Successful',
'',
'The plugin compiled successfully against **.NET 8** / **Jellyfin 10.10.0**.',
);
} else {
lines.push(
'## ❌ Build Failed',
'',
`The following step(s) failed: **${failed.map(([k]) => k).join('**, **')}**`,
);
if (skipped.length > 0) {
lines.push(`Skipped due to earlier failure: ${skipped.map(([k]) => k).join(', ')}`);
}
// Append collapsible log for each failed step
const logFiles = {
'Frontend Install': 'frontend-install.log',
'Frontend Build': 'frontend-build.log',
'Backend Build': 'backend-build.log',
};
for (const [name] of failed) {
const logPath = `build-results/${logFiles[name]}`;
let log = '';
try {
const full = fs.readFileSync(logPath, 'utf8');
const logLines = full.split('\n');
log = logLines.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)}\` |`,
`| **Workflow** | [Build #${context.payload.workflow_run.run_number}](${runUrl}) |`,
);
const body = lines.join('\n');
// Find existing comment to update
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,
});
}