From a8b878b122ff01e4a9f215853e5d8b4a0d46bd37 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Dec 2021 09:56:03 +0000 Subject: [PATCH 1/3] CI: Add concurrency to CI configs Previously, in Travis, when the same branch was pushed again and the "Auto cancellation" option on the "Settings" page had been turned on (as it was for most repos), any still running builds for the same branch would be stopped in favour of starting the build for the newly pushed version of the branch. To enable this behaviour in GH Actions, a concurrency configuration needs to be added to each workflow for which this should applied to. More than anything, this is a way to be kind to GitHub by not wasting resources which they so kindly provide to us for free. --- .github/workflows/codeql-analysis.yml | 6 ++++++ .github/workflows/cs-lint.yml | 6 ++++++ .github/workflows/integration-tests.yml | 6 ++++++ .github/workflows/node.js.yml | 6 ++++++ .github/workflows/unit-tests.yml | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ab664b453..387d7aad3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,6 +13,12 @@ on: schedule: - cron: '27 20 * * 2' +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: analyze: name: Analyze diff --git a/.github/workflows/cs-lint.yml b/.github/workflows/cs-lint.yml index a59a1d68a..e5dba5143 100644 --- a/.github/workflows/cs-lint.yml +++ b/.github/workflows/cs-lint.yml @@ -10,6 +10,12 @@ on: # Allow manually triggering the workflow. workflow_dispatch: +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: checkcs: name: 'Basic CS and QA checks' diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 30c6e7c2d..2c82a88d4 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -8,6 +8,12 @@ on: - '**.md' pull_request: +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: test: name: PHP ${{ matrix.php }} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 7450c59f3..17c452400 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -11,6 +11,12 @@ on: - '**/*[tj]sx?' - package*.json +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: runs-on: ubuntu-20.04 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 3e28962bd..def12077b 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -10,6 +10,12 @@ on: # Allow manually triggering the workflow. workflow_dispatch: +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: test: name: PHP ${{ matrix.php }} From 74f7877ef00d46c03f28f3038684f69fadd9ca40 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Dec 2021 10:04:14 +0000 Subject: [PATCH 2/3] CI: Composer tweaks - `ramsay/composer-install`, the action used to install Composer packages and handle the caching has released a new major (and some follow-up patch releases), which means the action reference needs to be updated to benefit from it. - Add `--no-interaction` to "plain" Composer commands to potentially prevent CI hanging if, for whatever reason, interaction would be needed in the future. --- .github/workflows/cs-lint.yml | 6 +++--- .github/workflows/integration-tests.yml | 10 +++++----- .github/workflows/unit-tests.yml | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cs-lint.yml b/.github/workflows/cs-lint.yml index e5dba5143..884bef6da 100644 --- a/.github/workflows/cs-lint.yml +++ b/.github/workflows/cs-lint.yml @@ -48,16 +48,16 @@ jobs: # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate - name: Validate Composer installation - run: composer validate --no-check-all --strict + run: composer validate --no-check-all --strict --no-interaction # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: Install Composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 # Lint PHP. - name: Lint PHP against parse errors - run: composer lint-ci | cs2pr + run: composer lint-ci --no-interaction | cs2pr # Needed as runs-on: system doesn't have xml-lint by default. # @link https://github.com/marketplace/actions/xml-lint diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 2c82a88d4..c05162edf 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -70,11 +70,11 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install Composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 # - name: Install Composer dependencies for PHP >= 8.2 # if: ${{ matrix.php >= 8.2 }} - # uses: ramsey/composer-install@v1 + # uses: ramsey/composer-install@v2 # with: # composer-options: --ignore-platform-reqs @@ -86,12 +86,12 @@ jobs: run: mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" - name: Prepare environment for integration tests - run: composer prepare-ci + run: composer prepare-ci --no-interaction - name: Run integration tests (single site) if: ${{ matrix.php != 8.0 }} - run: composer testwp + run: composer testwp --no-interaction - name: Run integration tests (multisite site with code coverage) if: ${{ matrix.php == 8.0 }} - run: composer coveragewp-ci + run: composer coveragewp-ci --no-interaction diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index def12077b..2f843d022 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -73,13 +73,13 @@ jobs: - name: Install Composer dependencies for PHP < 8.2 if: ${{ matrix.php < 8.2 }} - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 - name: Install Composer dependencies for PHP >= 8.2 if: ${{ matrix.php >= 8.2 }} - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: composer-options: --ignore-platform-reqs - name: Run unit tests - run: composer test + run: composer test --no-interaction From 2621daf84460f042dc833da060d231b4d4bff035 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Dec 2021 10:22:47 +0000 Subject: [PATCH 3/3] Composer: permit composer plugins The `dealerdirect/phpcodesniffer-composer-installer` and `composer/installers` Composer plugins are used to register an external PHPCS standards with PHPCS, and allow the plugin to be installed in a `wp-content/plugins` directory. As of Composer 2.2.0, Composer plugins need to be explicitly allowed to run. This adds the necessary configuration for that. Any globally-installed Composer plugin should be configured in the global `composer.json`. `composer normalize` also run on the file, which fixes a non-alphabetical script. Also refresh the list of script descriptions. Refs: https://blog.packagist.com/composer-2-2/#more-secure-plugin-execution --- composer.json | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index d55792abb..3f11fee5a 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,12 @@ "wp-coding-standards/wpcs": "^2.3.0", "yoast/wp-test-utils": "^1" }, + "config": { + "allow-plugins": { + "composer/installers": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "autoload": { "classmap": [ "src/" @@ -42,14 +48,14 @@ "@putenv WP_MULTISITE=1", "@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html/unit -v" ], - "coveragewp": [ - "@putenv WP_MULTISITE=1", - "@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html/integration -c phpunit-integration.xml.dist -v" - ], "coverage-ci": [ "@putenv WP_MULTISITE=1", "@php ./vendor/bin/phpunit -v" ], + "coveragewp": [ + "@putenv WP_MULTISITE=1", + "@php ./vendor/bin/phpunit --coverage-html ./build/coverage-html/integration -c phpunit-integration.xml.dist -v" + ], "coveragewp-ci": [ "@putenv WP_MULTISITE=1", "@php ./vendor/bin/phpunit -c phpunit-integration.xml.dist -v" @@ -82,13 +88,17 @@ ] }, "scripts-descriptions": { - "coverage": "Run tests with code coverage for the Parse.ly plugin and generate local HTML output.", - "coverage-ci": "Run tests with code coverage for the Parse.ly plugin and generate a Clover XML file for CI.", + "coverage": "Run unit tests with code coverage for the Parse.ly plugin, send results to stdout, and generate plus local HTML output.", + "coverage-ci": "Run unit tests with code coverage for the Parse.ly plugin and send results to stdout.", + "coveragewp": "Run integration tests with code coverage for the Parse.ly plugin, send results to stdout, and generate local HTML output.", + "coveragewp-ci": "Run integration tests with code coverage for the Parse.ly plugin and send results to stdout.", "cs": "Run PHPCS to checking coding standards for the Parse.ly plugin.", "lint": "Run PHP linting on the Parse.ly plugin.", "lint-ci": "Run PHP linting on the Parse.ly plugin with checkstyle output for CI.", "prepare-ci": "Install the files and setup a database needed to run tests for the Parse.ly plugin for CI.", - "test": "Run the tests for the Parse.ly plugin.", - "test-ms": "Run the tests for the Parse.ly plugin on a multisite install." + "test": "Run the unit tests for the Parse.ly plugin.", + "test-ms": "Run the unit tests for the Parse.ly plugin on a multisite install.", + "testwp": "Run the integration tests for the Parse.ly plugin.", + "testwp-ms": "Run the integration tests for the Parse.ly plugin on a multisite install." } }