Skip to content

Commit

Permalink
build(*) update to build on metal, simplify stack
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Sep 10, 2023
1 parent b964c7e commit e15dcc3
Show file tree
Hide file tree
Showing 76 changed files with 4,983 additions and 4,602 deletions.
40 changes: 20 additions & 20 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/.git export-ignore
/.gitattributes export-ignore
/.gitbook.yaml export-ignore
/.github export-ignore
/.gitignore export-ignore
/.idea export-ignore
/Makefile export-ignore
/bin export-ignore
/codeception.dist.yml export-ignore
/composer.lock export-ignore
/config export-ignore
/docker-compose.yml export-ignore
/docs export-ignore
/dynamicReturnTypeMeta.json export-ignore
/phpcs.xml export-ignore
/phpstan.neon.dist export-ignore
/tests export-ignore
/var export-ignore
/vendor export-ignore
/version-4-todos.txt export-ignore
/.DS_Store export-ignore
/.cache export-ignore
/.git export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.idea export-ignore
/Makefile export-ignore
/bin export-ignore
/codeception.dist.yml export-ignore
/composer.lock export-ignore
/config export-ignore
/docker-compose.yml export-ignore
/docs export-ignore
/dynamicReturnTypeMeta.json export-ignore
/mkdocs.yml export-ignore
/tests export-ignore
/todo.txt export-ignore
/var export-ignore
/vendor export-ignore
99 changes: 40 additions & 59 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: Test

on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
pull_request: null
push:
branches:
Expand All @@ -20,45 +20,30 @@ jobs:
strategy:
matrix:
php_version: [ '8.0', '8.1', '8.2' ]
name: PHP ${{ matrix.php_version }}
suite:
- acceptance
- climodule
- functional
- muloader
- unit
- webdriver
- wpcli_module
- wploader_multisite
- wploader_wpdb_interaction
- wploadersuite
name: ${{ matrix.suite }} php@${{ matrix.php_version }}
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v2

- name: Build WordPress image
uses: docker/build-push-action@v4
with:
context: config/containers/php
file: config/containers/php/Dockerfile
load: true
push: false
tags: wp-browser-wordpress:php${{ matrix.php_version }}-apache
cache-from: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-wordpress
cache-to: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-wordpress
build-args: |
PHP_VERSION=${{ matrix.php_version }}
TARGET=wordpress
- name: Build Codeception image
uses: docker/build-push-action@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
context: config/containers/php
file: config/containers/php/Dockerfile
load: true
push: false
tags: wp-browser-wordpress:php${{ matrix.php_version }}-codeception
cache-from: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-codeception
cache-to: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-codeception
build-args: |
PHP_VERSION=${{ matrix.php_version }}
TARGET=codeception
- name: Build
run: bin/stack -p${{ matrix.php_version }} -s build
php-version: ${{ matrix.php_version }}
extensions: uopz, sqlite3, gd
ini-values: post_max_size=256M, max_execution_time=180, uopz.exit=1
tools: composer

- name: Cache Composer dependencies
uses: actions/cache@v3
Expand All @@ -67,34 +52,30 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('**/composer.json') }}

- name: Install dependencies
run: bin/stack -p${{ matrix.php_version }} composer_update

- name: acceptance
run: bin/stack -p${{ matrix.php_version }} run acceptance --ext DotReporter
run: composer update

- name: climodule
run: bin/stack -p${{ matrix.php_version }} run climodule --ext DotReporter
- name: Update ChromeDriver
run: vendor/bin/codecept chromedriver:update --binary /usr/bin/google-chrome

- name: functional
run: bin/stack -p${{ matrix.php_version }} run functional --ext DotReporter
- name: Create var/wordpress directory
run: mkdir -p var/wordpress

- name: muloader
run: bin/stack -p${{ matrix.php_version }} run muloader --ext DotReporter
- name: Start services
run: vendor/bin/codecept dev:start

- name: unit
run: bin/stack -p${{ matrix.php_version }} run unit --debug -f
- name: Setup WordPress
run: php bin/setup-wp.php

- name: webdriver
run: bin/stack -p${{ matrix.php_version }} run webdriver --ext DotReporter
- name: Run tests
id: test
run: vendor/bin/codecept run ${{ matrix.suite }}

- name: wpcli_module
run: bin/stack -p${{ matrix.php_version }} run wpcli_module --ext DotReporter

- name: wploader_multisite
run: bin/stack -p${{ matrix.php_version }} run wploader_multisite --ext DotReporter

- name: wploader_wpdb_interaction
run: bin/stack -p${{ matrix.php_version }} run wploader_wpdb_interaction --ext DotReporter

