Skip to content

Commit 3535be0

Browse files
authored
[MISC] Fix PR comment in case of perf regression. (#1994)
1 parent 42f51c4 commit 3535be0

File tree

1 file changed

+32
-42
lines changed

1 file changed

+32
-42
lines changed

.github/workflows/alarm.yml

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ jobs:
6161

6262
# Input/Output paths
6363
ARTIFACTS_DIR: ${{ steps.dl.outputs.download-path }}
64-
PR_COMMENT_PATH: pr_comment.md
6564
CHECK_BODY_PATH: check_output.md
6665
CSV_RUNTIME_PATH: runtime_fps.csv
6766
CSV_COMPILE_PATH: compile_time.csv
@@ -86,8 +85,6 @@ jobs:
8685
}
8786
8887
artifacts_dir = Path(os.environ["ARTIFACTS_DIR"]).expanduser().resolve()
89-
90-
pr_comment_path = Path(os.environ["PR_COMMENT_PATH"]).expanduser()
9188
check_body_path = Path(os.environ["CHECK_BODY_PATH"]).expanduser()
9289
9390
csv_files = {
@@ -158,7 +155,6 @@ jobs:
158155
159156
current_csv_paths = list(artifacts_dir.rglob("speed_test*.txt"))
160157
if not current_csv_paths:
161-
pr_comment_path.touch()
162158
check_body_path.touch()
163159
sys.exit(0)
164160
@@ -367,7 +363,6 @@ jobs:
367363
368364
# write md results
369365
check_body_path.write_text(check_body + "\n", encoding="utf-8")
370-
pr_comment_path.write_text(comment_body + "\n", encoding="utf-8")
371366
372367
# Exit with 42 if regressions are found, 0 otherwise
373368
sys.exit(int(os.environ["EXIT_CODE_REGRESSION"]) if reg_found else 0)
@@ -387,17 +382,6 @@ jobs:
387382
echo "CHECK_OUTPUT=" >> "$GITHUB_ENV"
388383
fi
389384
390-
# Only set SCRIPT_OUTPUT when we actually want to comment
391-
if [ "$EXIT_CODE" = "$EXIT_CODE_REGRESSION" ] && [ -s "$PR_COMMENT_PATH" ]; then
392-
{
393-
echo 'SCRIPT_OUTPUT<<__EOF__'
394-
cat "$PR_COMMENT_PATH"
395-
echo '__EOF__'
396-
} >> "$GITHUB_ENV"
397-
else
398-
echo "SCRIPT_OUTPUT=" >> "$GITHUB_ENV"
399-
fi
400-
401385
# Export status
402386
echo "CONCLUSION=$([ "$EXIT_CODE" = "0" ] && echo 'success' || echo 'failure')" >> "$GITHUB_ENV"
403387
echo "HAS_REGRESSIONS=$([ "$EXIT_CODE" = "$EXIT_CODE_REGRESSION" ] && echo 1 || echo 0)" >> "$GITHUB_ENV"
@@ -412,33 +396,8 @@ jobs:
412396
compile_time.csv
413397
if-no-files-found: warn
414398

415-
- name: Add PR comment
416-
if: ${{ env.SCRIPT_OUTPUT != '' }}
417-
uses: actions/github-script@v8
418-
env:
419-
COMMENT_BODY: ${{ env.SCRIPT_OUTPUT }}
420-
with:
421-
script: |
422-
// Getting PR number when using 'workflow_run' is tricky. For reference, see:
423-
// * https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_run
424-
// * https://stackoverflow.com/a/75420270/4820605
425-
const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
426-
owner: context.payload.workflow_run.head_repository.owner.login,
427-
repo: context.payload.workflow_run.head_repository.name,
428-
commit_sha: context.payload.workflow_run.head_sha,
429-
});
430-
if (!data || !data.length) {
431-
core.info('No associated PR; skipping comment.');
432-
return;
433-
}
434-
await github.rest.issues.createComment({
435-
owner: context.repo.owner,
436-
repo: context.repo.repo,
437-
issue_number: data[0].number,
438-
body: process.env.COMMENT_BODY
439-
});
440-
441399
- name: Publish PR check
400+
id: publish_check
442401
uses: actions/github-script@v8
443402
env:
444403
CHECK_NAME: Benchmark Comparison
@@ -470,3 +429,34 @@ jobs:
470429
text: body || undefined
471430
}
472431
});
432+
core.setOutput("check-url", check.data.html_url);
433+
434+
- name: Add PR comment
435+
if: ${{ env.HAS_REGRESSIONS == '1' }}
436+
uses: actions/github-script@v8
437+
env:
438+
REPORT_URL: ${{ steps.publish_check.outputs.check-url }}
439+
with:
440+
script: |
441+
// Getting PR number when using 'workflow_run' is tricky. For reference, see:
442+
// * https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_run
443+
// * https://stackoverflow.com/a/75420270/4820605
444+
const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
445+
owner: context.payload.workflow_run.head_repository.owner.login,
446+
repo: context.payload.workflow_run.head_repository.name,
447+
commit_sha: context.payload.workflow_run.head_sha,
448+
});
449+
if (!data || !data.length) {
450+
core.info('No associated PR; skipping comment.');
451+
return;
452+
}
453+
454+
const comment = `:warning: **Benchmark Regression Detected**
455+
➡️ **[Open Benchmark Comparison Report](${process.env.REPORT_URL})**`;
456+
457+
await github.rest.issues.createComment({
458+
owner: context.repo.owner,
459+
repo: context.repo.repo,
460+
issue_number: data[0].number,
461+
body: comment
462+
});

0 commit comments

Comments
 (0)