Skip to content

Commit 6e2de73

Browse files
committed
Fixes and improvements
1 parent 64751de commit 6e2de73

File tree

1 file changed

+86
-48
lines changed

1 file changed

+86
-48
lines changed

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

Lines changed: 86 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@ on:
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")'
10+
type: number
11+
opcache:
12+
description: 'Whether opcache should be enabled for the benchmarked commit'
1313
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")'
14+
default: "1"
15+
type: choice
16+
options:
17+
- "0"
18+
- "1"
19+
- "2"
20+
baseline_opcache:
21+
description: 'Whether opcache should be enabled for the baseline commit'
2122
required: true
22-
type: string
23+
default: "1"
24+
type: choice
25+
options:
26+
- "0"
27+
- "1"
28+
- "2"
2329
jit:
2430
description: 'Whether JIT is benchmarked'
2531
required: false
@@ -35,12 +41,41 @@ jobs:
3541
if: github.repository == 'php/php-src' || github.event_name == 'workflow_dispatch'
3642
runs-on: ubuntu-22.04
3743
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' }}
44+
REPOSITORY: ${{ github.repository }}
45+
BRANCH: "master"
46+
COMMIT: ${{ github.sha }}
47+
BASELINE_COMMIT: "d5f6e56610c729710073350af318c4ea1b292cfe"
48+
ID: "master"
49+
OPCACHE: ${{ inputs.opcache || '1' }}
50+
BASELINE_OPCACHE: ${{ inputs.baseline_opcache || '2' }}
4251
JIT: ${{ inputs.jit || '1' }}
52+
YEAR: ""
4353
steps:
54+
- name: Setup benchmark environment
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
run: |
58+
YEAR="$(date '+%Y')"
59+
echo "YEAR=$YEAR" >> $GITHUB_ENV
60+
61+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
62+
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')
63+
64+
REPOSITORY="$(echo "$PR_INFO" | sed -n '1p')/$(echo "$PR_INFO" | sed -n '2p')"
65+
echo "REPOSITORY=$REPOSITORY" >> $GITHUB_ENV
66+
67+
BRANCH=$(echo "$PR_INFO" | sed -n '3p')
68+
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
69+
70+
COMMIT=$(echo "$PR_INFO" | sed -n '4p')
71+
echo "COMMIT=$COMMIT" >> $GITHUB_ENV
72+
73+
BASELINE_COMMIT=$(echo "$PR_INFO" | sed -n '5p')
74+
echo "BASELINE_COMMIT=$BASELINE_COMMIT" >> $GITHUB_ENV
75+
76+
echo "ID=benchmarked" >> $GITHUB_ENV
77+
fi
78+
4479
- name: Install dependencies
4580
run: |
4681
set -ex
@@ -66,7 +101,7 @@ jobs:
66101
repository: '${{ env.REPOSITORY }}'
67102
ref: '${{ env.COMMIT }}'
68103
fetch-depth: 100
69-
path: 'php-version-benchmarks/tmp/php_${{ env.BRANCH }}'
104+
path: 'php-version-benchmarks/tmp/php_${{ env.ID }}'
70105
- name: Checkout php-src (baseline version)
71106
uses: actions/checkout@v4
72107
with:
@@ -81,7 +116,7 @@ jobs:
81116
82117
rm -rf ./php-version-benchmarks/docs/results
83118
- name: Checkout benchmark data
84-
if: github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
119+
if: github.event_name != 'workflow_dispatch'
85120
uses: actions/checkout@v4
86121
with:
87122
repository: php/real-time-benchmark-data
@@ -97,61 +132,60 @@ jobs:
97132
cp ./php-version-benchmarks/build/infrastructure/config/aws.tfvars.dist ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
98133
sed -i 's/access_key = ""/access_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_ACCESS_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
99134
sed -i 's/secret_key = ""/secret_key = "${{ secrets.PHP_VERSION_BENCHMARK_AWS_SECRET_KEY }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
135+
sed -i 's/github_token = ""/github_token = "${{ secrets.PHP_VERSION_BENCHMARK_GITHUB_TOKEN }}"/g' ./php-version-benchmarks/build/infrastructure/config/aws.tfvars
100136
- name: Setup PHP config - baseline PHP version
101-
if: github.repository == 'php/php-src' && github.event_name != 'workflow_dispatch'
102137
run: |
103138
set -e
104139
105140
BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
106141
107-
cat << EOF > /php-version-benchmarks/config/php/baseline.ini
142+
cat << EOF > ./php-version-benchmarks/config/php/baseline.ini
108143
PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA"
109144
PHP_ID=php_baseline
110145
111146
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
112147
PHP_BRANCH=${{ env.BRANCH }}
113148
PHP_COMMIT=${{ env.BASELINE_COMMIT }}
114149
115-
PHP_OPCACHE=2
150+
PHP_OPCACHE=${{ env.BASELINE_OPCACHE }}
116151
PHP_JIT=0
117152
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'
153+
- name: Setup PHP config - baseline PHP version with JIT
154+
if: github.event_name == 'workflow_dispatch' && inputs.jit == '1'
120155
run: |
121156
set -e
122157
123158
BASELINE_SHORT_SHA="$(echo "${{ env.BASELINE_COMMIT }}" | cut -c1-4)"
124-
125-
cat << EOF > /php-version-benchmarks/config/php/baseline.ini
159+
160+
cat << EOF > ./php-version-benchmarks/config/php/baseline.ini
126161
PHP_NAME="PHP - baseline@$BASELINE_SHORT_SHA (JIT)"
127162
PHP_ID=php_baseline_jit
128163
129164
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
130165
PHP_BRANCH=${{ env.BRANCH }}
131166
PHP_COMMIT=${{ env.BASELINE_COMMIT }}
132167
133-
PHP_OPCACHE=2
168+
PHP_OPCACHE=${{ env.BASELINE_OPCACHE }}
134169
PHP_JIT=${{ env.JIT }}
135170
EOF
136171
137172
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'
173+
- name: Setup PHP config - previous PHP version
174+
if: github.event_name != 'workflow_dispatch'
140175
run: |
141176
set -e
142177
143-
YEAR="$(date '+%Y')"
144-
DATABASE="./php-version-benchmarks/docs/results/$YEAR/database.tsv"
178+
DATABASE="./php-version-benchmarks/docs/results/${{ env.YEAR }}/database.tsv"
145179
if [ -f "$DATABASE" ]; then
146180
LAST_RESULT_SHA="$(tail -n 2 "$DATABASE" | head -n 1 | cut -f 6)"
147181
else
148182
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')"
183+
LAST_RESULT_SHA="$(cd ./php-version-benchmarks/tmp/php_${{ env.ID }}/ && git --no-pager log --until="$YESTERDAY" -n 1 --pretty='%H')"
150184
fi
151185
152-
cat << EOF > /php-version-benchmarks/config/php/previous.ini
186+
cat << EOF > ./php-version-benchmarks/config/php/previous.ini
153187
PHP_NAME="PHP - previous ${{ env.BRANCH }}"
154-
PHP_ID=php_${{ env.BRANCH }}_previous
188+
PHP_ID=php_previous
155189
156190
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
157191
PHP_BRANCH=${{ env.BRANCH }}
@@ -164,35 +198,35 @@ jobs:
164198
run: |
165199
set -e
166200
167-
cat << EOF > /php-version-benchmarks/config/php/this.ini
201+
cat << EOF > ./php-version-benchmarks/config/php/this.ini
168202
PHP_NAME="PHP - ${{ env.BRANCH }}"
169-
PHP_ID=php_${{ env.BRANCH }}
203+
PHP_ID=php_${{ env.ID }}
170204
171205
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
172206
PHP_BRANCH=${{ env.BRANCH }}
173207
PHP_COMMIT=${{ env.COMMIT }}
174208
175-
PHP_OPCACHE=1
209+
PHP_OPCACHE=${{ env.OPCACHE }}
176210
PHP_JIT=0
177211
EOF
178212
- name: Setup PHP config - benchmarked PHP version with JIT
179213
if: env.JIT == '1'
180214
run: |
181215
set -e
182216
183-
cat << EOF > /php-version-benchmarks/config/php/this_jit.ini
217+
cat << EOF > ./php-version-benchmarks/config/php/this_jit.ini
184218
PHP_NAME="PHP - ${{ env.BRANCH }} (JIT)"
185-
PHP_ID=php_${{ env.BRANCH }}_jit
219+
PHP_ID=php_${{ env.ID }}_jit
186220
187221
PHP_REPO=https://github.com/${{ env.REPOSITORY }}.git
188222
PHP_BRANCH=${{ env.BRANCH }}
189223
PHP_COMMIT=${{ env.COMMIT }}
190224
191-
PHP_OPCACHE=1
225+
PHP_OPCACHE=${{ env.OPCACHE }}
192226
PHP_JIT=${{ env.JIT }}
193227
EOF
194228
195-
git clone ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}/ ./php-version-benchmarks/tmp/php_${{ env.BRANCH }}_jit
229+
git clone ./php-version-benchmarks/tmp/php_${{ env.ID }}/ ./php-version-benchmarks/tmp/php_${{ env.ID }}_jit
196230
- name: Setup test config
197231
run: |
198232
set -e
@@ -221,17 +255,21 @@ jobs:
221255
fi
222256
git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}"
223257
git push
258+
- name: Upload artifact
259+
if: github.event_name == 'workflow_dispatch'
260+
uses: actions/upload-artifact@v4
261+
with:
262+
name: results
263+
path: ./php-version-benchmarks/docs/results/${{ env.YEAR }}
264+
retention-days: 30
224265
- name: Comment results
225-
if: github.repository != 'php/php-src' && github.event_name == 'workflow_dispatch'
266+
if: github.event_name == 'workflow_dispatch'
226267
env:
227268
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228269
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
270+
cd ./php-version-benchmarks/tmp/php_${{ env.ID }}
271+
NEWEST_RESULT_DIRECTORY=$(ls -td ${{ github.workspace }}/php-version-benchmarks/docs/results/${{ env.YEAR }}/*/ | head -1)
272+
gh pr comment ${{ inputs.pull_request }} --body-file "${NEWEST_RESULT_DIRECTORY}result.md" --repo ${{ env.REPOSITORY }}
235273
- name: Cleanup
236274
if: always()
237275
run: |

0 commit comments

Comments
 (0)