Skip to content

Commit

Permalink
WIP better diff output
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine THEBAUD <[email protected]>
  • Loading branch information
Antoine THEBAUD committed Dec 12, 2024
1 parent c70b6ae commit 1bcfd26
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
52 changes: 40 additions & 12 deletions actions/diff_dashboards/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,52 @@ runs:
$([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}")
shell: bash

- name: Upload diffs as artifacts
uses: actions/upload-artifact@v4
with:
name: dashboard-diffs
path: built/

- name: Post artifacts link to PR
- name: Post diffs as PR comments
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
script: |
const runId = process.env.GITHUB_RUN_ID;
const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
const artifactUrl = `${repoUrl}/actions/runs/${runId}`;
const commentBody = `### Dashboard diffs\nThe dashboard diffs can be downloaded from the [workflow artifacts](artifactUrl).`;
const fs = require('fs');
const path = require('path');
// Directory containing the diff files
const diffDir = './built';
// Filter files to include only those with a `.diff` extension
const diffFiles = fs.readdirSync(diffDir).filter(file => file.endsWith('.diff'));
if (diffFiles.length === 0) {
console.log('No diff files found to comment.');
return;
}
// Generate the PR comment with collapsible sections
let commentBody = `### Dashboard diffs\n\n`;
for (const file of diffFiles) {
const filePath = path.join(diffDir, file);
const diffContent = fs.readFileSync(filePath, 'utf-8').trim();
if (diffContent) {
// Include a collapsible section for non-empty diffs
commentBody += `
<details>
<summary>${file}</summary>
\`\`\`diff
${diffContent}
\`\`\`
</details>\n\n
`;
} else {
// Add a plain "No change" message for empty diffs
commentBody += `- ${file}\nNo change\n`;
}
}
// Post the comment
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody.replace('artifactUrl', artifactUrl)
body: commentBody.trim() // Ensure no trailing newlines
});
20 changes: 20 additions & 0 deletions testdata/resources_folder/dashboard copy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"kind": "Dashboard",
"metadata": {
"name": "nodeexporterfull",
"createdAt": "2024-12-04T15:08:03.737189012Z",
"updatedAt": "2024-12-04T15:08:03.737189012Z",
"version": 0,
"project": "perses"
},
"spec": {
"display": {
"name": "Emptyeeeee Dashboard"
},
"panels": {},
"layouts": [],
"variables": [],
"duration": "1h",
"refreshInterval": "0s"
}
}
2 changes: 1 addition & 1 deletion testdata/resources_folder/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"spec": {
"display": {
"name": "Empty Dashboard"
"name": "Emptyeeeee Dashboard"
},
"panels": {},
"layouts": [],
Expand Down

0 comments on commit 1bcfd26

Please sign in to comment.