- name: wploadersuite
run: bin/stack -p${{ matrix.php_version }} run wploadersuite --ext DotReporter
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: ${{ matrix.suite }}-php@${{ matrix.php_version }}-screenshots
path: |
var/_output/*.html
var/_output/*.png
retention-days: 3
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ update_sqlite_plugin:

docs_serve:
mkdocs serve -a 0.0.0.0:8000

wordpress_install:
php bin/setup-wp.php

clean_procs:
pgrep -f 'php -S' | xargs kill
pgrep chromedriver | xargs kill
rm -f var/_output/*.pid var/_output/*.running
.PHONY: clean_procs
121 changes: 121 additions & 0 deletions bin/setup-wp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

use Codeception\Configuration;
use lucatume\WPBrowser\Utils\Filesystem;
use lucatume\WPBrowser\WordPress\ConfigurationData;
use lucatume\WPBrowser\WordPress\Database\MysqlDatabase;
use lucatume\WPBrowser\WordPress\Installation;
use lucatume\WPBrowser\WordPress\InstallationState\Configured;
use lucatume\WPBrowser\WordPress\InstallationState\EmptyDir;
use lucatume\WPBrowser\WordPress\InstallationState\InstallationStateInterface;
use lucatume\WPBrowser\WordPress\InstallationState\Scaffolded;

require_once dirname(__DIR__) . '/vendor/autoload.php';

global $_composer_autoload_path, $_composer_bin_dir;
$_composer_autoload_path = $_composer_autoload_path ?: (dirname(__DIR__) . '/vendor/autoload.php');
$_composer_bin_dir = $_composer_bin_dir ?: (dirname(__DIR__) . '/vendor/bin');
Configuration::append(['paths' => ['output' => dirname(__DIR__) . '/var/_output']]);

// Source the tests/.env file.
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__) . '/tests');
$env = $dotenv->load();

$wpRootDir = $env['WORDPRESS_ROOT_DIR'];

echo "Checking WordPress directory $wpRootDir ...\n";
if (!is_dir($wpRootDir) && mkdir($wpRootDir, 0777, true) && !is_dir($wpRootDir)) {
throw new InvalidArgumentException("The WordPress root directory $wpRootDir does not exist.");
}

$installation = new Installation($wpRootDir);

echo "Checking WordPress installation in $wpRootDir ...\n";
if ($installation->getState() instanceof EmptyDir) {
echo "Scaffolding WordPress in $wpRootDir ...\n";
$installation = Installation::scaffold($wpRootDir);
}

echo "Creating database {$env['WORDPRESS_DB_NAME']} ...\n";
$db = new MysqlDatabase(
$env['WORDPRESS_DB_NAME'],
$env['WORDPRESS_DB_USER'],
$env['WORDPRESS_DB_PASSWORD'],
$env['WORDPRESS_DB_HOST'],
$env['WORDPRESS_TABLE_PREFIX'],
);
$db->create();

echo "Checking WordPress configuration in $wpRootDir ...\n";
if ($installation->getState() instanceof Scaffolded) {
echo "Configuring WordPress in $wpRootDir ...\n";
$configData = new ConfigurationData();
$extraPHP = <<< PHP
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'DISABLE_CRON', true );
PHP;
$configData->setExtraPHP($extraPHP);
$installation = $installation->configure(
$db,
InstallationStateInterface::MULTISITE_SUBFOLDER,
$configData
);
}

echo "Checking WordPress installation in $wpRootDir ...\n";
if ($installation->getState() instanceof Configured) {
$db->drop()->create();
echo "Installing WordPress in $wpRootDir ...\n";
$installation = $installation->install(
$env['WORDPRESS_URL'],
$env['WORDPRESS_ADMIN_USER'],
$env['WORDPRESS_ADMIN_PASSWORD'],
$env['WORDPRESS_ADMIN_USER'] . '@example.com',
'TEST',
);
}

echo "Allowing external connections in $wpRootDir ...\n";
$installation->runWpCliCommand(['config', 'delete', 'WP_HTTP_BLOCK_EXTERNAL']);

foreach (['test_subdir', 'test_subdomain', 'test_empty'] as $dbName) {
echo "Creating database $dbName ...\n";
$db->query("CREATE DATABASE IF NOT EXISTS `$dbName`");
}

echo "Checking TwentyTwenty theme in $wpRootDir ...\n";
if (!is_dir($wpRootDir . '/wp-content/themes/twentytwenty')) {
echo "Installing TwentyTwenty theme in $wpRootDir ...\n";
$installation->runWpCliCommandOrThrow(['theme', 'install', 'twentytwenty', '--activate']);
}

echo "Installing required test plugins in $wpRootDir ...\n";
$installation->runWpCliCommandOrThrow(['plugin', 'install', 'woocommerce', 'akismet', 'hello-dolly']);

echo "Blocking external connections in $wpRootDir ...\n";
$installation->runWpCliCommandOrThrow(['config', 'set', 'WP_HTTP_BLOCK_EXTERNAL', 'true']);

echo "Copying over dummy theme to $wpRootDir ...\n";
if (!is_dir('var/wordpress/wp-content/themes/dummy')
&& !Filesystem::recurseCopy('tests/_data/themes/dummy', 'var/wordpress/wp-content/themes/dummy')) {
throw new RuntimeException('Could not copy dummy theme.');
}

echo "Copying over mu-plugin-1 to $wpRootDir ...\n";
if (!is_dir($wpRootDir . '/wp-content/plugins/mu-plugin-1')
&& !Filesystem::recurseCopy('tests/_data/plugins/mu-plugin-1', $wpRootDir . '/wp-content/plugins/mu-plugin-1')) {
throw new RuntimeException('Could not copy mu-plugin-1.');
}

if (!is_file($wpRootDir . '/wp-cli.yml')) {
$url = $env['WORDPRESS_URL'];
if (!file_put_contents(
$wpRootDir . '/wp-cli.yml',
<<<YAML
url: $url
YAML
)) {
throw new RuntimeException('Could not create wp-cli.yml file.');
}
}
Loading

0 comments on commit e15dcc3

Please sign in to comment.