Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1, opcache.enable_cli=1, opcache.jit=tracing, opcache.jit_buffer_size=64M
ini-values: memory_limit=-1

- name: "Checkout base"
uses: actions/checkout@v7
Expand All @@ -38,7 +38,7 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}

- name: "phpbench on base"
run: "vendor/bin/phpbench run tests/Benchmark --progress=none --report=default --tag=base"
run: "vendor/bin/phpbench run tests/Benchmark --progress=none --tag=base"

- name: "Checkout"
uses: actions/checkout@v7
Expand All @@ -50,46 +50,44 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}

- name: "phpbench diff"
id: bench
continue-on-error: true
run: "vendor/bin/phpbench run tests/Benchmark --progress=none --report=diff --ref=base > bench.txt"

- name: "Get Bench Result"
id: phpbench
run: |
echo 'BENCH_RESULT<<EOF' >> $GITHUB_ENV
cat bench.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV

- uses: actions/github-script@v9
with:
script: |
const fs = require('fs');

// the diff report prints one section per benchmark class: a title line, a console table, a blank line.
// The console table becomes a markdown table by dropping the outer borders and turning the border
// below the header into the separator row.
const sections = fs.readFileSync('bench.txt', 'utf8').trim().split(/\n\s*\n/).map((section) => {
const [title, , header, separator, ...rows] = section.trim().split('\n');
const table = [header, separator.replace(/\+/g, '|'), ...rows.filter((row) => !row.startsWith('+'))];

return `### ${title.replace(/Bench$/, '')}\n\n${table.join('\n')}`;
}).join('\n\n');

const failed = ${{ steps.bench.outcome == 'failure' }};
const commentBody = `Hello :wave:

Here are the most recent benchmark results, compared against \`${{ github.base_ref }}\`. Time is the mode over the iterations in the \`its\` column, with the relative standard deviation in brackets.

${sections}

${failed ? ':warning: At least one benchmark got slower than the tolerance in phpbench.json allows.' : ''}
This comment gets updated every time a new commit comes in.`;

// Get the existing comments.
const {data: comments} = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
})

// Find any comment already made by the bot.
const botComment = comments.find(comment => comment.user.id === 41898282)
const commentBody = `

Hello :wave:

<details>
<summary>here is the most recent benchmark result:</summary>

<p>

\`\`\`
${{ env.BENCH_RESULT }}
\`\`\`

</p>
</details>

This comment gets update everytime a new commit comes in!

`;
// Find any comment already made by the bot.
const botComment = comments.find(comment => comment.user.id === 41898282)

if (!context.payload.pull_request.head.repo.full_name.startsWith('patchlevel/')) {
console.log('Not attempting to write comment on PR from fork');
Expand All @@ -110,3 +108,7 @@ jobs:
})
}
}

- name: "Fail on regression"
if: steps.bench.outcome == 'failure'
run: "exit 1"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ infection.log
infection.html
.phpbench/
docs_php/
var
stub
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ static: phpstan cs ## run stat

test: phpunit ## run tests

.PHONY: benchmark
benchmark: vendor ## run benchmarks
vendor/bin/phpbench run tests/Benchmark --report=default
.PHONY: snapshot
snapshot: vendor ## regenerate the snapshot of the generated middleware
UPDATE_SNAPSHOTS=1 vendor/bin/phpunit --no-coverage --filter testGeneratedCodeMatchesSnapshot

.PHONY: benchmark-diff-test
benchmark-diff-test: vendor ## run benchmarks
vendor/bin/phpbench run tests/Benchmark --revs=1 --report=default --progress=none --tag=base
vendor/bin/phpbench run tests/Benchmark --revs=1 --report=diff --progress=none --ref=base
.PHONY: benchmark
benchmark: vendor ## run all benchmarks
vendor/bin/phpbench run --report=diff

.PHONY: benchmark-diff
benchmark-diff: vendor ## run the benchmarks twice and compare the second run against the first, like the CI does
vendor/bin/phpbench run --progress=none --tag=base
vendor/bin/phpbench run --progress=none --report=diff --ref=base

.PHONY: docs
docs: docs-extract-php docs-php-lint docs-phpcs docs-inject-php ## check and format docs code
Expand Down
Loading
Loading