Skip to content

Commit 6a0023c

Browse files
authored
Add perf-guard github workflow (#345)
* 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.
1 parent 8332ae9 commit 6a0023c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/csqa.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,53 @@ jobs:
105105

106106
- name: Run Static Analysis
107107
run: composer static-analysis
108+
109+
perf-guard:
110+
name: "Basic Performance Guard"
111+
runs-on: ubuntu-latest
112+
113+
env:
114+
MAX_PHPCS_PERF_SECS: 0.4
115+
PHPCS_OUTPUT_FILE: "phpcs-report-file"
116+
117+
steps:
118+
- name: Checkout code
119+
uses: actions/checkout@v4
120+
121+
- name: Install PHP
122+
uses: shivammathur/setup-php@v2
123+
with:
124+
php-version: "8.1"
125+
coverage: none
126+
127+
# Install dependencies and handle caching in one go.
128+
# Dependencies need to be installed to make sure the PHPUnit classes are recognized.
129+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
130+
- name: Install Composer dependencies
131+
uses: "ramsey/composer-install@v3"
132+
with:
133+
# Bust the cache at least once a month - output format: YYYY-MM.
134+
custom-cache-suffix: $(date -u "+%Y-%m")
135+
136+
- name: Download performance test fixture
137+
run: wget https://raw.githubusercontent.com/PHPMailer/PHPMailer/refs/tags/v6.9.3/src/PHPMailer.php
138+
139+
- name: Run performance report
140+
id: performance_report
141+
run: |
142+
PHPCS_OUTPUT=$(./vendor/bin/phpcs --standard=VariableAnalysis --report=Performance ./PHPMailer.php)
143+
echo "${PHPCS_OUTPUT}"
144+
echo "${PHPCS_OUTPUT}" > ${{ env.PHPCS_OUTPUT_FILE }}
145+
146+
- name: Parse performance report
147+
id: parse_performance_report
148+
run: |
149+
TOTAL_SECS=$(cat ${{ env.PHPCS_OUTPUT_FILE }} | grep -Eo 'TOTAL SNIFF PROCESSING TIME[ ]+[0-9.]+'|awk '{ print $5 }')
150+
echo "Performance time was ${TOTAL_SECS} (max ${{ env.MAX_PHPCS_PERF_SECS }})"
151+
echo "PHPCS_PERF_SECS=${TOTAL_SECS}" >> $GITHUB_OUTPUT
152+
153+
# fromJSON is used to convert strings to numbers in github actions.
154+
# @link https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#operators
155+
- name: Compare performance to baseline
156+
if: ${{ fromJSON( steps.parse_performance_report.outputs.PHPCS_PERF_SECS ) > fromJSON( env.MAX_PHPCS_PERF_SECS ) }}
157+
run: exit 1

0 commit comments

Comments
 (0)