From f37aad32ca51bdf01a5ef0c948f2d7a056875c24 Mon Sep 17 00:00:00 2001 From: Aner Ben Efraim Date: Wed, 7 May 2025 16:49:24 +0300 Subject: [PATCH] fix(ci): update committer benchmark comment --- .github/workflows/committer_ci.yml | 43 +++++++++++++------ .../benches/bench_split_and_prepare_post.sh | 5 ++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.github/workflows/committer_ci.yml b/.github/workflows/committer_ci.yml index 2443fdb960b..321416d2fb3 100644 --- a/.github/workflows/committer_ci.yml +++ b/.github/workflows/committer_ci.yml @@ -103,17 +103,34 @@ jobs: - run: echo BENCHES_RESULT=$(cat bench_new.txt) >> $GITHUB_ENV - # Post comment in case of performance regression or improvement. - - run: npm install fs - - if: contains(env.BENCHES_RESULT, 'regressed') || contains(env.BENCHES_RESULT, 'improved') - uses: actions/github-script@v6 + # Comment with a link to the workflow (or update existing comment on rerun). + - name: Find Comment + if: github.event_name == 'pull_request' + uses: starkware-libs/find-comment@v3 + id: find-benchmark-comment with: - script: | - const fs = require('fs') - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: fs.readFileSync('bench_new.txt', 'utf8'), - path: 'Commits' - }) + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Benchmark movements + + - name: Create comment + # If the PR number is found and the comment is not found, create a new comment. + if: github.event_name == 'pull_request' + && steps.find-benchmark-comment.outputs.comment-id == '' + uses: starkware-libs/create-or-update-comment@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: ${{ env.BENCHES_RESULT }} + + - name: Update comment + # If the PR number is found and the comment exists, update it. + if: github.event_name == 'pull_request' + && steps.find-benchmark-comment.outputs.comment-id != '' + uses: starkware-libs/create-or-update-comment@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + comment-id: ${{ steps.find-benchmark-comment.outputs.comment-id }} + edit-mode: replace + body: ${{ env.BENCHES_RESULT }} diff --git a/crates/starknet_committer_and_os_cli/benches/bench_split_and_prepare_post.sh b/crates/starknet_committer_and_os_cli/benches/bench_split_and_prepare_post.sh index 6ff8845ada8..c766b72f668 100644 --- a/crates/starknet_committer_and_os_cli/benches/bench_split_and_prepare_post.sh +++ b/crates/starknet_committer_and_os_cli/benches/bench_split_and_prepare_post.sh @@ -13,7 +13,7 @@ cat ${benchmarks_list} | done # Prepare the results for posting comment. -echo "Benchmark movements:" > ${benchmark_results} +echo "Benchmark movements: " > ${benchmark_results} cat ${benchmarks_list} | while read line; do if grep -q "regressed" ${line}.txt; then @@ -24,3 +24,6 @@ cat ${benchmarks_list} | cat ${line}.txt >> ${benchmark_results}; fi; done +if ! (grep -q "regressed" ${benchmark_results} || grep -q "improved" ${benchmark_results}); then + echo "No major performance changes detected." >> ${benchmark_results}; +fi