@@ -103,17 +103,50 @@ jobs:
103
103
104
104
- run : echo BENCHES_RESULT=$(cat bench_new.txt) >> $GITHUB_ENV
105
105
106
- # Post comment in case of performance regression or improvement.
107
106
- run : npm install fs
108
- - if : contains(env.BENCHES_RESULT, 'regressed') || contains(env.BENCHES_RESULT, 'improved')
109
- uses : actions/github-script@v6
107
+
108
+ # Comment with a link to the workflow (or update existing comment on rerun).
109
+ - name : Find Comment
110
+ if : github.event_name == 'pull_request'
111
+ uses : starkware-libs/find-comment@v3
112
+ id : find-benchmark-comment
113
+ with :
114
+ token : ${{ secrets.GITHUB_TOKEN }}
115
+ issue-number : ${{ github.event.pull_request.number }}
116
+ comment-author : ' github-actions[bot]'
117
+ body-includes : Benchmark movements
118
+
119
+ - name : Create comment
120
+ # If the PR number is found and the comment is not found, create a new comment.
121
+ if : (contains(env.BENCHES_RESULT, 'regressed') || contains(env.BENCHES_RESULT, 'improved')) && github.event_name == 'pull_request' && steps.find-benchmark-comment.outputs.comment-id == ''
122
+ uses : starkware-libs/create-or-update-comment@v4
123
+ with :
124
+ token : ${{ secrets.GITHUB_TOKEN }}
125
+ issue-number : ${{ github.event.pull_request.number }}
126
+ body : $(fs.readFileSync('bench_new.txt', 'utf8')),
127
+
128
+ - name : Update comment
129
+ # If the PR number is found and the comment exists, update it.
130
+ if : (contains(env.BENCHES_RESULT, 'regressed') || contains(env.BENCHES_RESULT, 'improved')) && github.event_name == 'pull_request' && steps.find-benchmark-comment.outputs.comment-id != ''
131
+ uses : starkware-libs/create-or-update-comment@v4
110
132
with :
111
- script : |
112
- const fs = require('fs')
113
- github.rest.issues.createComment({
114
- issue_number: context.issue.number,
115
- owner: context.repo.owner,
116
- repo: context.repo.repo,
117
- body: fs.readFileSync('bench_new.txt', 'utf8'),
118
- path: 'Commits'
119
- })
133
+ token : ${{ secrets.GITHUB_TOKEN }}
134
+ comment-id : ${{ steps.find-benchmark-comment.outputs.comment-id }}
135
+ edit-mode : append
136
+ body : $(fs.readFileSync('bench_new.txt', 'utf8')),
137
+
138
+
139
+ # # Post comment in case of performance regression or improvement.
140
+ # - run: npm install fs
141
+ # - if: contains(env.BENCHES_RESULT, 'regressed') || contains(env.BENCHES_RESULT, 'improved')
142
+ # uses: actions/github-script@v6
143
+ # with:
144
+ # script: |
145
+ # const fs = require('fs')
146
+ # github.rest.issues.createComment({
147
+ # issue_number: context.issue.number,
148
+ # owner: context.repo.owner,
149
+ # repo: context.repo.repo,
150
+ # body: fs.readFileSync('bench_new.txt', 'utf8'),
151
+ # path: 'Commits'
152
+ # })
0 commit comments