Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Created March 29, 2021 08:38
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save slaFFik/2642e12668f490bea2d585b8171b1470 to your computer and use it in GitHub Desktop.
Save slaFFik/2642e12668f490bea2d585b8171b1470 to your computer and use it in GitHub Desktop.
GH Actions: WordPress + BuddyPress test environment
name: Tests
on: [ push ]
jobs:
tests:
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
wp-versions: [ 5.6 ]
php-versions: [ 7.4 ]
name: WP ${{ matrix.wp-versions }} on PHP ${{ matrix.php-versions }}
env:
php-ini-values: post_max_size=256M
wp-bp-directory: src/wp-content/plugins/buddypress
DB_DATABASE: wordpress_test
DB_USER: root
DB_PASSWORD: 'root'
DB_HOST: localhost
steps:
- run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE wordpress_test;' -uroot -proot
mysql -e 'SHOW DATABASES;' -uroot -proot
- name: Cancel previous runs of this workflow
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}
- name: Checkout WordPress
uses: actions/checkout@v2
with:
repository: WordPress/wordpress-develop
ref: ${{ matrix.wp-versions }}
path: ''
- name: Checkout BuddyPress
uses: actions/checkout@v2
with:
path: ${{ env.wp-bp-directory }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: pecl
php-version: ${{ matrix.php-versions }}
ini-values: ${{ env.php-ini-values }}
env:
update: true
- name: Get Composer cache directory
working-directory: ${{ env.wp-bp-directory }}
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
working-directory: ${{ env.wp-bp-directory }}
run: composer install -q --prefer-dist --no-progress --ansi --no-interaction --no-suggest
- name: Install NodeJS
uses: actions/setup-node@v1
with:
node-version: 12.16.0
- name: Cache NodeJS modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Node dependencies
working-directory: ${{ env.wp-bp-directory }}
run: npm ci
- name: Install phpunit 5.x on PHP 5.6
if: ${{ matrix.php-versions == '5.6' }}
run: |
composer global require --dev phpunit/phpunit ^5 -q --prefer-dist --no-progress --ansi --no-interaction --no-suggest
phpunit --version
- name: Install phpunit 6.x on PHP 7.4
if: ${{ matrix.php-versions == '7.4' }}
run: |
composer global require --dev phpunit/phpunit ^6 -q --prefer-dist --no-progress --ansi --no-interaction --no-suggest
phpunit --version
- name: Set up tests config
run: |
cp wp-tests-config-sample.php wp-tests-config.php
sed -i "s/youremptytestdbnamehere/${{ env.DB_DATABASE }}/" wp-tests-config.php
sed -i "s/yourusernamehere/${{ env.DB_USER }}/" wp-tests-config.php
sed -i "s/yourpasswordhere/${{ env.DB_PASSWORD }}/" wp-tests-config.php
sed -i "s/localhost/${{ env.DB_HOST }}:${{ job.services.mysql.ports['3306'] }}/" wp-tests-config.php
- name: Upload build artifact (TEMP)
uses: actions/upload-artifact@v2
with:
name: wp-${{ matrix.wp-versions }}-php-${{ matrix.php-versions }}
path: wp-tests-config.php
- name: Run phpunit tests
working-directory: ${{ env.wp-bp-directory }}
run: phpunit
@hendisantika
Copy link

I have this error

Run sudo /etc/init.d/mysql start
  
Starting mysql (via systemctl): mysql.service.
Warning: arning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'mysql8' (-3)
Error: Process completed with exit code 1.

@Cynthia-Amanat
Copy link

i using the same process its seem to work fine and i also migrated and seed the database to run playwright tests

  • name: Migrate and seed the database
    run: php artisan migrate:fresh --seed
    but all test fails that The error message SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment