From 36fe88d602c2a98870b9bb9cc5d8deb496d42255 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 27 Nov 2023 04:27:53 +0100 Subject: [PATCH] GH Action/cs: use the threshold/branch report ... instead of a full scan. As there are some YoastCS 3.0 issues which still need to be solved by the teams, this changes the CS workflow to use the threshold report instead of expecting a 100% clean code base. --- .github/workflows/cs.yml | 30 ++++++++++++++++++++++++++---- composer.json | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 0e77750..03d7e7b 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -38,6 +38,22 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Determine the base branch for the file diff + id: base_branch + env: + BASE_REF: ${{ github.base_ref }} + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "NAME=$BASE_REF" >> $GITHUB_OUTPUT + echo "REF=origin/$BASE_REF" >> $GITHUB_OUTPUT + else + echo 'NAME=develop' >> $GITHUB_OUTPUT + echo "REF=origin/develop" >> $GITHUB_OUTPUT + fi + + - name: Fetch base branch + run: git fetch --no-tags --depth=1 origin ${{ steps.base_branch.outputs.NAME }} + - name: Install PHP uses: shivammathur/setup-php@v2 with: @@ -58,12 +74,18 @@ jobs: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") - # Check the codestyle of the files. - # The results of the CS check will be shown inline in the PR via the CS2PR tool. + # Check the codestyle of the files against a threshold of expected errors and warnings. + - name: Check PHP code style against the thresholds + run: composer check-cs-thresholds + + # Check the codestyle only of the files which were changed in the current branch. + # This step will only be executed if the threshold check exited with a failure status. + # The results of this CS check will be shown inline in the PR via the CS2PR tool. # @link https://github.com/staabm/annotate-pull-request-from-checkstyle/ - - name: Check PHP code style + - name: Check PHP code style for the changes made in the branch only + if: ${{ failure() }} id: phpcs - run: composer check-cs-warnings -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml + run: composer check-branch-cs -- ${{ steps.base_branch.outputs.REF }} - name: Show PHPCS results in PR if: ${{ always() && steps.phpcs.outcome == 'failure' }} diff --git a/composer.json b/composer.json index 2319118..15bcf25 100644 --- a/composer.json +++ b/composer.json @@ -85,7 +85,7 @@ "Yoast\\WP\\ACF\\Config\\Composer\\Actions::check_coding_standards" ], "check-cs-thresholds": [ - "@putenv YOASTCS_THRESHOLD_ERRORS=0", + "@putenv YOASTCS_THRESHOLD_ERRORS=11", "@putenv YOASTCS_THRESHOLD_WARNINGS=0", "Yoast\\WP\\ACF\\Config\\Composer\\Actions::check_cs_thresholds" ],