From 6a0023c9ad614d7a3b5230825d1c9a6a7e104996 Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Sun, 8 Dec 2024 20:45:11 -0500 Subject: [PATCH] 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 769bd71a6469f3c929d0003395ae10aec685de4c. * 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 5f016c15b775fed94514dd7152c61d814addeb4e. * Revert "Use multi-line output to set var" This reverts commit 22fb0cad996a07ddac98d680f9f657ab20622d3b. * Revert "Try quoting phpcs output" This reverts commit 29a2be79ba759c34b634f62a8aa2cc4217468bcd. * Revert "Move parsing performance to own step" This reverts commit f45a26ac8c5d6b863ae092cfd2aa14c3cffa68df. * Temporarily decrease MAX_PHPCS_PERF_SECS * Decrease it further * Revert "Decrease it further" This reverts commit 7d2a1702071eeba63cab4a068a459101473b5c79. * Revert "Temporarily decrease MAX_PHPCS_PERF_SECS" This reverts commit ded6e9e8ba1404db22abf6cdc68aef1510709ee2. * 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 ed540b8e96ff7e505fbd104abe1ea3ed6282945e. --- .github/workflows/csqa.yml | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/.github/workflows/csqa.yml b/.github/workflows/csqa.yml index 79bce8f..626b312 100644 --- a/.github/workflows/csqa.yml +++ b/.github/workflows/csqa.yml @@ -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