@@ -2,13 +2,70 @@ 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 : true
26+ type : string
27+ opcache :
28+ description : ' Whether opcache should be enabled for the benchmarked code'
29+ required : true
30+ default : " 1"
31+ type : choice
32+ options :
33+ - " 0"
34+ - " 1"
35+ - " 2"
36+ baseline_opcache :
37+ description : ' Whether opcache should be enabled for the baseline'
38+ required : true
39+ default : " 1"
40+ type : choice
41+ options :
42+ - " 0"
43+ - " 1"
44+ - " 2"
45+ jit :
46+ description : ' Whether JIT is benchmarked'
47+ required : false
48+ type : choice
49+ options :
50+ - " 0"
51+ - " 1"
552permissions :
653 contents : read
754jobs :
855 REAL_TIME_BENCHMARK :
956 name : REAL_TIME_BENCHMARK
10- if : github.repository == 'php /php-src'
57+ if : github.repository == 'kocsismate /php-src' || github.event_name == 'workflow_dispatch '
1158 runs-on : ubuntu-22.04
59+ env :
60+ REPOSITORY : ${{ inputs.repository || 'php/php-src' }}
61+ BRANCH : ${{ inputs.branch || 'master' }}
62+ COMMIT : ${{ inputs.commit || github.sha }}
63+ BASELINE_COMMIT : ${{ inputs.baseline_commit || 'd5f6e56610c729710073350af318c4ea1b292cfe' }}
64+ ID : ${{ inputs.id || 'master' }}
65+ OPCACHE : ${{ inputs.opcache || '1' }}
66+ BASELINE_OPCACHE : ${{ inputs.baseline_opcache || '2' }}
67+ JIT : ${{ inputs.jit || '1' }}
68+ YEAR : " "
1269 steps :
1370 - name : Install dependencies
1471 run : |
@@ -29,81 +86,155 @@ jobs:
2986 ref : ' main'
3087 fetch-depth : 1
3188 path : ' php-version-benchmarks'
32- - name : Checkout php-src
89+ - name : Checkout php-src (benchmarked version)
3390 uses : actions/checkout@v4
3491 with :
35- repository : ' php/php-src '
36- ref : ' ${{ github.sha }}'
92+ repository : ' ${{ env.REPOSITORY }} '
93+ ref : ' ${{ env.COMMIT }}'
3794 fetch-depth : 100
38- path : ' php-version-benchmarks/tmp/php_master'
39- - name : Setup benchmark results
95+ path : ' php-version-benchmarks/tmp/php_${{ env.ID }}'
96+ - name : Checkout php-src (baseline version)
97+ uses : actions/checkout@v4
98+ with :
99+ repository : ' ${{ env.REPOSITORY }}'
100+ ref : ' ${{ env.BASELINE_COMMIT }}'
101+ fetch-depth : 100
102+ path : ' php-version-benchmarks/tmp/php_baseline'
103+ - name : Setup benchmark and results
40104 run : |
41105 git config --global user.name "Benchmark"
42106 git config --global user.email "[email protected] " 43107
108+ YEAR="$(date '+%Y')"
109+ echo "YEAR=$YEAR" >> $GITHUB_ENV
110+
44111 rm -rf ./php-version-benchmarks/docs/results
45112 - name : Checkout benchmark data
113+ if : github.repository == 'kocsismate/php-src' && github.event_name != 'workflow_dispatch'
46114 uses : actions/checkout@v4
47115 with :
48116 repository : php/real-time-benchmark-data
49117 ssh-key : ${{ secrets.PHP_VERSION_BENCHMARK_RESULTS_DEPLOY_KEY }}
50118 path : ' php-version-benchmarks/docs/results'
51- - name : Set benchmark config
119+ - name : Setup infra config
52120 run : |
53121 set -e
54122
55- # Set infrastructure config
56123 cp ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini.dist ./php-version-benchmarks/config/infra/aws/x86_64-metal.ini
57124 ESCAPED_DOCKER_REGISTRY=$(printf '%s\n' "${{ secrets.PHP_VERSION_BENCHMARK_DOCKER_REGISTRY }}" | sed -e 's/[\/&]/\\&/g')
58125 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
59126 cp ./php-version-benchmarks/build/infrastructure/config/aws.tfvars.dist ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
60127 sed -i 's/access_key = ""/access_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_ACCESS_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
61128 sed -i 's/secret_key = ""/secret_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_SECRET_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
129+ sed -i 's/github_token = ""/github_token = "${{ secrets.PHP_VERSION_BENCHMARK_GITHUB_TOKEN }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
130+ - name : Setup PHP config - baseline PHP version
131+ if : github.repository == 'kocsismate/php-src' && github.event_name != 'workflow_dispatch'
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,24 @@ 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+ NEWEST_RESULT_DIRECTORY=$(ls -td ./php-version-benchmarks/docs/results/${{ env.YEAR }}/*/ | head -1)
269+ gh pr comment $PR_NUMBER --body-file "$NEWEST_RESULT_DIRECTORY/result.md"
270+ fi
122271 - name : Cleanup
123272 if : always()
124273 run : |
0 commit comments