@@ -2,13 +2,71 @@ name: Real-time Benchmark
22on :
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 : ' Full commit SHA that is going to be benchmarked (e.g. "123456789a...")'
17+ required : true
18+ type : string
19+ baseline_commit :
20+ description : ' Full commit SHA that is compared against the one provided by the "commit" input (e.g. "abcdef123456...")'
21+ required : true
22+ type : string
23+ id :
24+ description : ' ID of the benchmarked code. It should be a valid identifier (e.g. "master", "php_85").'
25+ required : false
26+ default : " benchmarked"
27+ type : string
28+ opcache :
29+ description : ' Whether opcache should be enabled for the benchmarked code'
30+ required : true
31+ default : " 1"
32+ type : choice
33+ options :
34+ - " 0"
35+ - " 1"
36+ - " 2"
37+ baseline_opcache :
38+ description : ' Whether opcache should be enabled for the baseline'
39+ required : true
40+ default : " 1"
41+ type : choice
42+ options :
43+ - " 0"
44+ - " 1"
45+ - " 2"
46+ jit :
47+ description : ' Whether JIT is benchmarked'
48+ required : false
49+ type : choice
50+ options :
51+ - " 0"
52+ - " 1"
553permissions :
654 contents : read
755jobs :
856 REAL_TIME_BENCHMARK :
957 name : REAL_TIME_BENCHMARK
10- if : github.repository == 'php /php-src'
58+ if : github.repository == 'kocsismate /php-src' || github.event_name == 'workflow_dispatch '
1159 runs-on : ubuntu-22.04
60+ env :
61+ REPOSITORY : ${{ inputs.repository || 'php/php-src' }}
62+ BRANCH : ${{ inputs.branch || 'master' }}
63+ COMMIT : ${{ inputs.commit || github.sha }}
64+ BASELINE_COMMIT : ${{ inputs.baseline_commit || 'd5f6e56610c729710073350af318c4ea1b292cfe' }}
65+ ID : ${{ inputs.id || 'master' }}
66+ OPCACHE : ${{ inputs.opcache || '1' }}
67+ BASELINE_OPCACHE : ${{ inputs.baseline_opcache || '2' }}
68+ JIT : ${{ inputs.jit || '1' }}
69+ YEAR : " "
1270 steps :
1371 - name : Install dependencies
1472 run : |
@@ -29,81 +87,154 @@ jobs:
2987 ref : ' main'
3088 fetch-depth : 1
3189 path : ' php-version-benchmarks'
32- - name : Checkout php-src
90+ - name : Checkout php-src (benchmarked version)
3391 uses : actions/checkout@v4
3492 with :
35- repository : ' php/php-src '
36- ref : ' ${{ github.sha }}'
93+ repository : ' ${{ env.REPOSITORY }} '
94+ ref : ' ${{ env.COMMIT }}'
3795 fetch-depth : 100
38- path : ' php-version-benchmarks/tmp/php_master'
39- - name : Setup benchmark results
96+ path : ' php-version-benchmarks/tmp/php_${{ env.ID }}'
97+ - name : Checkout php-src (baseline version)
98+ uses : actions/checkout@v4
99+ with :
100+ repository : ' ${{ env.REPOSITORY }}'
101+ ref : ' ${{ env.BASELINE_COMMIT }}'
102+ fetch-depth : 100
103+ path : ' php-version-benchmarks/tmp/php_baseline'
104+ - name : Setup benchmark and results
40105 run : |
41106 git config --global user.name "Benchmark"
42107 git config --global user.email "[email protected] " 43108
109+ YEAR="$(date '+%Y')"
110+ echo "YEAR=$YEAR" >> $GITHUB_ENV
111+
44112 rm -rf ./php-version-benchmarks/docs/results
45113 - name : Checkout benchmark data
114+ if : github.repository == 'kocsismate/php-src' && github.event_name != 'workflow_dispatch'
46115 uses : actions/checkout@v4
47116 with :
48117 repository : php/real-time-benchmark-data
49118 ssh-key : ${{ secrets.PHP_VERSION_BENCHMARK_RESULTS_DEPLOY_KEY }}
50119 path : ' php-version-benchmarks/docs/results'
51- - name : Set benchmark config
120+ - name : Setup infra config
52121 run : |
53122 set -e
54123
55- # Set infrastructure config
56124 cp ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini.dist ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini
57125 ESCAPED_DOCKER_REGISTRY=$(printf '%s\n' "${{ secrets.PHP_VERSION_BENCHMARK_DOCKER_REGISTRY }}" | sed -e 's/[\/&]/\\&/g')
58126 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
59127 cp ./php-version-benchmarks/build/infrastructure/config/aws.tfvars.dist ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
60128 sed -i 's/access_key = ""/access_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_ACCESS_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
61129 sed -i 's/secret_key = ""/secret_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_SECRET_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
130+ sed -i 's/github_token = ""/github_token = "${{ secrets.PHP_VERSION_BENCHMARK_GITHUB_TOKEN }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
131+ - name : Setup PHP config - baseline PHP version
132+ run : |
133+ set -e
62134
63- YEAR="$(date '+%Y')"
64- DATABASE="./php-version-benchmarks/docs/results/$YEAR/database.tsv"
135+ BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
136+
137+ cat << EOF > ./php-version-benchmarks/config/php/baseline.ini
138+ PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA"
139+ PHP_ID=php_baseline
140+
141+ PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
142+ PHP_BRANCH=${{ env.BRANCH }}
143+ PHP_COMMIT=${{ env.BASELINE_COMMIT }}
144+
145+ PHP_OPCACHE=${{ env.BASELINE_OPCACHE }}
146+ PHP_JIT=0
147+ EOF
148+ - name : Setup PHP config - baseline PHP version with JIT (manual only)
149+ if : github.repository == 'kocsismate/php-src' && github.event_name == 'workflow_dispatch' && inputs.jit == '1'
150+ run : |
151+ set -e
152+
153+ BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
154+
155+ cat << EOF > ./php-version-benchmarks/config/php/baseline.ini
156+ PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA (JIT)"
157+ PHP_ID=php_baseline_jit
158+
159+ PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
160+ PHP_BRANCH=${{ env.BRANCH }}
161+ PHP_COMMIT=${{ env.BASELINE_COMMIT }}
162+
163+ PHP_OPCACHE=${{ env.BASELINE_OPCACHE }}
164+ PHP_JIT=${{ env.JIT }}
165+ EOF
166+
167+ git clone ./php-version-benchmarks/tmp/php_baseline/ ./php-version-benchmarks/tmp/php_baseline_jit
168+ - name : Setup PHP config - previous PHP version (scheduled only)
169+ if : github.repository == 'kocsismate/php-src' && github.event_name != 'workflow_dispatch'
170+ run : |
171+ set -e
172+
173+ DATABASE="./php-version-benchmarks/docs/results/${{ env.YEAR }}/database.tsv"
65174 if [ -f "$DATABASE" ]; then
66175 LAST_RESULT_SHA="$(tail -n 2 "$DATABASE" | head -n 1 | cut -f 6)"
67176 else
68177 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')"
178+ LAST_RESULT_SHA="$(cd ./php-version-benchmarks/tmp/php_${{ env.ID }} / && git --no-pager log --until="$YESTERDAY" -n 1 --pretty='%H')"
70179 fi
71180
72- BASELINE_SHA="d5f6e56610c729710073350af318c4ea1b292cfe"
73- BASELINE_SHORT_SHA="$(echo "$BASELINE_SHA" | cut -c1-4)"
74-
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
80- sed -i "s/PHP_OPCACHE=1/PHP_OPCACHE=2/g" ./php-version-benchmarks/config/php/master_baseline.ini
81-
82- # Set config for the previous PHP version
83- cp ./php-version-benchmarks/config/php/master.ini.dist ./php-version-benchmarks/config/php/master_last.ini
84- sed -i 's/PHP_NAME="PHP - master"/PHP_NAME="PHP - previous master"/g' ./php-version-benchmarks/config/php/master_last.ini
85- sed -i "s/PHP_ID=php_master/PHP_ID=php_master_previous/g" ./php-version-benchmarks/config/php/master_last.ini
86- sed -i "s/PHP_COMMIT=/PHP_COMMIT=$LAST_RESULT_SHA/g" ./php-version-benchmarks/config/php/master_last.ini
87- sed -i "s/PHP_OPCACHE=1/PHP_OPCACHE=2/g" ./php-version-benchmarks/config/php/master_last.ini
88-
89- # Set config for the current PHP version
90- cp ./php-version-benchmarks/config/php/master.ini.dist ./php-version-benchmarks/config/php/master_now.ini
91- sed -i "s/PHP_COMMIT=/PHP_COMMIT=${{ github.sha }}/g" ./php-version-benchmarks/config/php/master_now.ini
92-
93- # Set config for current PHP version with JIT
94- git clone ./php-version-benchmarks/tmp/php_master/ ./php-version-benchmarks/tmp/php_master_jit
95- cp ./php-version-benchmarks/config/php/master_jit.ini.dist ./php-version-benchmarks/config/php/master_now_jit.ini
96- sed -i "s/PHP_COMMIT=/PHP_COMMIT=${{ github.sha }}/g" ./php-version-benchmarks/config/php/master_now_jit.ini
97-
98- # Set test configs
181+ cat << EOF > ./php-version-benchmarks/config/php/previous.ini
182+ PHP_NAME="PHP - previous ${{ env.BRANCH }}"
183+ PHP_ID=php_previous
184+
185+ PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
186+ PHP_BRANCH=${{ env.BRANCH }}
187+ PHP_COMMIT=$LAST_RESULT_SHA
188+
189+ PHP_OPCACHE=1
190+ PHP_JIT=0
191+ EOF
192+ - name : Setup PHP config - benchmarked PHP version
193+ run : |
194+ set -e
195+
196+ cat << EOF > ./php-version-benchmarks/config/php/this.ini
197+ PHP_NAME="PHP - ${{ env.BRANCH }}"
198+ PHP_ID=php_${{ env.ID }}
199+
200+ PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
201+ PHP_BRANCH=${{ env.BRANCH }}
202+ PHP_COMMIT=${{ env.COMMIT }}
203+
204+ PHP_OPCACHE=${{ env.OPCACHE }}
205+ PHP_JIT=0
206+ EOF
207+ - name : Setup PHP config - benchmarked PHP version with JIT
208+ if : env.JIT == '1'
209+ run : |
210+ set -e
211+
212+ cat << EOF > ./php-version-benchmarks/config/php/this_jit.ini
213+ PHP_NAME="PHP - ${{ env.BRANCH }} (JIT)"
214+ PHP_ID=php_${{ env.ID }}_jit
215+
216+ PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
217+ PHP_BRANCH=${{ env.BRANCH }}
218+ PHP_COMMIT=${{ env.COMMIT }}
219+
220+ PHP_OPCACHE=${{ env.OPCACHE }}
221+ PHP_JIT=${{ env.JIT }}
222+ EOF
223+
224+ git clone ./php-version-benchmarks/tmp/php_${{ env.ID }}/ ./php-version-benchmarks/tmp/php_${{ env.ID }}_jit
225+ - name : Setup test config
226+ run : |
227+ set -e
228+
99229 cp ./php-version-benchmarks/config/test/1_laravel.ini.dist ./php-version-benchmarks/config/test/1_laravel.ini
100230 cp ./php-version-benchmarks/config/test/2_symfony_main.ini.dist ./php-version-benchmarks/config/test/2_symfony_main.ini
101231 cp ./php-version-benchmarks/config/test/4_wordpress.ini.dist ./php-version-benchmarks/config/test/4_wordpress.ini
102232 cp ./php-version-benchmarks/config/test/5_bench.php.ini.dist ./php-version-benchmarks/config/test/5_bench.php.ini
103233 cp ./php-version-benchmarks/config/test/6_micro_bench.php.ini.dist ./php-version-benchmarks/config/test/6_micro_bench.php.ini
104234 - name : Run benchmark
105235 run : ./php-version-benchmarks/benchmark.sh run aws
106- - name : Store results
236+ - name : Store results (scheduled only)
237+ if : github.repository == 'kocsismate/php-src' && github.event_name != 'workflow_dispatch'
107238 run : |
108239 set -ex
109240
@@ -119,6 +250,25 @@ jobs:
119250 fi
120251 git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}"
121252 git push
253+ - name : Upload artifact (manual only)
254+ if : github.event_name == 'workflow_dispatch'
255+ uses : actions/upload-artifact@v4
256+ with :
257+ name : results
258+ path : ./php-version-benchmarks/docs/results/${{ env.YEAR }}
259+ retention-days : 30
260+ - name : Comment results
261+ if : github.repository != 'php/php-src' && github.event_name == 'workflow_dispatch'
262+ env :
263+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
264+ run : |
265+ cd ./php-version-benchmarks/tmp/php_${{ env.ID }}
266+ PR_NUMBER=$(gh pr list --head "${{ inputs.branch }}" --state open --json number --jq '.[0].number')
267+ if [ ! -z "$PR_NUMBER" ]; then
268+ ls -la ./php-version-benchmarks/docs/results/
269+ NEWEST_RESULT_DIRECTORY=$(ls -td ./php-version-benchmarks/docs/results/${{ env.YEAR }}/*/ | head -1)
270+ gh pr comment $PR_NUMBER --body-file "${NEWEST_RESULT_DIRECTORY}result.md"
271+ fi
122272 - name : Cleanup
123273 if : always()
124274 run : |
0 commit comments