From 841e75c6eae7d21c76fefe22a728c836d3d7faf6 Mon Sep 17 00:00:00 2001 From: Marko Grujic Date: Tue, 5 Mar 2024 23:20:45 +0100 Subject: [PATCH] Add job for commenting benchmark results on the PR --- .github/workflows/pr_benchmarks.yml | 49 +++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_benchmarks.yml b/.github/workflows/pr_benchmarks.yml index c3b0b914d2f9..251126d279b1 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,49 @@ 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 artifacts/message.md + + - name: Upload benchmark comparison message + uses: actions/upload-artifact@v4 + with: + name: message + path: 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: message.md + + - name: Post a comment + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const content = fs.readFileSync('message.md', 'utf8'); + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: content, + })