Skip to content

Commit fbfa071

Browse files
committed
[CI] Fix benchmarking HEAD sha consistently
1 parent e045b88 commit fbfa071

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

.github/workflows/test-suite.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,11 @@ jobs:
10511051
repository: php/benchmarking-data
10521052
ssh-key: ${{ secrets.BENCHMARKING_DATA_DEPLOY_KEY }}
10531053
path: benchmark/repos/data
1054+
- name: HEAD commit
1055+
id: head_commit
1056+
run: echo "sha=${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}" >> $GITHUB_OUTPUT
10541057
- name: Benchmark
1055-
run: php benchmark/benchmark.php true
1058+
run: php benchmark/benchmark.php ${{ steps.head_commit.outputs.sha }} true
10561059
- name: Store result
10571060
if: github.event_name == 'push'
10581061
run: |
@@ -1067,15 +1070,15 @@ jobs:
10671070
if git diff --cached --quiet; then
10681071
exit 0
10691072
fi
1070-
git commit -m "Add result for ${{ github.repository }}@${{ github.sha }}"
1073+
git commit -m "Add result for ${{ github.repository }}@${{ steps.head_commit.outputs.sha }}"
10711074
git push
10721075
- name: Show diff
10731076
if: github.event_name == 'pull_request'
10741077
run: |-
10751078
set -x
10761079
php benchmark/generate_diff.php \
1077-
${{ github.event.pull_request.head.sha }} \
1078-
$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) \
1080+
${{ steps.head_commit.outputs.sha }} \
1081+
$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ steps.head_commit.outputs.sha }}) \
10791082
> $GITHUB_STEP_SUMMARY
10801083
- uses: actions/upload-artifact@v6
10811084
with:

benchmark/benchmark.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
}
99
}
1010

11-
$storeResult = ($argv[1] ?? 'false') === 'true';
12-
$phpCgi = $argv[2] ?? dirname(PHP_BINARY) . '/php-cgi';
11+
$commitHash = $argv[1] ?? '';
12+
if ($commitHash === '') {
13+
fwrite(STDERR, "Commit hash required\n");
14+
exit(1);
15+
}
16+
$storeResult = ($argv[2] ?? 'false') === 'true';
17+
$phpCgi = $argv[3] ?? dirname(PHP_BINARY) . '/php-cgi';
1318
if (!file_exists($phpCgi)) {
1419
fwrite(STDERR, "php-cgi not found\n");
1520
exit(1);
@@ -43,10 +48,11 @@ function main() {
4348
}
4449

4550
function storeResult(string $result) {
51+
global $commitHash;
52+
4653
$repo = __DIR__ . '/repos/data';
4754
cloneRepo($repo, 'git@github.com:php/benchmarking-data.git');
4855

49-
$commitHash = getPhpSrcCommitHash();
5056
$dir = $repo . '/' . substr($commitHash, 0, 2) . '/' . $commitHash;
5157
$summaryFile = $dir . '/summary.json';
5258
if (!is_dir($dir)) {
@@ -55,11 +61,6 @@ function storeResult(string $result) {
5561
file_put_contents($summaryFile, $result);
5662
}
5763

58-
function getPhpSrcCommitHash(): string {
59-
$result = runCommand(['git', 'log', '--pretty=format:%H', '-n', '1'], dirname(__DIR__));
60-
return $result->stdout;
61-
}
62-
6364
function runBench(bool $jit): array {
6465
return runValgrindPhpCgiCommand('bench', [dirname(__DIR__) . '/Zend/bench.php'], jit: $jit);
6566
}

0 commit comments

Comments
 (0)