Skip to content

Commit 5717f21

Browse files
author
Antoine THEBAUD
committed
WIP better diff output
Signed-off-by: Antoine THEBAUD <[email protected]>
1 parent c70b6ae commit 5717f21

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

actions/diff_dashboards/action.yaml

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,43 @@ runs:
2929
$([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}")
3030
shell: bash
3131

32-
- name: Upload diffs as artifacts
33-
uses: actions/upload-artifact@v4
34-
with:
35-
name: dashboard-diffs
36-
path: built/
37-
38-
- name: Post artifacts link to PR
32+
- name: Post diffs as PR comments
3933
if: ${{ github.event_name == 'pull_request' }}
4034
uses: actions/github-script@v7
4135
with:
4236
script: |
43-
const runId = process.env.GITHUB_RUN_ID;
44-
const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
45-
const artifactUrl = `${repoUrl}/actions/runs/${runId}`;
46-
const commentBody = `### Dashboard diffs\nThe dashboard diffs can be downloaded from the [workflow artifacts](artifactUrl).`;
37+
const fs = require('fs');
38+
const path = require('path');
39+
40+
// Directory containing the diff files
41+
const diffDir = './built';
42+
43+
// Filter files to include only those with a `.diff` extension
44+
const diffFiles = fs.readdirSync(diffDir).filter(file => file.endsWith('.diff'));
45+
46+
if (diffFiles.length === 0) {
47+
console.log('No diff files found to comment.');
48+
return;
49+
}
50+
51+
// Generate the PR comment with collapsible sections
52+
let commentBody = `### Dashboard diffs\n\n`;
53+
for (const file of diffFiles) {
54+
const diffContent = fs.readFileSync(path.join(diffDir, file), 'utf-8');
55+
commentBody += `
56+
<details>
57+
<summary>Diff for ${file}</summary>
58+
59+
\`\`\`diff
60+
${diffContent}
61+
\`\`\`
62+
</details>\n\n`;
63+
}
64+
65+
// Post the comment
4766
github.rest.issues.createComment({
4867
owner: context.repo.owner,
4968
repo: context.repo.repo,
5069
issue_number: context.issue.number,
51-
body: commentBody.replace('artifactUrl', artifactUrl)
70+
body: commentBody.trim() // Ensure no trailing newlines
5271
});

testdata/resources_folder/dashboard.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"spec": {
1111
"display": {
12-
"name": "Empty Dashboard"
12+
"name": "Emptyeeeee Dashboard"
1313
},
1414
"panels": {},
1515
"layouts": [],

0 commit comments

Comments
 (0)