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 5717f21
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
43 changes: 31 additions & 12 deletions actions/diff_dashboards/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,43 @@ 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 diffContent = fs.readFileSync(path.join(diffDir, file), 'utf-8');
commentBody += `
<details>
<summary>Diff for ${file}</summary>
\`\`\`diff
${diffContent}
\`\`\`
</details>\n\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
});
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 5717f21

Please sign in to comment.