diff --git a/.distignore b/.distignore index da31e4e..dcb821b 100644 --- a/.distignore +++ b/.distignore @@ -4,7 +4,6 @@ .git .gitignore .gitattributes -.travis.yml .DS_Store .wordpress-org .github diff --git a/.gitattributes b/.gitattributes index 034fdd4..1b1d528 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,6 @@ .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.travis.yml export-ignore composer.json export-ignore deploy.sh export-ignore phpcs.xml.dist export-ignore diff --git a/.github/workflows/phpunit-ci.yml b/.github/workflows/phpunit-ci.yml new file mode 100644 index 0000000..21df7c2 --- /dev/null +++ b/.github/workflows/phpunit-ci.yml @@ -0,0 +1,112 @@ +name: PHPUnit Tests + +on: + push: + branches: + - master + - release/* + pull_request: + +jobs: + test: + name: PHP ${{ matrix.php }} - WP ${{ matrix.wp }} + runs-on: ubuntu-latest + + permissions: + contents: read + + strategy: + fail-fast: false + matrix: + php: ['7.4', '8.0', '8.1', '8.2'] + wp: ['latest'] + experimental: [false] + include: + # Test with older WordPress version + - php: '7.4' + wp: '4.9' + experimental: false + - php: '8.0' + wp: '4.9' + experimental: false + # Test with WordPress trunk/master (allow failures) + - php: '8.2' + wp: 'trunk' + experimental: true + + continue-on-error: ${{ matrix.experimental }} + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: wordpress_tests + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mysqli + coverage: none + tools: composer + + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Setup Composer cache + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-progress --no-interaction + + - name: PHP Lint + run: find -L . -path ./vendor -prune -o -name '*.php' -not -name 'class-wp-ms-network-command.php' -print0 | xargs -0 -n 1 -P 4 php -l + + - name: Setup WordPress test environment + env: + WP_VERSION: ${{ matrix.wp }} + run: | + if [[ "$WP_VERSION" == "latest" ]]; then + WP_VERSION=$(curl -s http://api.wordpress.org/core/version-check/1.7/ | grep -o '"version":"[^"]*' | sed 's/"version":"//' | head -1) + fi + if [[ "$WP_VERSION" == "trunk" ]]; then + WP_VERSION="master" + fi + + # Get plugin slug from repository name + PLUGIN_SLUG=$(basename "$GITHUB_WORKSPACE") + + # Clone WordPress + git clone --depth=1 --branch="$WP_VERSION" https://github.com/WordPress/wordpress-develop.git /tmp/wordpress + + # Setup plugin directory + mkdir -p /tmp/wordpress/src/wp-content/mu-plugins + cp -r "$GITHUB_WORKSPACE" "/tmp/wordpress/src/wp-content/mu-plugins/$PLUGIN_SLUG" + + # Configure tests + cd /tmp/wordpress + cp wp-tests-config-sample.php wp-tests-config.php + sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php + sed -i "s/yourusernamehere/root/" wp-tests-config.php + sed -i "s/yourpasswordhere//" wp-tests-config.php + sed -i "s/localhost/127.0.0.1/" wp-tests-config.php + + - name: Run PHPUnit tests + run: | + PLUGIN_SLUG=$(basename "$GITHUB_WORKSPACE") + cd "/tmp/wordpress/src/wp-content/mu-plugins/$PLUGIN_SLUG" + vendor/bin/phpunit -c phpunit.xml.dist diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f253323..0000000 --- a/.travis.yml +++ /dev/null @@ -1,95 +0,0 @@ -sudo: false -dist: trusty - -language: php - -notifications: - email: - on_success: never - on_failure: change - -cache: - directories: - - $HOME/.composer/cache - -matrix: - include: - - php: 7.4 - env: WP_VERSION=latest WP_MULTISITE=1 PHPLINT=1 - - php: 7.3 - env: WP_VERSION=latest WP_MULTISITE=1 - - php: 7.2 - env: WP_VERSION=latest WP_MULTISITE=1 - - php: 8.0 - env: WP_VERSION=latest WP_MULTISITE=1 PHPLINT=1 - dist: precise - - php: 7.2 - env: WP_VERSION=4.9 WP_MULTISITE=1 - - php: 8.0 - env: WP_VERSION=4.9 WP_MULTISITE=1 - dist: precise - - php: nightly - env: WP_VERSION=master WP_MULTISITE=1 - allow_failures: - - php: nightly - env: WP_VERSION=master WP_MULTISITE=1 - -before_script: - - | - if [[ "$COVERAGE" != "1" ]]; then - stable='^[0-9\.]+$' - if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then - if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then - phpenv config-rm xdebug.ini - fi - fi - fi - - | - case "$TRAVIS_PHP_VERSION" in - 5.6|5.5|5.4|5.3) - composer global require "phpunit/phpunit:^4" - ;; - 5.2) - ;; - *) - composer install --no-interaction - ;; - esac - - | - if [[ "$WP_VERSION" == "latest" ]]; then - curl -s http://api.wordpress.org/core/version-check/1.7/ > /tmp/wp-latest.json - WP_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') - fi - - PLUGIN_SLUG=$(basename $(pwd)) - - export WP_DEVELOP_DIR=/tmp/wordpress/ - - git clone --depth=50 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress - - cd .. - - mkdir -p /tmp/wordpress/src/wp-content/mu-plugins - - cp -r "$PLUGIN_SLUG" "/tmp/wordpress/src/wp-content/mu-plugins/$PLUGIN_SLUG" - - cd /tmp/wordpress/ - - cp wp-tests-config-sample.php wp-tests-config.php - - sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php - - sed -i "s/yourusernamehere/travis/" wp-tests-config.php - - sed -i "s/yourpasswordhere//" wp-tests-config.php - - mysql -e "CREATE DATABASE wordpress_tests;" -uroot - - cd "/tmp/wordpress/src/wp-content/mu-plugins/$PLUGIN_SLUG" - - phpenv rehash -script: - - | - if [[ "$PHPLINT" == "1" ]]; then - find -L . -path ./vendor -prune -o -name '*.php' -not -name 'class-wp-ms-network-command.php' -print0 | xargs -0 -n 1 -P 4 php -l - fi - - | - case "$TRAVIS_PHP_VERSION" in - 5.6|5.5|5.4|5.3|5.2) - phpunit -c phpunit.xml.dist - ;; - *) - if [[ "$COVERAGE" == "1" ]]; then - mkdir -p build/logs - vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml - else - vendor/bin/phpunit -c phpunit.xml.dist - fi - ;; - esac diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1092ad9..3888d75 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,8 +18,9 @@ This project provides workflows for: * running integration tests (using PHPUnit) * checking coding and documentation standards (using PHPCodeSniffer). +* static analysis (using PHPStan). -It is also integrated with Travis-CI to ensure those always pass. +It is also integrated with GitHub Actions to ensure those always pass. ### PHPUnit and PHPCS Workflows diff --git a/deploy.sh b/deploy.sh index 0e27008..56d46a9 100644 --- a/deploy.sh +++ b/deploy.sh @@ -96,7 +96,6 @@ svn propset --quiet svn:ignore ".editorconfig .git .gitattributes .gitignore -.travis.yml composer.json composer.lock deploy.sh