Make CI collapse previous PR comments with profiling benchmark deltas (#1974)

CI change again

CI collapse by default
This commit is contained in:
Keavon Chambers 2024-09-13 22:54:33 -07:00 committed by GitHub
parent 514582fd8d
commit 426f3b2cb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 14 deletions

View File

@ -1,4 +1,4 @@
name: "Editor: CI & Dev" name: "Editor: Dev & CI"
on: on:
push: push:

View File

@ -54,7 +54,7 @@ jobs:
repo: context.repo.repo, repo: context.repo.repo,
}); });
const botComments = comments.filter(comment => const botComments = comments.filter((comment) =>
comment.user.type === 'Bot' && comment.body.includes('Clippy Warnings/Errors') comment.user.type === 'Bot' && comment.body.includes('Clippy Warnings/Errors')
); );

View File

@ -1,4 +1,4 @@
name: Profiling name: Profiling Changes
on: on:
pull_request: pull_request:
@ -23,8 +23,8 @@ jobs:
- name: Install Valgrind - name: Install Valgrind
run: | run: |
sudo apt-get update sudo apt update
sudo apt-get install -y valgrind sudo apt install -y valgrind
- name: Cache dependencies - name: Cache dependencies
uses: actions/cache@v3 uses: actions/cache@v3
@ -60,6 +60,31 @@ jobs:
echo "$BENCH_OUTPUT" >> $GITHUB_OUTPUT echo "$BENCH_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT
- name: Make old comments collapsed by default
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComments = comments.filter((comment) =>
comment.user.type === 'Bot' && comment.body.includes('Performance Benchmark Results') && comment.body.includes('<details open>')
);
for (const comment of botComments) {
// Edit the comment to remove the "open" attribute from the <details> tag
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: comment.body.replace('<details open>', '<details>')
});
}
- name: Comment PR - name: Comment PR
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
@ -67,25 +92,25 @@ jobs:
script: | script: |
const benchmarkOutput = JSON.parse(`${{ steps.benchmark.outputs.BENCHMARK_OUTPUT }}`); const benchmarkOutput = JSON.parse(`${{ steps.benchmark.outputs.BENCHMARK_OUTPUT }}`);
let significantChanges = false; let significantChanges = false;
let commentBody = "#### Performance Benchmark Results\n\n"; let commentBody = "";
function formatNumber(num) { function formatNumber(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
function formatPercentage(pct) { function formatPercentage(pct) {
const sign = pct >= 0 ? '+' : ''; const sign = pct >= 0 ? '+' : '';
return `${sign}${pct.toFixed(2)}%`; return `${sign}${pct.toFixed(2)}%`;
} }
function padRight(str, len) { function padRight(str, len) {
return str.padEnd(len); return str.padEnd(len);
} }
function padLeft(str, len) { function padLeft(str, len) {
return str.padStart(len); return str.padStart(len);
} }
for (const benchmark of benchmarkOutput) { for (const benchmark of benchmarkOutput) {
if (benchmark.callgrind_summary && benchmark.callgrind_summary.summaries) { if (benchmark.callgrind_summary && benchmark.callgrind_summary.summaries) {
const summary = benchmark.callgrind_summary.summaries[0]; const summary = benchmark.callgrind_summary.summaries[0];
@ -119,15 +144,25 @@ jobs:
} }
} }
} }
const output = `
<details open>
<summary>Performance Benchmark Results</summary>
${commentBody}
</details>
`;
if (significantChanges) { if (significantChanges) {
github.rest.issues.createComment({ github.rest.issues.createComment({
issue_number: context.issue.number, issue_number: context.issue.number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: commentBody body: output
}); });
} else { } else {
console.log("No significant performance changes detected. Skipping comment."); console.log("No significant performance changes detected. Skipping comment.");
console.log(commentBody); console.log(output);
} }