Skip to content

Commit c347367

Browse files
committed
Split benchmark workflow for fork PR compatibility
1 parent 36c6d01 commit c347367

2 files changed

Lines changed: 81 additions & 36 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Benchmark Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: [Benchmark]
6+
types: [completed]
7+
8+
jobs:
9+
comment:
10+
name: Post Benchmark Results
11+
runs-on: ubuntu-latest
12+
permissions:
13+
actions: read
14+
issues: write
15+
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
16+
17+
steps:
18+
- name: Download benchmark artifact
19+
uses: actions/download-artifact@v7
20+
with:
21+
name: benchmark-result
22+
path: benchmark-artifact/
23+
run-id: ${{ github.event.workflow_run.id }}
24+
github-token: ${{ github.token }}
25+
26+
- name: Read artifact data
27+
id: bench
28+
run: |
29+
echo "pr-number=$(cat benchmark-artifact/pr-number.txt)" >> "$GITHUB_OUTPUT"
30+
echo "head-ref=$(cat benchmark-artifact/head-ref.txt)" >> "$GITHUB_OUTPUT"
31+
echo "base-ref=$(cat benchmark-artifact/base-ref.txt)" >> "$GITHUB_OUTPUT"
32+
echo "base-sha=$(cat benchmark-artifact/base-sha.txt)" >> "$GITHUB_OUTPUT"
33+
echo "head-sha=$(cat benchmark-artifact/head-sha.txt)" >> "$GITHUB_OUTPUT"
34+
{
35+
echo "result<<BENCH_EOF"
36+
cat benchmark-artifact/benchmark-result.txt
37+
echo "BENCH_EOF"
38+
} >> "$GITHUB_OUTPUT"
39+
40+
- name: Find existing comment
41+
uses: peter-evans/find-comment@v4
42+
id: find-comment
43+
with:
44+
issue-number: ${{ steps.bench.outputs.pr-number }}
45+
comment-author: github-actions[bot]
46+
body-includes: "## Benchmark Results"
47+
48+
- name: Post benchmark results
49+
uses: peter-evans/create-or-update-comment@v5
50+
with:
51+
issue-number: ${{ steps.bench.outputs.pr-number }}
52+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
53+
edit-mode: replace
54+
body: |
55+
## Benchmark Results
56+
57+
Comparison of `${{ steps.bench.outputs.head-ref }}` against `${{ steps.bench.outputs.base-ref }}` (`${{ steps.bench.outputs.base-sha }}`).
58+
59+
```
60+
${{ steps.bench.outputs.result }}
61+
```
62+
63+
<sub>Generated by phpbench against commit ${{ steps.bench.outputs.head-sha }}</sub>

.github/workflows/benchmark.yml

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: Benchmark
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
branches: [main]
66

7-
permissions:
8-
pull-requests: write
9-
issues: write
7+
concurrency:
8+
group: benchmark-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
1010

1111
jobs:
1212
benchmark:
@@ -39,38 +39,20 @@ jobs:
3939
run: |
4040
git checkout ${{ github.event.pull_request.head.sha }}
4141
composer install --no-interaction --prefer-dist --quiet
42-
vendor/bin/phpbench run --tag=pr --store --ref=base --report=aggregate --progress=dots > benchmark-result.txt 2>&1 || true
42+
vendor/bin/phpbench run --tag=pr --store --ref=base --report=aggregate --progress=dots | tee benchmark-result.txt || true
4343
44-
- name: Read benchmark result
45-
id: bench
44+
- name: Prepare artifact
4645
run: |
47-
{
48-
echo "result<<BENCH_EOF"
49-
cat benchmark-result.txt
50-
echo "BENCH_EOF"
51-
} >> "$GITHUB_OUTPUT"
52-
53-
- name: Find existing comment
54-
uses: peter-evans/find-comment@v4
55-
id: find-comment
56-
with:
57-
issue-number: ${{ github.event.pull_request.number }}
58-
comment-author: github-actions[bot]
59-
body-includes: "## Benchmark Results"
60-
61-
- name: Post benchmark results
62-
uses: peter-evans/create-or-update-comment@v5
46+
mkdir -p benchmark-artifact
47+
cp benchmark-result.txt benchmark-artifact/
48+
echo "${{ github.event.pull_request.number }}" > benchmark-artifact/pr-number.txt
49+
echo "${{ github.head_ref }}" > benchmark-artifact/head-ref.txt
50+
echo "${{ github.base_ref }}" > benchmark-artifact/base-ref.txt
51+
echo "${{ github.event.pull_request.base.sha }}" > benchmark-artifact/base-sha.txt
52+
echo "${{ github.event.pull_request.head.sha }}" > benchmark-artifact/head-sha.txt
53+
54+
- name: Upload benchmark artifact
55+
uses: actions/upload-artifact@v6
6356
with:
64-
issue-number: ${{ github.event.pull_request.number }}
65-
comment-id: ${{ steps.find-comment.outputs.comment-id }}
66-
edit-mode: replace
67-
body: |
68-
## Benchmark Results
69-
70-
Comparison of `${{ github.head_ref }}` against `${{ github.base_ref }}` (`${{ github.event.pull_request.base.sha }}`).
71-
72-
```
73-
${{ steps.bench.outputs.result }}
74-
```
75-
76-
<sub>Generated by phpbench against commit ${{ github.event.pull_request.head.sha }}</sub>
57+
name: benchmark-result
58+
path: benchmark-artifact/

0 commit comments

Comments
 (0)