diff --git a/.github/workflows/pr_benchmarks.yml b/.github/workflows/pr_benchmarks.yml index c3b0b914d2f97..56254ddbc6875 100644 --- a/.github/workflows/pr_benchmarks.yml +++ b/.github/workflows/pr_benchmarks.yml @@ -1,8 +1,7 @@ -name: Run and Cache Benchmarks +name: Benchmarks on: pull_request: - types: [labeled, opened, reopened, synchronize] jobs: benchmark: @@ -48,7 +47,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: | @@ -59,5 +58,68 @@ jobs: # Temporary workaround, until `RESULTS_NAME` var lands into main mv -f results/HEAD results/${{ env.BASE_REF_SHA }} + echo ${{ github.event.pull_request.number }} > pr + 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 + + - name: Upload PR number + uses: actions/upload-artifact@v4 + with: + name: pr + path: benchmarks/pr + + comment: + # Separate job with default write permissions, which can + # execute another workflow to actually post a PR comment + name: Post benchmarks comment + runs-on: ubuntu-latest + needs: [ benchmark ] + steps: + - name: Download comment message + uses: actions/download-artifact@v4 + with: + name: message + + - name: Download pr number + uses: actions/download-artifact@v4 + with: + name: pr + + - name: Print message and pr number + run: | + cat pr + echo "PR_NUMBER=$(cat pr)" >> "$GITHUB_ENV" + cat 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: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + body: content, + }) diff --git a/.github/workflows/pr_comment.yml b/.github/workflows/pr_comment.yml new file mode 100644 index 0000000000000..440063565288a --- /dev/null +++ b/.github/workflows/pr_comment.yml @@ -0,0 +1,53 @@ +name: PR Comment + +on: + workflow_run: + workflows: ["Benchmarks"] + types: + - completed + +jobs: + comment: + name: PR Comment + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJSON(github) }} + run: echo "$GITHUB_CONTEXT" + + - name: Download comment message + uses: actions/download-artifact@v4 + with: + name: message + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Download pr number + uses: actions/download-artifact@v4 + with: + name: pr + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Print message and pr number + run: | + cat pr + echo "PR_NUMBER=$(cat pr)" >> "$GITHUB_ENV" + cat message.md + + - name: Post the 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: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + body: content, + })