-
Notifications
You must be signed in to change notification settings - Fork 2
178 lines (152 loc) · 5.61 KB
/
Copy pathphpbench.yml
File metadata and controls
178 lines (152 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: PHPBench PR Benchmark
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
permissions:
contents: read
pull-requests: write
env:
REQUIRED_PHP_EXTENSIONS: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
# TemplateCacheBench's var-export subjects segfault on CI for PHP 8.4/8.5. Exclude them on
# every version, not just those two: a benchmark set that varies per PHP version makes
# the per-version comparison summaries incomparable with each other. Local runs are
# unfiltered, so the benchmarks still exist — they just do not gate PRs.
PHPBENCH_FILTER: '^(?!.*TemplateCacheBench::bench(Build|LoadAndRender)VarExporter$).*'
PHPBENCH_MAX_REG: '5'
jobs:
benchmark:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
name: PHPBench (PHP ${{ matrix.php }})
steps:
- name: Checkout PR branch
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.REQUIRED_PHP_EXTENSIONS }}
coverage: none
- name: Prepare benchmark worktrees
run: |
set -euo pipefail
WORKSPACE="$RUNNER_TEMP/phpbench-workspace"
BASE_DIR="$WORKSPACE/base"
PR_DIR="$WORKSPACE/pr"
rm -rf "$WORKSPACE"
mkdir -p "$WORKSPACE"
git fetch origin "${{ github.event.pull_request.base.sha }}"
git worktree add "$PR_DIR" "${{ github.event.pull_request.head.sha }}"
git worktree add "$BASE_DIR" "${{ github.event.pull_request.base.sha }}"
{
echo "WORKSPACE=$WORKSPACE"
echo "BASE_DIR=$BASE_DIR"
echo "PR_DIR=$PR_DIR"
} >> "$GITHUB_ENV"
- name: Install dependencies (PR)
run: composer install --no-interaction --prefer-dist --no-progress
working-directory: ${{ env.PR_DIR }}
- name: Install dependencies (base)
run: composer install --no-interaction --prefer-dist --no-progress
working-directory: ${{ env.BASE_DIR }}
- name: Run PHPBench (PR)
run: |
set -euo pipefail
vendor/bin/phpbench run \
--group=default \
--filter="$PHPBENCH_FILTER" \
--progress=none \
--warmup=1 \
--retry-threshold=5 \
--report=aggregate \
--output=json > "$WORKSPACE/pr.json"
working-directory: ${{ env.PR_DIR }}
- name: Run PHPBench (base)
run: |
set -euo pipefail
vendor/bin/phpbench run \
--group=default \
--filter="$PHPBENCH_FILTER" \
--progress=none \
--warmup=1 \
--retry-threshold=5 \
--report=aggregate \
--output=json > "$WORKSPACE/base.json"
working-directory: ${{ env.BASE_DIR }}
- name: Compare benchmark results
id: compare
continue-on-error: true
env:
PHPBENCH_PHP_VERSION: ${{ matrix.php }}
PHPBENCH_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PHPBENCH_PR_SHA: ${{ github.event.pull_request.head.sha }}
PHPBENCH_WARMUP: '1'
run: |
set +e
export PHPBENCH_RUNNER="${ImageOS:-$RUNNER_OS}"
php "$GITHUB_WORKSPACE/tools/phpbench-compare.php" "$WORKSPACE/base.json" "$WORKSPACE/pr.json" > "$WORKSPACE/summary.md"
STATUS=$?
set -e
{
echo "comment<<EOF"
if [ -f "$WORKSPACE/summary.md" ]; then
cat "$WORKSPACE/summary.md"
else
echo "Benchmark comparison could not be generated."
fi
echo "EOF"
echo "exit_code=$STATUS"
} >> "$GITHUB_OUTPUT"
exit "$STATUS"
- name: Post benchmark comment
if: always() && github.event.pull_request.head.repo.fork == false
uses: actions/github-script@v9
env:
COMMENT_BODY: ${{ steps.compare.outputs.comment }}
PHP_VERSION: ${{ matrix.php }}
with:
script: |
const marker = `<!-- phpbench-pr-benchmark-php-${process.env.PHP_VERSION} -->`;
const body = `${marker}
## PHPBench comparison (PHP ${process.env.PHP_VERSION})
${process.env.COMMENT_BODY || 'Benchmark comparison was not generated.'}`;
const issue_number = context.payload.pull_request.number;
const { owner, repo } = context.repo;
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
});
const existing = comments.find((comment) =>
comment.user?.type === 'Bot' && comment.body?.includes(marker),
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
- name: Enforce comparison failures
if: always() && steps.compare.outputs.exit_code != '0'
run: exit 1