diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 489f379..e895408 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -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 += ` +
+ Diff for ${file} + + \`\`\`diff + ${diffContent} + \`\`\` +
\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 }); \ No newline at end of file diff --git a/testdata/resources_folder/dashboard.json b/testdata/resources_folder/dashboard.json index fa26045..e64d700 100644 --- a/testdata/resources_folder/dashboard.json +++ b/testdata/resources_folder/dashboard.json @@ -9,7 +9,7 @@ }, "spec": { "display": { - "name": "Empty Dashboard" + "name": "Emptyeeeee Dashboard" }, "panels": {}, "layouts": [],