Skip to content

Update workflow

Update workflow #38

Workflow file for this run

name: Run Tests
on:
push:
branches: [ main, workflow ]
pull_request:
branches: [ main, workflow ]
env:
IGNORED_PHP_VERSIONS: "" # Space-separated list of ignored PHP versions
IGNORED_WP_VERSIONS: "6.5.1" # Space-separated list of ignored WordPress versions
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@v4
- 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 }}
IGNORED_PHP_VERSIONS=(${IGNORED_PHP_VERSIONS})
# Fetch PHP versions and filter out the latest minor versions
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')
echo "Fetched PHP Versions: $PHP_VERSIONS"
LATEST_PHP_VERSIONS=$(echo "$PHP_VERSIONS" | awk -F. '{print $1"."$2"."$3}' | sort -t. -k1,1n -k2,2n -k3,3n | awk -F. '{
major_minor=$1"."$2
latest[major_minor]=$0
} END {
for (i in latest) print latest[i]
}')
if [ -n "${IGNORED_PHP_VERSIONS[*]}" ]; then
LATEST_PHP_VERSIONS=$(echo "$LATEST_PHP_VERSIONS" | grep -v -E "$(IFS="|"; echo "${IGNORED_PHP_VERSIONS[*]}")")
fi
echo "Latest PHP Versions: $LATEST_PHP_VERSIONS"
PHP_VERSIONS_JSON=$(echo "$LATEST_PHP_VERSIONS" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "PHP_VERSIONS=$PHP_VERSIONS_JSON" >> $GITHUB_ENV
echo "versions=$PHP_VERSIONS_JSON" >> $GITHUB_OUTPUT
- name: Fetch available WP versions
id: set-wp-versions
run: |
MIN_WP_VERSION=${{ env.WP_VERSION }}
IGNORED_WP_VERSIONS=(${IGNORED_WP_VERSIONS})
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 -R -s -c 'split("\n") | map(select(length > 0))')
if [ -n "${IGNORED_WP_VERSIONS[*]}" ]; then
WP_VERSIONS_JSON=$(echo "$WP_VERSIONS_JSON" | jq -c --argjson ignored "$(jq -n '$ARGS.positional' --args ${IGNORED_WP_VERSIONS[@]})" 'map(select(. as $v | $ignored | index($v) | not))')
fi
echo "WP_VERSIONS=$WP_VERSIONS_JSON" >> $GITHUB_ENV
echo "versions=$WP_VERSIONS_JSON" >> $GITHUB_OUTPUT
- name: Debug Outputs
run: |
echo "PHP Versions JSON: ${{ steps.set-php-versions.outputs.versions }}"
echo "WP Versions JSON: ${{ steps.set-wp-versions.outputs.versions }}"
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: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer, wp-cli
- 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: Create Database
run: wp db create --path=wordpress
- 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: Checkout code
uses: actions/checkout@v4
with:
path: wordpress/wp-content/plugins/wp-plugin-mold
- name: Install dependencies
run: composer install --prefer-dist --no-progress --working-dir=wordpress/wp-content/plugins/wp-plugin-mold
- name: Install and activate the plugin
run: wp plugin activate wp-plugin-mold --path=wordpress
- name: Run PHP tests
run: composer test --working-dir=wordpress/wp-content/plugins/wp-plugin-mold
- 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