From 182b804d89d90c9812246bba3a20d2068a6e24e0 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:00:00 -0800 Subject: [PATCH 01/12] Fix namespace of function in test --- tests/phpunit/includes/HiiveConnectionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/HiiveConnectionTest.php b/tests/phpunit/includes/HiiveConnectionTest.php index 4c0265f..d1bfaa5 100644 --- a/tests/phpunit/includes/HiiveConnectionTest.php +++ b/tests/phpunit/includes/HiiveConnectionTest.php @@ -179,7 +179,7 @@ function ( $request_response ) { * * @see https://github.com/10up/wp_mock/pull/246 */ - WP_Mock::userFunction( 'NewfoldLabs\WP\Module\Data\remove_filter' ) + WP_Mock::userFunction( 'remove_filter' ) ->once() ->with( 'http_headers_useragent', array( $sut, 'add_plugin_name_version_to_user_agent' ) ); @@ -343,7 +343,7 @@ function ( string $constant_name ) use ( $temp_dir ) { * * @see https://github.com/10up/wp_mock/pull/246 */ - WP_Mock::userFunction( 'NewfoldLabs\WP\Module\Data\remove_filter' ) + WP_Mock::userFunction( 'remove_filter' ) ->twice() ->with( 'http_headers_useragent', array( $sut, 'add_plugin_name_version_to_user_agent' ) ); From 380e87bc263ed00f374db02047110b2ac41c012b Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:18:49 -0800 Subject: [PATCH 02/12] Add matrix --- .github/workflows/codecoverage-main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecoverage-main.yml b/.github/workflows/codecoverage-main.yml index 49a12c0..7cbebab 100644 --- a/.github/workflows/codecoverage-main.yml +++ b/.github/workflows/codecoverage-main.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: - php: [ '7.4' ] + php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] steps: - name: Checkout From b46021712b6c8d9ff9069c5fe07f5611a8552b86 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:18:55 -0800 Subject: [PATCH 03/12] Run on pull requests --- .github/workflows/codecoverage-main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/codecoverage-main.yml b/.github/workflows/codecoverage-main.yml index 7cbebab..c1e5cc6 100644 --- a/.github/workflows/codecoverage-main.yml +++ b/.github/workflows/codecoverage-main.yml @@ -7,6 +7,11 @@ on: push: branches: - main + pull_request: + types: [ opened, reopened, ready_for_review, synchronize ] + branches: + - main + workflow_dispatch: jobs: From 421a0845863c75b6ac13f8c03592132f69362a4c Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:19:06 -0800 Subject: [PATCH 04/12] Only commit changes on main --- .github/workflows/codecoverage-main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/codecoverage-main.yml b/.github/workflows/codecoverage-main.yml index c1e5cc6..524e104 100644 --- a/.github/workflows/codecoverage-main.yml +++ b/.github/workflows/codecoverage-main.yml @@ -107,6 +107,7 @@ jobs: run: php-coverage-badger gh-pages/phpunit/clover.xml gh-pages/phpunit/coverage.svg - name: Commit code coverage to gh-pages + if: ${{ github.ref == 'refs/heads/main' && matrix.php-version == '7.3' }} # only commit on main, on the PHP version we're using in production. uses: stefanzweifel/git-auto-commit-action@v5 with: repository: gh-pages From f2685c57e59e30b3e5ab846b0d9fc54c8ad33bdb Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:19:28 -0800 Subject: [PATCH 05/12] Update unit-tests-and-coverage-report.yml --- .../{codecoverage-main.yml => unit-tests-and-coverage-report.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{codecoverage-main.yml => unit-tests-and-coverage-report.yml} (100%) diff --git a/.github/workflows/codecoverage-main.yml b/.github/workflows/unit-tests-and-coverage-report.yml similarity index 100% rename from .github/workflows/codecoverage-main.yml rename to .github/workflows/unit-tests-and-coverage-report.yml From 693b502447981176c8ac6a5ad8e1f8b59e27fcd7 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:29:16 -0800 Subject: [PATCH 06/12] Update actions' versions --- .github/workflows/lint.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 697910d..7a4a99f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,7 +22,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # User PHP 7.4 here for compatibility with the WordPress codesniffer rules. - name: Setup PHP @@ -32,7 +32,7 @@ jobs: coverage: none tools: composer, cs2pr - - uses: technote-space/get-diff-action@v6 + - uses: technote-space/get-diff-action@v6 # repo is archived. with: SUFFIX_FILTER: .php @@ -42,7 +42,7 @@ jobs: if: "!! env.GIT_DIFF" - name: Cache Composer vendor directory - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} From 7a50a91e5956257289ab063db48c199521d64408 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:29:30 -0800 Subject: [PATCH 07/12] Annotate PR with errors --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7a4a99f..8c01fd5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -59,5 +59,5 @@ jobs: if: "!! env.GIT_DIFF" - name: Detecting PHP Code Standards Violations - run: vendor/bin/phpcs --standard=phpcs.xml -s ${{ env.GIT_DIFF }} + run: vendor/bin/phpcs --standard=phpcs.xml -s ${{ env.GIT_DIFF }} --report=checkstyle | cs2pr if: "!! env.GIT_DIFF" From cadabff925cb6e9c2a38b74974680066b7aa889e Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:30:17 -0800 Subject: [PATCH 08/12] Run PHPCBF to auto-fix and commit where possible I.e. don't fail a PR if the computer can fix it --- .github/workflows/lint.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8c01fd5..a9f738e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -39,7 +39,6 @@ jobs: - name: Get Composer cache directory id: composer-cache run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - if: "!! env.GIT_DIFF" - name: Cache Composer vendor directory uses: actions/cache@v4 @@ -48,15 +47,25 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: | ${{ runner.os }}-composer- - if: "!! env.GIT_DIFF" - name: Validate composer.json and composer.lock run: composer validate - if: "!! env.GIT_DIFF" - name: Install dependencies run: composer install --no-progress --optimize-autoloader --prefer-dist - if: "!! env.GIT_DIFF" + + - name: Fix auto-fixable PHP Code Standards Violations + continue-on-error: true + run: vendor/bin/phpcbf --standard=phpcs.xml + + - name: Commit PHPCBF changes on main + if: ${{ github.ref == 'refs/heads/main' }} # only commit on main + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "🤖 PHPCBF" + commit_options: "" + env: + GITHUB_TOKEN: "${{ github.token }}" - name: Detecting PHP Code Standards Violations run: vendor/bin/phpcs --standard=phpcs.xml -s ${{ env.GIT_DIFF }} --report=checkstyle | cs2pr From 81919e2b8899e3e6bcc3e828cda25940614925ef Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:39:25 -0800 Subject: [PATCH 09/12] Debug gh-pages branch needed --- .github/workflows/unit-tests-and-coverage-report.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-and-coverage-report.yml b/.github/workflows/unit-tests-and-coverage-report.yml index 524e104..b6bbcb4 100644 --- a/.github/workflows/unit-tests-and-coverage-report.yml +++ b/.github/workflows/unit-tests-and-coverage-report.yml @@ -39,9 +39,11 @@ jobs: - name: Check does gh-pages branch need to be created run: | if [[ $(git branch -l gh-pages) == "" ]]; then - gh_pages_branch_needed=true + gh_pages_branch_needed=true; + echo "gh-pages branch is needed"; else gh_pages_branch_needed=false + echo "gh-pages branch already exists"; fi echo "GH_PAGES_BRANCH_NEEDED=$gh_pages_branch_needed" >> $GITHUB_ENV; mkdir gh-pages From ab5c6071bf04b115f4678663a2d87aeba4e0c0f0 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:39:33 -0800 Subject: [PATCH 10/12] Update name/description of workflow --- .github/workflows/unit-tests-and-coverage-report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-and-coverage-report.yml b/.github/workflows/unit-tests-and-coverage-report.yml index b6bbcb4..03fcc28 100644 --- a/.github/workflows/unit-tests-and-coverage-report.yml +++ b/.github/workflows/unit-tests-and-coverage-report.yml @@ -1,4 +1,4 @@ -name: Codecoverage-Main +name: Unit tests + Code coverage report # Runs PHPUnit unit and Codeception wp-browser wpunit tests, merges the code coverage, commits the html report to # GitHub Pages, generates a README badge with the coverage percentage. From 93485617eed714edb189ff5c3462cf05c1045125 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:43:01 -0800 Subject: [PATCH 11/12] debug `git branch -l` for gh-pages --- .github/workflows/unit-tests-and-coverage-report.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests-and-coverage-report.yml b/.github/workflows/unit-tests-and-coverage-report.yml index 03fcc28..5d4aae9 100644 --- a/.github/workflows/unit-tests-and-coverage-report.yml +++ b/.github/workflows/unit-tests-and-coverage-report.yml @@ -38,6 +38,7 @@ jobs: - name: Check does gh-pages branch need to be created run: | + git branch -l; if [[ $(git branch -l gh-pages) == "" ]]; then gh_pages_branch_needed=true; echo "gh-pages branch is needed"; From 4f26ce68737b2a0b2ebb87346a25fafd45c42193 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 18 Nov 2024 10:46:35 -0800 Subject: [PATCH 12/12] Update unit-tests-and-coverage-report.yml --- .github/workflows/unit-tests-and-coverage-report.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/unit-tests-and-coverage-report.yml b/.github/workflows/unit-tests-and-coverage-report.yml index 5d4aae9..448863b 100644 --- a/.github/workflows/unit-tests-and-coverage-report.yml +++ b/.github/workflows/unit-tests-and-coverage-report.yml @@ -35,6 +35,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 # attempting to get all branch names. - name: Check does gh-pages branch need to be created run: |