Skip to content

Smoke Test

Smoke Test #181

Workflow file for this run

name: Smoke Test
on:
pull_request:
types: [ labeled ]
workflow_dispatch:
inputs:
ref:
description: 'The branch to run the smoke test on'
required: false
default: 'master'
workflow_run:
workflows: [ Release Plugin ]
types:
- completed
schedule:
- cron: '0 3 * * 0/2'
env:
# Must match the env variables in .dist.env file
TEST_SITE_DB_HOST: localhost
WP_ROOT_FOLDER: /tmp/wordpress
TEST_SITE_DB_NAME: test_acceptance
TEST_SITE_DB_USER: root
TEST_SITE_DB_PASSWORD: root
TEST_SITE_TABLE_PREFIX: wp_
TEST_SITE_ADMIN_USERNAME: admin
TEST_SITE_ADMIN_PASSWORD: password
TEST_SITE_WP_ADMIN_PATH: /wp-admin
TEST_SITE_WP_URL: http://localhost:8888
TEST_SITE_WP_DOMAIN: localhost:8888
TEST_SITE_ADMIN_EMAIL: [email protected]
jobs:
smoke_test:
# If the event is label added, check if the label is 'run: smoke tests' otherwise run the smoke test
if: |
github.event_name == 'pull_request' && contains(github.event.label.name, 'run: smoke tests') ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' && github.ref == 'refs/heads/master' ||
github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' ||
github.event_name == 'schedule'
name: Smoke Test
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 2
matrix:
php: [ 7.4, 8.0 ]
WP_VERSION: [ latest ]
WC_VERSION: [ latest ]
include:
- php: 7.4
WP_VERSION: latest
WC_VERSION: latest
- php: 8.1
WP_VERSION: latest
WC_VERSION: latest
services:
mariadb:
image: mariadb:latest
ports:
- 3306
env:
MYSQL_DATABASE: test_acceptance
MYSQL_ROOT_PASSWORD: root
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: actions/checkout@v3
- name: Setup proper PHP version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: output_buffering=off
extensions: mbstring, intl, pdo_mysql
- name: Setup github token
run: composer config -g github-oauth.github.com ${{ secrets.ACCESS_TOKEN }}
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: |
composer install --no-interaction --prefer-dist --no-progress
- name: Set database connection env globals
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
echo "TEST_SITE_DB_HOST=127.0.0.1:$DB_PORT" >> $GITHUB_ENV
echo "TEST_SITE_DB_DSN=mysql:host=127.0.0.1:$DB_PORT;dbname=$TEST_SITE_DB_NAME" >> $GITHUB_ENV
- name: Verify MariaDB connection and database list
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do
sleep 1
done
mysql -u $TEST_SITE_DB_USER -p"$TEST_SITE_DB_PASSWORD" -h"127.0.0.1" -P"$DB_PORT" -e "SHOW DATABASES;"
- name: Setup WP CLI tools
run: |
mkdir -p $WP_ROOT_FOLDER
mkdir $GITHUB_WORKSPACE/tools
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -P $GITHUB_WORKSPACE/tools/
chmod +x $GITHUB_WORKSPACE/tools/wp-cli.phar && mv $GITHUB_WORKSPACE/tools/wp-cli.phar $GITHUB_WORKSPACE/tools/wp
echo "$GITHUB_WORKSPACE/tools/" >> $GITHUB_PATH
- name: Prepare environment
run: |
# Install WP
wp core download --version=${{ matrix.WP_VERSION }} || exit 1
wp config create --dbname="$TEST_SITE_DB_NAME" --dbuser="$TEST_SITE_DB_USER" --dbpass="$TEST_SITE_DB_PASSWORD" --dbhost="$TEST_SITE_DB_HOST" --dbprefix="$TEST_SITE_TABLE_PREFIX" || exit 1
wp config set WP_DEBUG true --raw || exit 1
wp config set WP_DEBUG_LOG true --raw || exit 1
wp core install --url="$TEST_SITE_WP_URL" --title="Test" --admin_user="$TEST_SITE_ADMIN_USERNAME" --admin_password="$TEST_SITE_ADMIN_PASSWORD" --admin_email="$TEST_SITE_ADMIN_EMAIL" --skip-email || exit 1
wp rewrite structure '/%postname%/' --hard || exit 1
wp core update-db || exit 1
# Uninstall all plugins
wp plugin uninstall --all || exit 1
# Install WooCommerce
if [[ ${{ matrix.WC_VERSION }} == 'latest' ]]; then
wp plugin install woocommerce --activate || exit 1
else
wp plugin install woocommerce --version=${{ matrix.WC_VERSION }} --activate || exit 1
fi
# Import dummy data
wp wc tool run install_pages --user=$TEST_SITE_ADMIN_USERNAME || exit 1
wp plugin install wordpress-importer --activate || exit 1
wp import $WP_ROOT_FOLDER/wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=create >> /dev/null || exit 1
# Deactivate WooCommerce and importer plugin
wp plugin deactivate wordpress-importer --uninstall || exit 1
wp plugin deactivate woocommerce || exit 1
# Install plugin
# wp plugin install $GITHUB_WORKSPACE --activate || exit 1
# Export the database
wp db export $GITHUB_WORKSPACE/tests/_data/dump.sql || exit 1
# Create codeception.yml file
cp $GITHUB_WORKSPACE/codeception.dist.yml $GITHUB_WORKSPACE/codeception.yml || exit 1
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
working-directory: ${{ env.WP_ROOT_FOLDER }}
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- name: Run Selenium
run: nohup java -jar $SELENIUM_JAR_PATH standalone --port 4444 &
- name: Run chromedriver
run: nohup $CHROMEWEBDRIVER/chromedriver --url-base=/wd/hub /dev/null 2>&1 &
- name: Start a web server
run: php -S "$TEST_SITE_WP_DOMAIN" -t "$WP_ROOT_FOLDER" >/dev/null 2>&1 &
- name: Log versions
run: |
echo "Tested on PHP ${{ matrix.php }} and WordPress ${{ matrix.WP_VERSION }} and WooCommerce ${{ matrix.WC_VERSION }}"
echo "PHP version: $(php -v)"
echo "Composer version: $(composer --version)"
echo "Node version: $(node -v)"
echo "NPM version: $(npm -v)"
echo "Yarn version: $(yarn -v)"
- name: Run Codeception acceptance tests
run: composer run-script test:acceptance
- name: Run Codeception functional tests
run: composer run-script test:functional
# - name: Run Codeception WP unit tests
# run: composer run-script test:wpunit
- name: Maybe Upload Tests Output
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: tests-output-${{ matrix.php }}-${{ matrix.WP_VERSION }}-${{ matrix.WC_VERSION }}
path: ./tests/_output/
- name: Maybe Upload Database Dump
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: database-dump-${{ matrix.php }}-${{ matrix.WP_VERSION }}-${{ matrix.WC_VERSION }}
path: ./tests/_data/
- name: Upload Debug Log
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: debug-log-${{ matrix.php }}-${{ matrix.WP_VERSION }}-${{ matrix.WC_VERSION }}
path: ${{ env.WP_ROOT_FOLDER }}/wp-content/debug.log