Skip to content

Allow testing on workflow branch #20

Allow testing on workflow branch

Allow testing on workflow branch #20

Workflow file for this run

name: Run Tests
on:
push:
branches: [ main, workflow ]
pull_request:
branches: [ main, workflow ]
jobs:
fetch-versions:
runs-on: ubuntu-latest
outputs:
php-versions: ${{ steps.set-php-versions.outputs.versions }}
wp-versions: ${{ steps.set-wp-versions.outputs.versions }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Extract PHP and WP version requirements
id: extract
run: |
PHP_VERSION=$(grep -i "Requires PHP" wp-plugin-mold.php | sed -E 's/.*Requires PHP:\s*([0-9\.]+).*/\1/')
WP_VERSION=$(grep -i "Requires at least" wp-plugin-mold.php | sed -E 's/.*Requires at least:\s*([0-9\.]+).*/\1/')
echo "PHP_VERSION=${PHP_VERSION}" >> $GITHUB_ENV
echo "WP_VERSION=${WP_VERSION}" >> $GITHUB_ENV
- name: Fetch available PHP versions
id: set-php-versions
run: |
MIN_PHP_VERSION=${{ env.PHP_VERSION }}
PHP_VERSIONS=$(curl -s https://api.github.com/repos/php/php-src/git/refs/tags | jq -r '.[].ref' | grep -E 'refs/tags/php-[0-9]+\.[0-9]+\.[0-9]+$' | sed 's#refs/tags/php-##' | grep -vE 'alpha|beta|rc' | awk -v min=$MIN_PHP_VERSION '$1 >= min')
PHP_VERSIONS_JSON=$(echo $PHP_VERSIONS | jq -Rnc '[inputs | split("\n") | .[] | select(length > 0)]')
echo "versions=${PHP_VERSIONS_JSON}" >> $GITHUB_OUTPUT
- name: Fetch available WP versions
id: set-wp-versions
run: |
MIN_WP_VERSION=${{ env.WP_VERSION }}
WP_VERSIONS=$(curl -s https://api.github.com/repos/WordPress/WordPress/git/refs/tags | jq -r '.[].ref' | grep -E 'refs/tags/[0-9]+\.[0-9]+\.[0-9]+$' | sed 's#refs/tags/##' | awk -v min=$MIN_WP_VERSION '$1 >= min')
WP_VERSIONS_JSON=$(echo $WP_VERSIONS | jq -Rnc '[inputs | split("\n") | .[] | select(length > 0)]')
echo "versions=${WP_VERSIONS_JSON}" >> $GITHUB_OUTPUT
run-tests:
needs: fetch-versions
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ${{ fromJson(needs.fetch-versions.outputs.php-versions) }}
wp-version: ${{ fromJson(needs.fetch-versions.outputs.wp-versions) }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer, wp-cli
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Download WordPress
run: wp core download --version=${{ matrix.wp-version }} --path=wordpress
- name: Create wp-config.php
run: wp config create --path=wordpress --dbname=wordpress --dbuser=root --dbpass=root --dbhost=127.0.0.1 --skip-check
- name: Install WordPress
run: wp core install --path=wordpress --url=http://localhost --title="Test Site" --admin_user=admin --admin_password=admin --admin_email=test@example.com
- name: Install and activate the plugin
run: |
cp -r . wordpress/wp-content/plugins/wp-plugin-mold
wp plugin activate wp-plugin-mold --path=wordpress
- name: Run PHP tests
run: composer test
- name: Run WordPress plugin activation test
run: wp eval 'echo "Plugin activated successfully\n";' --path=wordpress
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=3