Skip to content

Commit

Permalink
Add perf-guard github workflow (#345)
Browse files Browse the repository at this point in the history
* Add perf-guard github workflow

* Fix typo

* Switch to GITHUB_OUTPUT

* Fix typo

* Log performance

* Temporarily reduce baseline for testing

* Revert "Temporarily reduce baseline for testing"

This reverts commit 769bd71.

* Compare SNIFF PROCESSING TIME

* Add comment for fromJSON usage

* Remove unnecessary fromJSON

* Refactor to print output of phpcs alone

* Replace WP copy of PHPMailer with tagged official version

* Remove set x

* Move parsing performance to own step

* Try quoting phpcs output

* Use multi-line output to set var

* Try to parse with heredoc

* Revert "Try to parse with heredoc"

This reverts commit 5f016c1.

* Revert "Use multi-line output to set var"

This reverts commit 22fb0ca.

* Revert "Try quoting phpcs output"

This reverts commit 29a2be7.

* Revert "Move parsing performance to own step"

This reverts commit f45a26a.

* Temporarily decrease MAX_PHPCS_PERF_SECS

* Decrease it further

* Revert "Decrease it further"

This reverts commit 7d2a170.

* Revert "Temporarily decrease MAX_PHPCS_PERF_SECS"

This reverts commit ded6e9e.

* Set MAX_PHPCS_PERF_SECS to 0.4 since 0.2 seems average

* Try using a file to pass perf report

* Fix escaping of env vars

* Also output performance report

* Temporarily break phpcs output to see what happens

* Revert "Temporarily break phpcs output to see what happens"

This reverts commit ed540b8.
  • Loading branch information
sirbrillig authored Dec 9, 2024
1 parent 8332ae9 commit 6a0023c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/csqa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,53 @@ jobs:

- name: Run Static Analysis
run: composer static-analysis

perf-guard:
name: "Basic Performance Guard"
runs-on: ubuntu-latest

env:
MAX_PHPCS_PERF_SECS: 0.4
PHPCS_OUTPUT_FILE: "phpcs-report-file"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
coverage: none

# Install dependencies and handle caching in one go.
# Dependencies need to be installed to make sure the PHPUnit classes are recognized.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v3"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Download performance test fixture
run: wget https://raw.githubusercontent.com/PHPMailer/PHPMailer/refs/tags/v6.9.3/src/PHPMailer.php

- name: Run performance report
id: performance_report
run: |
PHPCS_OUTPUT=$(./vendor/bin/phpcs --standard=VariableAnalysis --report=Performance ./PHPMailer.php)
echo "${PHPCS_OUTPUT}"
echo "${PHPCS_OUTPUT}" > ${{ env.PHPCS_OUTPUT_FILE }}
- name: Parse performance report
id: parse_performance_report
run: |
TOTAL_SECS=$(cat ${{ env.PHPCS_OUTPUT_FILE }} | grep -Eo 'TOTAL SNIFF PROCESSING TIME[ ]+[0-9.]+'|awk '{ print $5 }')
echo "Performance time was ${TOTAL_SECS} (max ${{ env.MAX_PHPCS_PERF_SECS }})"
echo "PHPCS_PERF_SECS=${TOTAL_SECS}" >> $GITHUB_OUTPUT
# fromJSON is used to convert strings to numbers in github actions.
# @link https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#operators
- name: Compare performance to baseline
if: ${{ fromJSON( steps.parse_performance_report.outputs.PHPCS_PERF_SECS ) > fromJSON( env.MAX_PHPCS_PERF_SECS ) }}
run: exit 1

0 comments on commit 6a0023c

Please sign in to comment.