diff --git a/.github/workflows/pr_benchmarks.yml b/.github/workflows/pr_benchmarks.yml index c3b0b914d2f97..178743fc3d26f 100644 --- a/.github/workflows/pr_benchmarks.yml +++ b/.github/workflows/pr_benchmarks.yml @@ -48,7 +48,7 @@ jobs: ref: ${{ github.event.pull_request.base.sha }} clean: false - - name: Benchmark baseline and compare + - name: Benchmark baseline and generate comparison message env: RESULTS_NAME: ${{ env.BASE_REF_SHA }} run: | @@ -60,4 +60,55 @@ jobs: mv -f results/HEAD results/${{ env.BASE_REF_SHA }} pip3 install rich - ./bench.sh compare ${{ env.BASE_REF_SHA }} ${{ env.HEAD_REF_SHA }} + cat > message.md < + Benchmarks comparing ${{ github.event.pull_request.base.sha }} and ${{ github.sha }} + + \`\`\` + $(./bench.sh compare ${{ env.BASE_REF_SHA }} ${{ env.HEAD_REF_SHA }}) + \`\`\` + + + EOF + + cat message.md + + - name: Upload benchmark comparison message + uses: actions/upload-artifact@v4 + with: + name: message + path: benchmarks/message.md + + comment: + name: Post benchmarks in PR comment + runs-on: ubuntu-latest + needs: [benchmark] + permissions: + pull-requests: write + steps: + - name: Download comment message + uses: actions/download-artifact@v4 + with: + name: message + path: benchmarks + + - name: Print benchmarks + run: | + cat benchmarks/message.md + + - name: Post a comment + uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + script: | + const fs = require('fs'); + const content = fs.readFileSync('benchmarks/message.md', 'utf8'); + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: content, + })