Skip to content

Commit ec991b1

Browse files
authored
Merge pull request #98 from Provenance-Emu/libretro/fix/artifact-links
Post build artifact links as PR comments
2 parents d071e7b + dfff0da commit ec991b1

2 files changed

Lines changed: 75 additions & 20 deletions

File tree

.github/workflows/artifacts.yml

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

.github/workflows/c-cpp.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
pull_request:
77
branches: [ master ]
88

9+
permissions:
10+
actions: read
11+
contents: read
12+
pull-requests: write
13+
914
jobs:
1015
build:
1116
strategy:
@@ -75,3 +80,73 @@ jobs:
7580
name: ${{ matrix.config.displayTargetName }}
7681
path: ${{ matrix.config.artifact }}
7782
if-no-files-found: error
83+
84+
post-artifacts:
85+
if: github.event_name == 'pull_request'
86+
needs: build
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Comment artifact links on PR
90+
continue-on-error: true
91+
uses: actions/github-script@v7
92+
with:
93+
script: |
94+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
95+
96+
// Fetch actual artifact list from this workflow run
97+
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
run_id: context.runId,
101+
});
102+
103+
let rows = '';
104+
for (const a of artifacts) {
105+
const dlUrl = `${runUrl}/artifacts/${a.id}`;
106+
rows += `| ${a.name} | [${a.name}](${dlUrl}) | ${(a.size_in_bytes / 1024).toFixed(0)} KB |\n`;
107+
}
108+
109+
if (!rows) {
110+
rows = `| - | No artifacts found | - |\n`;
111+
}
112+
113+
const comments = await github.paginate(
114+
github.rest.issues.listComments,
115+
{
116+
owner: context.repo.owner,
117+
repo: context.repo.repo,
118+
issue_number: context.issue.number,
119+
per_page: 100,
120+
}
121+
);
122+
const marker = '<!-- build-artifacts -->';
123+
const existing = comments.find(c => c.body.includes(marker));
124+
125+
const body = [
126+
marker,
127+
'### Build Artifacts',
128+
'',
129+
'| Platform | Download | Size |',
130+
'|----------|----------|------|',
131+
rows.trim(),
132+
'',
133+
`> [Full workflow run](${runUrl})`,
134+
'',
135+
`<sub>Updated by CI at ${new Date().toISOString()}</sub>`,
136+
].join('\n');
137+
138+
if (existing) {
139+
await github.rest.issues.updateComment({
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
comment_id: existing.id,
143+
body,
144+
});
145+
} else {
146+
await github.rest.issues.createComment({
147+
owner: context.repo.owner,
148+
repo: context.repo.repo,
149+
issue_number: context.issue.number,
150+
body,
151+
});
152+
}

0 commit comments

Comments
 (0)