diff --git a/.forgejo/workflows/phpcs.yml b/.forgejo/workflows/phpcs.yml index 4db1ac5..8a18ae7 100755 --- a/.forgejo/workflows/phpcs.yml +++ b/.forgejo/workflows/phpcs.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: php-versions: ['8.1'] - name: Run PHP Code Checker + name: PHP Code Checker env: extensions: mysql key: cache-v1 @@ -25,17 +25,26 @@ jobs: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 + - name: Cache Composer + id: cache-composer + uses: https://code.forgejo.org/actions/cache@v4 + with: + path: | + ./vendor/ + key: cache-composer-phpcs-1 + - name: Setup PHP uses: https://github.com/shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} coverage: none - tools: composer, cs2pr + tools: composer env: runner: self-hosted - name: Install Composer dependencies for PHP + if: steps.cache-composer.outputs.cache-hit != 'true' uses: ramsey/composer-install@v3 - name: Detect coding standard violations - run: ./vendor/bin/phpcs \ No newline at end of file + run: ./vendor/bin/phpcs diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index 0daeb73..e96a415 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -1,4 +1,5 @@ -name: Unit Testing +name: PHPUnit + on: push: branches: @@ -19,8 +20,8 @@ jobs: MYSQL_ROOT_PASSWORD: root strategy: matrix: - php-versions: ['8.1'] - name: Run phpunit tests + php-version: ['8.1', '8.2', '8.3'] + name: PHPUnit – PHP ${{ matrix.php-version }} env: extensions: mysql key: cache-v1 @@ -28,25 +29,51 @@ jobs: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 + - name: Cache WordPress Setup + id: cache-wordpress + uses: https://code.forgejo.org/actions/cache@v4 + with: + path: | + ${{ env.WP_CORE_DIR }} + ${{ env.WP_TESTS_DIR }} + key: cache-wordpress-1 + + - name: Cache Composer + id: cache-composer-phpunit + uses: https://code.forgejo.org/actions/cache@v4 + with: + path: | + ./vendor/ + key: cache-composer-phpunit-1 + - name: Setup PHP uses: https://github.com/shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-versions }} + php-version: ${{ matrix.php-version }} coverage: none - tools: composer, phpunit-polyfills + tools: composer env: runner: self-hosted - - name: Install Composer dependencies for PHP - uses: ramsey/composer-install@v3 + - name: Install PHPUnit and PHPUnit-Polyfills + if: steps.cache-composer-phpunit.outputs.cache-hit != 'true' + run: composer require --dev yoast/phpunit-polyfills:"^3.0" - - name: Install mysqladmin - run: sudo apt update && sudo apt -y upgrade && sudo apt -y install mysql-client + - name: Install and cache mysqladmin needed to initialize the test database + uses: https://github.com/awalsh128/cache-apt-pkgs-action@latest + with: + packages: mysql-client + version: 1.0 - name: Setup Test Environment - run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 + if: steps.cache-wordpress.outputs.cache-hit != 'true' + run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 false false false false + + - name: Initialize WordPress test database + if: steps.cache-wordpress.outputs.cache-hit != 'false' + run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 false true true true - name: Unit Testing - run: cd /workspace/Event-Federation/wordpress-activitypub-event-extensions/ && phpunit + run: cd /workspace/Event-Federation/wordpress-activitypub-event-extensions/ && ./vendor/bin/phpunit env: - PHP_VERSION: ${{ matrix.php-versions }} + PHP_VERSION: ${{ matrix.php-version }} diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index e772021..f10e7c3 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + echo "usage: $0 [db-host] [wp-version] [skip-database-creation] [skip-wp-install] [skip-plugins] [skip-test-suite]" exit 1 fi @@ -11,6 +11,10 @@ DB_PASS=$3 DB_HOST=${4-localhost} WP_VERSION=${5-latest} SKIP_DB_CREATE=${6-false} +SKIP_WP_INSTALL=${7-false} +SKIP_PLUGINS_INSTALL=${8-false} +SKIP_TEST_SUITE_INSTALL=${9-false} + TMPDIR=${TMPDIR-/tmp} TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") @@ -54,7 +58,10 @@ fi set -ex install_wp() { - rm -rf $WP_CORE_DIR + if [ "$SKIP_WP_INSTALL" = "true" ]; then + echo "Skipping WordPress installation." + return 0 + fi if [ -d $WP_CORE_DIR ]; then return; @@ -97,6 +104,11 @@ install_wp() { } install_test_suite() { + if [ "$SKIP_TEST_SUITE_INSTALL" = "true" ]; then + echo "Skipping test suite installation." + return 0 + fi + # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then local ioption='-i.bak' @@ -178,7 +190,11 @@ install_db() { } install_wp_plugins() { - download https://downloads.wordpress.org/plugin/activitypub.3.2.5.zip $TMPDIR/activitypub.zip + if [ "$SKIP_PLUGINS_INSTALL" = "true" ]; then + echo "Skipping WordPress plugin installation." + return 0 + fi + download https://downloads.wordpress.org/plugin/activitypub.3.2.5.zip $TMPDIR/activitypub.zip unzip $TMPDIR/activitypub.zip -d $WP_CORE_DIR/wp-content/plugins/ } diff --git a/composer.json b/composer.json index 945c004..8a5b5a5 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "phpcompatibility/php-compatibility": "*", "phpcompatibility/phpcompatibility-wp": "*", "squizlabs/php_codesniffer": "3.*", - "wp-coding-standards/wpcs": "dev-develop", + "wp-coding-standards/wpcs": "^3.1.0", "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", "sirbrillig/phpcs-variable-analysis": "^2.11" }, @@ -32,7 +32,7 @@ }, "scripts": { "lint": [ - "vendor/bin/phpcs -n -q" + "vendor/bin/phpcs" ], "lint:fix": [ "vendor/bin/phpcbf"