Improve Actions (#27)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 34s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 58s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 57s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 54s

Try to make caching in Forgejo Actions work.

Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#27
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
This commit is contained in:
André Menrath 2024-09-21 14:06:11 +02:00 committed by André Menrath
parent 575aff68b0
commit 712e56c87e
4 changed files with 72 additions and 20 deletions

View file

@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-versions: ['8.1']
name: Run PHP Code Checker
name: PHP Code Checker
env:
extensions: mysql
key: cache-v1
@ -25,17 +25,26 @@ jobs:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
- name: Cache Composer
id: cache-composer
uses: https://code.forgejo.org/actions/cache@v4
with:
path: |
./vendor/
key: cache-composer-phpcs-1
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
tools: composer, cs2pr
tools: composer
env:
runner: self-hosted
- name: Install Composer dependencies for PHP
if: steps.cache-composer.outputs.cache-hit != 'true'
uses: ramsey/composer-install@v3
- name: Detect coding standard violations
run: ./vendor/bin/phpcs
run: ./vendor/bin/phpcs

View file

@ -1,4 +1,5 @@
name: Unit Testing
name: PHPUnit
on:
push:
branches:
@ -19,8 +20,8 @@ jobs:
MYSQL_ROOT_PASSWORD: root
strategy:
matrix:
php-versions: ['8.1']
name: Run phpunit tests
php-version: ['8.1', '8.2', '8.3']
name: PHPUnit PHP ${{ matrix.php-version }}
env:
extensions: mysql
key: cache-v1
@ -28,25 +29,51 @@ jobs:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
- name: Cache WordPress Setup
id: cache-wordpress
uses: https://code.forgejo.org/actions/cache@v4
with:
path: |
${{ env.WP_CORE_DIR }}
${{ env.WP_TESTS_DIR }}
key: cache-wordpress-1
- name: Cache Composer
id: cache-composer-phpunit
uses: https://code.forgejo.org/actions/cache@v4
with:
path: |
./vendor/
key: cache-composer-phpunit-1
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php-version }}
coverage: none
tools: composer, phpunit-polyfills
tools: composer
env:
runner: self-hosted
- name: Install Composer dependencies for PHP
uses: ramsey/composer-install@v3
- name: Install PHPUnit and PHPUnit-Polyfills
if: steps.cache-composer-phpunit.outputs.cache-hit != 'true'
run: composer require --dev yoast/phpunit-polyfills:"^3.0"
- name: Install mysqladmin
run: sudo apt update && sudo apt -y upgrade && sudo apt -y install mysql-client
- name: Install and cache mysqladmin needed to initialize the test database
uses: https://github.com/awalsh128/cache-apt-pkgs-action@latest
with:
packages: mysql-client
version: 1.0
- name: Setup Test Environment
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6
if: steps.cache-wordpress.outputs.cache-hit != 'true'
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 false false false false
- name: Initialize WordPress test database
if: steps.cache-wordpress.outputs.cache-hit != 'false'
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 false true true true
- name: Unit Testing
run: cd /workspace/Event-Federation/wordpress-activitypub-event-extensions/ && phpunit
run: cd /workspace/Event-Federation/wordpress-activitypub-event-extensions/ && ./vendor/bin/phpunit
env:
PHP_VERSION: ${{ matrix.php-versions }}
PHP_VERSION: ${{ matrix.php-version }}

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation] [skip-wp-install] [skip-plugins] [skip-test-suite]"
exit 1
fi
@ -11,6 +11,10 @@ DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
SKIP_WP_INSTALL=${7-false}
SKIP_PLUGINS_INSTALL=${8-false}
SKIP_TEST_SUITE_INSTALL=${9-false}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
@ -54,7 +58,10 @@ fi
set -ex
install_wp() {
rm -rf $WP_CORE_DIR
if [ "$SKIP_WP_INSTALL" = "true" ]; then
echo "Skipping WordPress installation."
return 0
fi
if [ -d $WP_CORE_DIR ]; then
return;
@ -97,6 +104,11 @@ install_wp() {
}
install_test_suite() {
if [ "$SKIP_TEST_SUITE_INSTALL" = "true" ]; then
echo "Skipping test suite installation."
return 0
fi
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i.bak'
@ -178,7 +190,11 @@ install_db() {
}
install_wp_plugins() {
download https://downloads.wordpress.org/plugin/activitypub.3.2.5.zip $TMPDIR/activitypub.zip
if [ "$SKIP_PLUGINS_INSTALL" = "true" ]; then
echo "Skipping WordPress plugin installation."
return 0
fi
download https://downloads.wordpress.org/plugin/activitypub.3.2.5.zip $TMPDIR/activitypub.zip
unzip $TMPDIR/activitypub.zip -d $WP_CORE_DIR/wp-content/plugins/
}

View file

@ -10,7 +10,7 @@
"phpcompatibility/php-compatibility": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"squizlabs/php_codesniffer": "3.*",
"wp-coding-standards/wpcs": "dev-develop",
"wp-coding-standards/wpcs": "^3.1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"sirbrillig/phpcs-variable-analysis": "^2.11"
},
@ -32,7 +32,7 @@
},
"scripts": {
"lint": [
"vendor/bin/phpcs -n -q"
"vendor/bin/phpcs"
],
"lint:fix": [
"vendor/bin/phpcbf"