diff --git a/.github/workflows/benchmark-comment.yml b/.github/workflows/benchmark-comment.yml new file mode 100644 index 0000000..d5e90aa --- /dev/null +++ b/.github/workflows/benchmark-comment.yml @@ -0,0 +1,63 @@ +name: Benchmark Comment + +on: + workflow_run: + workflows: [Benchmark] + types: [completed] + +jobs: + comment: + name: Post Benchmark Results + runs-on: ubuntu-latest + permissions: + actions: read + pull-requests: write + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' + + steps: + - name: Download benchmark artifact + uses: actions/download-artifact@v7 + with: + name: benchmark-result + path: benchmark-artifact/ + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Read artifact data + id: bench + run: | + echo "pr-number=$(cat benchmark-artifact/pr-number.txt)" >> "$GITHUB_OUTPUT" + echo "head-ref=$(cat benchmark-artifact/head-ref.txt)" >> "$GITHUB_OUTPUT" + echo "base-ref=$(cat benchmark-artifact/base-ref.txt)" >> "$GITHUB_OUTPUT" + echo "base-sha=$(cat benchmark-artifact/base-sha.txt)" >> "$GITHUB_OUTPUT" + echo "head-sha=$(cat benchmark-artifact/head-sha.txt)" >> "$GITHUB_OUTPUT" + { + echo "result<> "$GITHUB_OUTPUT" + + - name: Find existing comment + uses: peter-evans/find-comment@v4 + id: find-comment + with: + issue-number: ${{ steps.bench.outputs.pr-number }} + comment-author: github-actions[bot] + body-includes: "## Benchmark Results" + + - name: Post benchmark results + uses: peter-evans/create-or-update-comment@v5 + with: + issue-number: ${{ steps.bench.outputs.pr-number }} + comment-id: ${{ steps.find-comment.outputs.comment-id }} + edit-mode: replace + body: | + ## Benchmark Results + + Comparison of `${{ steps.bench.outputs.head-ref }}` against `${{ steps.bench.outputs.base-ref }}` (`${{ steps.bench.outputs.base-sha }}`). + + ``` + ${{ steps.bench.outputs.result }} + ``` + + Generated by phpbench against commit ${{ steps.bench.outputs.head-sha }} diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 426fe06..876a92d 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,12 +1,12 @@ name: Benchmark on: - pull_request_target: + pull_request: branches: [main] -permissions: - pull-requests: write - issues: write +concurrency: + group: benchmark-${{ github.event.pull_request.number }} + cancel-in-progress: true jobs: benchmark: @@ -33,44 +33,27 @@ jobs: run: | git checkout ${{ github.event.pull_request.base.sha }} composer install --no-interaction --prefer-dist --quiet - vendor/bin/phpbench run --tag=base --store --progress=dots + vendor/bin/phpbench run --tag=base --store --progress=none - name: Benchmark PR branch run: | git checkout ${{ github.event.pull_request.head.sha }} composer install --no-interaction --prefer-dist --quiet - vendor/bin/phpbench run --tag=pr --store --ref=base --report=aggregate --progress=dots > benchmark-result.txt 2>&1 || true + vendor/bin/phpbench run --tag=pr --store --ref=base --report=aggregate --progress=none 2>&1 | tee benchmark-result.txt || true - - name: Read benchmark result - id: bench + - name: Prepare artifact run: | - { - echo "result<> "$GITHUB_OUTPUT" - - - name: Find existing comment - uses: peter-evans/find-comment@v4 - id: find-comment - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: github-actions[bot] - body-includes: "## Benchmark Results" - - - name: Post benchmark results - uses: peter-evans/create-or-update-comment@v5 + mkdir -p benchmark-artifact + cp benchmark-result.txt benchmark-artifact/ + echo "${{ github.event.pull_request.number }}" > benchmark-artifact/pr-number.txt + echo "${{ github.head_ref }}" > benchmark-artifact/head-ref.txt + echo "${{ github.base_ref }}" > benchmark-artifact/base-ref.txt + echo "${{ github.event.pull_request.base.sha }}" > benchmark-artifact/base-sha.txt + echo "${{ github.event.pull_request.head.sha }}" > benchmark-artifact/head-sha.txt + + - name: Upload benchmark artifact + uses: actions/upload-artifact@v6 with: - issue-number: ${{ github.event.pull_request.number }} - comment-id: ${{ steps.find-comment.outputs.comment-id }} - edit-mode: replace - body: | - ## Benchmark Results - - Comparison of `${{ github.head_ref }}` against `${{ github.base_ref }}` (`${{ github.event.pull_request.base.sha }}`). - - ``` - ${{ steps.bench.outputs.result }} - ``` - - Generated by phpbench against commit ${{ github.event.pull_request.head.sha }} + name: benchmark-result + path: benchmark-artifact/ + retention-days: 1