Skip to content

Commit a233037

Browse files
committed
Add support for manually runnung the real-time benchmark on PRs
1 parent f4ad6ea commit a233037

File tree

1 file changed

+144
-29
lines changed

1 file changed

+144
-29
lines changed

.github/workflows/real-time-benchmark.yml

Lines changed: 144 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,44 @@ name: Real-time Benchmark
22
on:
33
schedule:
44
- cron: "30 0 * * *"
5+
workflow_dispatch:
6+
inputs:
7+
repository:
8+
description: 'Repository name that is going to be benchmarked (e.g. "johndoe/php-src")'
9+
required: true
10+
type: string
11+
branch:
12+
description: 'Branch name that is going to be benchmarked (e.g. "my-branch")'
13+
required: true
14+
type: string
15+
commit:
16+
description: 'Commit SHA that is going to be benchmarked (e.g. "123456789a")'
17+
required: true
18+
type: string
19+
baseline_commit:
20+
description: 'A commit SHA that is compared against the one provided by the "commit" input (e.g. "abcdef123456")'
21+
required: true
22+
type: string
23+
jit:
24+
description: 'Whether JIT is benchmarked'
25+
required: false
26+
type: choice
27+
options:
28+
- "0"
29+
- "1"
530
permissions:
631
contents: read
732
jobs:
833
REAL_TIME_BENCHMARK:
934
name: REAL_TIME_BENCHMARK
10-
if: github.repository == 'php/php-src'
35+
if: github.repository == 'php/php-src' || github.event_name == 'workflow_dispatch'
1136
runs-on: ubuntu-22.04
37+
env:
38+
REPOSITORY: ${{ inputs.repository || 'php/php-src' }}
39+
BRANCH: ${{ inputs.branch || 'master' }}
40+
COMMIT: ${{ inputs.commit || github.sha }}
41+
BASELINE_COMMIT: ${{ inputs.baseline_commit || 'd5f6e56610c729710073350af318c4ea1b292cfe' }}
42+
JIT: ${{ inputs.jit || '1' }}
1243
steps:
1344
- name: Install dependencies
1445
run: |
@@ -29,71 +60,143 @@ jobs:
2960
ref: 'main'
3061
fetch-depth: 1
3162
path: 'php-version-benchmarks'
32-
- name: Checkout php-src
63+
- name: Checkout php-src (benchmarked version)
3364
uses: actions/checkout@v4
3465
with:
35-
repository: 'php/php-src'
36-
ref: '${{ github.sha }}'
66+
repository: '${{ env.REPOSITORY }}'
67+
ref: '${{ env.COMMIT }}'
3768
fetch-depth: 100
38-
path: 'php-version-benchmarks/tmp/php_master'
69+
path: 'php-version-benchmarks/tmp/php_${{ env.BRANCH }}'
70+
- name: Checkout php-src (baseline version)
71+
uses: actions/checkout@v4
72+
with:
73+
repository: '${{ env.REPOSITORY }}'
74+
ref: '${{ env.BASELINE_COMMIT }}'
75+
fetch-depth: 100
76+
path: 'php-version-benchmarks/tmp/php_baseline'
3977
- name: Setup benchmark results
4078
run: |
4179
git config --global user.name "Benchmark"
4280
git config --global user.email "[email protected]"
43-
81+
4482
rm -rf ./php-version-benchmarks/docs/results
4583
- name: Checkout benchmark data
84+
if: github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
4685
uses: actions/checkout@v4
4786
with:
4887
repository: php/real-time-benchmark-data
4988
ssh-key: ${{ secrets.PHP_VERSION_BENCHMARK_RESULTS_DEPLOY_KEY }}
5089
path: 'php-version-benchmarks/docs/results'
51-
- name: Set benchmark config
90+
- name: Setup infra config
5291
run: |
5392
set -e
5493
55-
# Set infrastructure config
5694
cp ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini.dist ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini
5795
ESCAPED_DOCKER_REGISTRY=$(printf '%s\n' "${{ secrets.PHP_VERSION_BENCHMARK_DOCKER_REGISTRY }}" | sed -e 's/[\/&]/\\&/g')
5896
sed -i "s/INFRA_DOCKER_REGISTRY=public.ecr.aws\/abcdefgh/INFRA_DOCKER_REGISTRY=$ESCAPED_DOCKER_REGISTRY/g" ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini
5997
cp ./php-version-benchmarks/build/infrastructure/config/aws.tfvars.dist ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
6098
sed -i 's/access_key = ""/access_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_ACCESS_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
6199
sed -i 's/secret_key = ""/secret_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_SECRET_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
100+
- name: Setup PHP config - baseline PHP version
101+
if: github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
102+
run: |
103+
set -e
104+
105+
BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
106+
107+
cat << EOF > /php-version-benchmarks/config/php/baseline.ini
108+
PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA"
109+
PHP_ID=php_baseline
110+
111+
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
112+
PHP_BRANCH=${{ env.BRANCH }}
113+
PHP_COMMIT=${{ env.BASELINE_COMMIT }}
114+
115+
PHP_OPCACHE=1
116+
PHP_JIT=0
117+
EOF
118+
- name: Setup PHP config - baseline PHP version with JIT (manual only)
119+
if: github.repository == 'php/php-src' && github.event_name == 'workflow_dispatch' && inputs.jit == '1'
120+
run: |
121+
set -e
122+
123+
BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
124+
125+
cat << EOF > /php-version-benchmarks/config/php/baseline.ini
126+
PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA (JIT)"
127+
PHP_ID=php_baseline_jit
128+
129+
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
130+
PHP_BRANCH=${{ env.BRANCH }}
131+
PHP_COMMIT=${{ env.BASELINE_COMMIT }}
132+
133+
PHP_OPCACHE=1
134+
PHP_JIT=${{ env.JIT }}
135+
EOF
136+
137+
git clone ./php-version-benchmarks/tmp/php_baseline/ ./php-version-benchmarks/tmp/php_baseline_jit
138+
- name: Setup PHP config - previous PHP version (scheduled only)
139+
if: github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
140+
run: |
141+
set -e
62142
63143
YEAR="$(date '+%Y')"
64144
DATABASE="./php-version-benchmarks/docs/results/$YEAR/database.tsv"
65145
if [ -f "$DATABASE" ]; then
66146
LAST_RESULT_SHA="$(tail -n 2 "$DATABASE" | head -n 1 | cut -f 6)"
67147
else
68148
YESTERDAY="$(date -d "-2 day 23:59:59" '+%Y-%m-%d %H:%M:%S')"
69-
LAST_RESULT_SHA="$(cd ./php-version-benchmarks/tmp/php_master/ && git --no-pager log --until="$YESTERDAY" -n 1 --pretty='%H')"
149+
LAST_RESULT_SHA="$(cd ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}/ && git --no-pager log --until="$YESTERDAY" -n 1 --pretty='%H')"
70150
fi
71151
72-
BASELINE_SHA="d5f6e56610c729710073350af318c4ea1b292cfe"
73-
BASELINE_SHORT_SHA="$(echo "$BASELINE_SHA" | cut -c1-4)"
152+
cat << EOF > /php-version-benchmarks/config/php/previous.ini
153+
PHP_NAME="PHP - previous ${{ env.BRANCH }}"
154+
PHP_ID=php_${{ env.BRANCH }}_previous
155+
156+
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
157+
PHP_BRANCH=${{ env.BRANCH }}
158+
PHP_COMMIT=$LAST_RESULT_SHA
159+
160+
PHP_OPCACHE=1
161+
PHP_JIT=0
162+
EOF
163+
- name: Setup PHP config - benchmarked PHP version
164+
run: |
165+
set -e
166+
167+
cat << EOF > /php-version-benchmarks/config/php/this.ini
168+
PHP_NAME="PHP - ${{ env.BRANCH }}"
169+
PHP_ID=php_${{ env.BRANCH }}
74170
75-
# Set config for the baseline PHP version
76-
cp ./php-version-benchmarks/config/php/master.ini.dist ./php-version-benchmarks/config/php/master_baseline.ini
77-
sed -i 's/PHP_NAME="PHP - master"/PHP_NAME="PHP - baseline@'"$BASELINE_SHORT_SHA"'"/g' ./php-version-benchmarks/config/php/master_baseline.ini
78-
sed -i "s/PHP_ID=php_master/PHP_ID=php_master_baseline/g" ./php-version-benchmarks/config/php/master_baseline.ini
79-
sed -i "s/PHP_COMMIT=/PHP_COMMIT=$BASELINE_SHA/g" ./php-version-benchmarks/config/php/master_baseline.ini
171+
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
172+
PHP_BRANCH=${{ env.BRANCH }}
173+
PHP_COMMIT=${{ env.COMMIT }}
80174
81-
# Set config for the previous PHP version
82-
cp ./php-version-benchmarks/config/php/master.ini.dist ./php-version-benchmarks/config/php/master_last.ini
83-
sed -i 's/PHP_NAME="PHP - master"/PHP_NAME="PHP - previous master"/g' ./php-version-benchmarks/config/php/master_last.ini
84-
sed -i "s/PHP_ID=php_master/PHP_ID=php_master_previous/g" ./php-version-benchmarks/config/php/master_last.ini
85-
sed -i "s/PHP_COMMIT=/PHP_COMMIT=$LAST_RESULT_SHA/g" ./php-version-benchmarks/config/php/master_last.ini
175+
PHP_OPCACHE=1
176+
PHP_JIT=0
177+
EOF
178+
- name: Setup PHP config - benchmarked PHP version with JIT
179+
if: env.JIT == '1'
180+
run: |
181+
set -e
182+
183+
cat << EOF > /php-version-benchmarks/config/php/this_jit.ini
184+
PHP_NAME="PHP - ${{ env.BRANCH }} (JIT)"
185+
PHP_ID=php_${{ env.BRANCH }}_jit
186+
187+
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
188+
PHP_BRANCH=${{ env.BRANCH }}
189+
PHP_COMMIT=${{ env.COMMIT }}
86190
87-
# Set config for the current PHP version
88-
cp ./php-version-benchmarks/config/php/master.ini.dist ./php-version-benchmarks/config/php/master_now.ini
89-
sed -i "s/PHP_COMMIT=/PHP_COMMIT=${{ github.sha }}/g" ./php-version-benchmarks/config/php/master_now.ini
191+
PHP_OPCACHE=1
192+
PHP_JIT=${{ env.JIT }}
193+
EOF
90194
91-
# Set config for current PHP version with JIT
92-
git clone ./php-version-benchmarks/tmp/php_master/ ./php-version-benchmarks/tmp/php_master_jit
93-
cp ./php-version-benchmarks/config/php/master_jit.ini.dist ./php-version-benchmarks/config/php/master_now_jit.ini
94-
sed -i "s/PHP_COMMIT=/PHP_COMMIT=${{ github.sha }}/g" ./php-version-benchmarks/config/php/master_now_jit.ini
195+
git clone ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}/ ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}_jit
196+
- name: Setup test config
197+
run: |
198+
set -e
95199
96-
# Set test configs
97200
cp ./php-version-benchmarks/config/test/1_laravel.ini.dist ./php-version-benchmarks/config/test/1_laravel.ini
98201
cp ./php-version-benchmarks/config/test/2_symfony_main.ini.dist ./php-version-benchmarks/config/test/2_symfony_main.ini
99202
cp ./php-version-benchmarks/config/test/4_wordpress.ini.dist ./php-version-benchmarks/config/test/4_wordpress.ini
@@ -102,6 +205,7 @@ jobs:
102205
- name: Run benchmark
103206
run: ./php-version-benchmarks/benchmark.sh run aws
104207
- name: Store results
208+
if: github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
105209
run: |
106210
set -ex
107211
@@ -117,6 +221,17 @@ jobs:
117221
fi
118222
git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}"
119223
git push
224+
- name: Comment results
225+
if: github.repository != 'php/php-src' && github.event_name == 'workflow_dispatch'
226+
env:
227+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228+
run: |
229+
PR_NUMBER=$(gh pr list --head "${{ inputs.branch }}" --state open --json number --jq '.[0].number')
230+
if [ ! -z "$PR_NUMBER" ]; then
231+
YEAR="$(date '+%Y')"
232+
NEWEST_RESULT_DIRECTORY=$(ls -td ./php-version-benchmarks/docs/results/$YEAR/*/ | head -1)
233+
gh pr comment $PR_NUMBER --body-file "$NEWEST_RESULT_DIRECTORY/result.md"
234+
fi
120235
- name: Cleanup
121236
if: always()
122237
run: |

0 commit comments

Comments
 (0)