Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/benchmark-comment.yml
Original file line number Diff line number Diff line change
@@ -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<<BENCH_EOF"
cat benchmark-artifact/benchmark-result.txt
echo "BENCH_EOF"
} >> "$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 }}
```

<sub>Generated by phpbench against commit ${{ steps.bench.outputs.head-sha }}</sub>
57 changes: 20 additions & 37 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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<<BENCH_EOF"
cat benchmark-result.txt
echo "BENCH_EOF"
} >> "$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 }}
```

<sub>Generated by phpbench against commit ${{ github.event.pull_request.head.sha }}</sub>
name: benchmark-result
path: benchmark-artifact/
retention-days: 1
Loading