44 - cron : " 30 0 * * *"
55 workflow_dispatch :
66 inputs :
7- repository :
8- description : ' Repository name that is going to be benchmarked (e.g. "johndoe/php-src ")'
7+ pull_request :
8+ description : ' PR number that is going to be benchmarked (e.g. "1234 ")'
99 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
10+ type : number
2311 jit :
2412 description : ' Whether JIT is benchmarked'
2513 required : false
2614 type : choice
2715 options :
2816 - " 0"
2917 - " 1"
18+ opcache :
19+ description : ' Whether opcache is enabled for the benchmarked commit'
20+ required : true
21+ default : " 1"
22+ type : choice
23+ options :
24+ - " 0"
25+ - " 1"
26+ - " 2"
27+ baseline_opcache :
28+ description : ' Whether opcache is enabled for the baseline commit'
29+ required : true
30+ default : " 1"
31+ type : choice
32+ options :
33+ - " 0"
34+ - " 1"
35+ - " 2"
3036permissions :
3137 contents : read
38+ pull-requests : write
3239jobs :
3340 REAL_TIME_BENCHMARK :
3441 name : REAL_TIME_BENCHMARK
3542 if : github.repository == 'php/php-src' || github.event_name == 'workflow_dispatch'
3643 runs-on : ubuntu-22.04
3744 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' }}
45+ REPOSITORY : ${{ github.repository }}
46+ BRANCH : " master"
47+ COMMIT : ${{ github.sha }}
48+ BASELINE_COMMIT : " d5f6e56610c729710073350af318c4ea1b292cfe"
49+ ID : " master"
50+ OPCACHE : ${{ inputs.opcache || '1' }}
51+ BASELINE_OPCACHE : ${{ inputs.baseline_opcache || '2' }}
4252 JIT : ${{ inputs.jit || '1' }}
53+ YEAR : " "
4354 steps :
55+ - name : Setup benchmark environment
56+ env :
57+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
58+ run : |
59+ YEAR="$(date '+%Y')"
60+ echo "YEAR=$YEAR" >> $GITHUB_ENV
61+
62+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
63+ PR_INFO=$(gh pr view ${{ inputs.pull_request }} --json headRepositoryOwner,headRepository,headRefName,headRefOid,baseRefOid --repo ${{ github.repository }} | jq -r '.headRepositoryOwner.login, .headRepository.name, .headRefName, .headRefOid, .baseRefOid')
64+
65+ REPOSITORY="$(echo "$PR_INFO" | sed -n '1p')/$(echo "$PR_INFO" | sed -n '2p')"
66+ echo "REPOSITORY=$REPOSITORY" >> $GITHUB_ENV
67+
68+ BRANCH=$(echo "$PR_INFO" | sed -n '3p')
69+ echo "BRANCH=$BRANCH" >> $GITHUB_ENV
70+
71+ COMMIT=$(echo "$PR_INFO" | sed -n '4p')
72+ echo "COMMIT=$COMMIT" >> $GITHUB_ENV
73+
74+ BASELINE_COMMIT=$(echo "$PR_INFO" | sed -n '5p')
75+ echo "BASELINE_COMMIT=$BASELINE_COMMIT" >> $GITHUB_ENV
76+
77+ echo "ID=benchmarked" >> $GITHUB_ENV
78+ fi
79+
4480 - name : Install dependencies
4581 run : |
4682 set -ex
66102 repository : ' ${{ env.REPOSITORY }}'
67103 ref : ' ${{ env.COMMIT }}'
68104 fetch-depth : 100
69- path : ' php-version-benchmarks/tmp/php_${{ env.BRANCH }}'
105+ path : ' php-version-benchmarks/tmp/php_${{ env.ID }}'
70106 - name : Checkout php-src (baseline version)
71107 uses : actions/checkout@v4
72108 with :
81117
82118 rm -rf ./php-version-benchmarks/docs/results
83119 - name : Checkout benchmark data
84- if : github.repository == 'php/php-src' && github. event_name != 'workflow_dispatch'
120+ if : github.event_name != 'workflow_dispatch'
85121 uses : actions/checkout@v4
86122 with :
87123 repository : php/real-time-benchmark-data
@@ -97,61 +133,60 @@ jobs:
97133 cp ./php-version-benchmarks/build/infrastructure/config/aws.tfvars.dist ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
98134 sed -i 's/access_key = ""/access_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_ACCESS_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
99135 sed -i 's/secret_key = ""/secret_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_SECRET_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
136+ sed -i 's/github_token = ""/github_token = "${{ secrets.GITHUB_TOKEN }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
100137 - name : Setup PHP config - baseline PHP version
101- if : github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
102138 run : |
103139 set -e
104140
105141 BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
106142
107- cat << EOF > /php-version-benchmarks/config/php/baseline.ini
143+ cat << EOF > . /php-version-benchmarks/config/php/baseline.ini
108144 PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA"
109145 PHP_ID=php_baseline
110146
111147 PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
112148 PHP_BRANCH=${{ env.BRANCH }}
113149 PHP_COMMIT=${{ env.BASELINE_COMMIT }}
114150
115- PHP_OPCACHE=2
151+ PHP_OPCACHE=${{ env.BASELINE_OPCACHE }}
116152 PHP_JIT=0
117153 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'
154+ - name : Setup PHP config - baseline PHP version with JIT
155+ if : github.event_name == 'workflow_dispatch' && inputs.jit == '1'
120156 run : |
121157 set -e
122158
123159 BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
124-
125- cat << EOF > /php-version-benchmarks/config/php/baseline .ini
160+
161+ cat << EOF > . /php-version-benchmarks/config/php/baseline_jit .ini
126162 PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA (JIT)"
127163 PHP_ID=php_baseline_jit
128164
129165 PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
130166 PHP_BRANCH=${{ env.BRANCH }}
131167 PHP_COMMIT=${{ env.BASELINE_COMMIT }}
132168
133- PHP_OPCACHE=2
169+ PHP_OPCACHE=${{ env.BASELINE_OPCACHE }}
134170 PHP_JIT=${{ env.JIT }}
135171 EOF
136172
137173 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'
174+ - name : Setup PHP config - previous PHP version
175+ if : github.event_name != 'workflow_dispatch'
140176 run : |
141177 set -e
142178
143- YEAR="$(date '+%Y')"
144- DATABASE="./php-version-benchmarks/docs/results/$YEAR/database.tsv"
179+ DATABASE="./php-version-benchmarks/docs/results/${{ env.YEAR }}/database.tsv"
145180 if [ -f "$DATABASE" ]; then
146181 LAST_RESULT_SHA="$(tail -n 2 "$DATABASE" | head -n 1 | cut -f 6)"
147182 else
148183 YESTERDAY="$(date -d "-2 day 23:59:59" '+%Y-%m-%d %H:%M:%S')"
149- LAST_RESULT_SHA="$(cd ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}/ && git --no-pager log --until="$YESTERDAY" -n 1 --pretty='%H')"
184+ LAST_RESULT_SHA="$(cd ./php-version-benchmarks/tmp/php_${{ env.ID }}/ && git --no-pager log --until="$YESTERDAY" -n 1 --pretty='%H')"
150185 fi
151186
152- cat << EOF > /php-version-benchmarks/config/php/previous.ini
187+ cat << EOF > . /php-version-benchmarks/config/php/previous.ini
153188 PHP_NAME="PHP - previous ${{ env.BRANCH }}"
154- PHP_ID=php_${{ env.BRANCH }}_previous
189+ PHP_ID=php_previous
155190
156191 PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
157192 PHP_BRANCH=${{ env.BRANCH }}
@@ -164,35 +199,35 @@ jobs:
164199 run : |
165200 set -e
166201
167- cat << EOF > /php-version-benchmarks/config/php/this.ini
202+ cat << EOF > . /php-version-benchmarks/config/php/this.ini
168203 PHP_NAME="PHP - ${{ env.BRANCH }}"
169- PHP_ID=php_${{ env.BRANCH }}
204+ PHP_ID=php_${{ env.ID }}
170205
171206 PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
172207 PHP_BRANCH=${{ env.BRANCH }}
173208 PHP_COMMIT=${{ env.COMMIT }}
174209
175- PHP_OPCACHE=1
210+ PHP_OPCACHE=${{ env.OPCACHE }}
176211 PHP_JIT=0
177212 EOF
178213 - name : Setup PHP config - benchmarked PHP version with JIT
179214 if : env.JIT == '1'
180215 run : |
181216 set -e
182217
183- cat << EOF > /php-version-benchmarks/config/php/this_jit.ini
218+ cat << EOF > . /php-version-benchmarks/config/php/this_jit.ini
184219 PHP_NAME="PHP - ${{ env.BRANCH }} (JIT)"
185- PHP_ID=php_${{ env.BRANCH }}_jit
220+ PHP_ID=php_${{ env.ID }}_jit
186221
187222 PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
188223 PHP_BRANCH=${{ env.BRANCH }}
189224 PHP_COMMIT=${{ env.COMMIT }}
190225
191- PHP_OPCACHE=1
226+ PHP_OPCACHE=${{ env.OPCACHE }}
192227 PHP_JIT=${{ env.JIT }}
193228 EOF
194229
195- git clone ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}/ ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}_jit
230+ git clone ./php-version-benchmarks/tmp/php_${{ env.ID }}/ ./php-version-benchmarks/tmp/php_${{ env.ID }}_jit
196231 - name : Setup test config
197232 run : |
198233 set -e
@@ -221,17 +256,21 @@ jobs:
221256 fi
222257 git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}"
223258 git push
259+ - name : Upload artifact
260+ if : github.event_name == 'workflow_dispatch'
261+ uses : actions/upload-artifact@v4
262+ with :
263+ name : results
264+ path : ./php-version-benchmarks/docs/results/${{ env.YEAR }}
265+ retention-days : 30
224266 - name : Comment results
225- if : github.repository != 'php/php-src' && github. event_name == 'workflow_dispatch'
267+ if : github.event_name == 'workflow_dispatch'
226268 env :
227269 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
228270 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
271+ cd ./php-version-benchmarks/tmp/php_${{ env.ID }}
272+ NEWEST_RESULT_DIRECTORY=$(ls -td ${{ github.workspace }}/php-version-benchmarks/docs/results/${{ env.YEAR }}/*/ | head -1)
273+ gh pr comment ${{ inputs.pull_request }} --body-file "${NEWEST_RESULT_DIRECTORY}result.md" --repo ${{ env.REPOSITORY }}
235274 - name : Cleanup
236275 if : always()
237276 run : |
0 commit comments