Skip to content

Commit

Permalink
Merge pull request #912 from matomo-org/wdio-github-action
Browse files Browse the repository at this point in the history
Add github action for wdio tests
  • Loading branch information
diosmosis authored Oct 25, 2023
2 parents 01080ae + 51bd60d commit c97c917
Show file tree
Hide file tree
Showing 20 changed files with 12,994 additions and 117 deletions.
72 changes: 69 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ permissions:
repository-projects: none
security-events: none
statuses: none
id-token: write # for docker gha cache

concurrency:
group: php-${{ github.ref }}
Expand All @@ -39,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
wp-versions: [ 'latest', 'trunk' ]
wp-versions: [ 'latest' ]
php-versions: [ '7.2', '7.3', '7.4', '8.0' ]
include:
- wp-versions: '5.2'
Expand Down Expand Up @@ -100,6 +101,73 @@ jobs:
shell: bash
run: cd ${{ github.workspace }}/wp-content/plugins/matomo && WP_MULTISITE=1 ./vendor/bin/phpunit

e2e_tests:
runs-on: 'ubuntu-22.04'
strategy:
fail-fast: false
matrix:
wp-versions: [ 'latest', 'trunk' ]
php-versions: [ '7.2', '8.1' ]
permissions:
contents: read # <--- allows to read repo
steps:
- uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

# setup xvfb
- run: sudo apt-get update && sudo apt-get install -y xvfb x11-xserver-utils xauth

# setup firefox
- uses: browser-actions/setup-firefox@v1
- run: firefox --version

# setup node
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: '**/package-lock.json'
- run: npm install

# docker-compose up
- run: ls ${{ github.workspace }}/scripts
- run: pwd
# TODO: i can't seem to get docker layer caching to work.
- run: |
export ACTIONS_CACHE_URL=$(echo "$ACTIONS_ID_TOKEN_REQUEST_URL" | grep -Po 'https://[^/]+/[^/]+/' | sed 's/pipelines/artifactcache/')
export ACTIONS_RUNTIME_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN
docker buildx build --cache-to type=gha --cache-from type=gha --build-arg PHP_VERSION=${{ matrix.php-versions }} --build-context project="${{ github.workspace }}/scripts" --file=scripts/Dockerfile.local scripts
env:
PHP_VERSION: ${{ matrix.php-versions }}
WOOCOMMERCE: 1
WORDPRESS_FOLDER: test
RESET_DATABASE: 1
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
- run: docker-compose up -d wordpress
env:
PHP_VERSION: ${{ matrix.php-versions }}
WOOCOMMERCE: 1
WORDPRESS_FOLDER: test
RESET_DATABASE: 1
WORDPRESS_VERSION: ${{ matrix.wp-versions }}
- run: sleep 60 # wait for docker-compose launch to finish

# run tests
- run: xvfb-run --auto-servernum npm run wdio
env:
PHP_VERSION: ${{ matrix.php-versions }}
WOOCOMMERCE: 1
WORDPRESS_FOLDER: test
RESET_DATABASE: 1
WORDPRESS_VERSION: ${{ matrix.wp-versions }}

# output docker-compose logs
- run: docker-compose logs --no-color
- run: docker-compose stop

checkstyle:
runs-on: 'ubuntu-20.04'
steps:
Expand Down Expand Up @@ -137,5 +205,3 @@ jobs:
- name: Run checkstyle
shell: bash
run: cd ${{ github.workspace }}/wp-content/plugins/matomo && ./vendor/bin/phpcs


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
.*~
*~
.idea/
/node_modules/*
!/node_modules/chart.js

# for local docker dev
docker
.env

87 changes: 87 additions & 0 deletions classes/WpMatomo/Commands/MatomoCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use WpMatomo\WpStatistics\Logger\WpCliLogger;
use WpMatomo\Bootstrap;
use WpMatomo\Site;
use WpMatomo\User;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -31,6 +33,91 @@
}

class MatomoCommands extends WP_CLI_Command {

/**
* Installs Matomo if not already installed.
*
* @when after_wp_load
*/
public function install() {
$installer = new Installer( \WpMatomo::$settings );
$installer->register_hooks();
if ( $installer->looks_like_it_is_installed() ) {
WP_CLI::success( 'Already installed.' );
return;
}

if ( ! $installer->can_be_installed() ) {
WP_CLI::error( 'Unable to install.' );
return;
}

$installer->install();
WP_CLI::success( 'Finished installing Matomo.' );
}

/**
* Gets or sets a Matomo for WordPress global setting.
*
* ## OPTIONS
*
* <mode>
* : Either 'get' or 'set'.
*
* <name>
* : The name of the setting.
*
* [<value>]
* : Required if 'set' is used. The value to set the setting to.
*
* @when after_wp_load
*/
public function globalSetting( $args, $assoc_args ) {
$mode = $args[0];
$key = $args[1];

if ( 'set' === $mode ) {
$value = $args[2];
\WpMatomo::$settings->set_global_option( $key, $value );
\WpMatomo::$settings->save();
WP_CLI::success( sprintf( 'Modified Matomo setting %s.', $key ) );
} elseif ( 'get' === $mode ) {
$value = \WpMatomo::$settings->get_global_option( $key );
WP_CLI::success( $value );
} else {
WP_CLI::error( sprintf( 'Invalid mode "%s".', $mode ) );
}
}

/**
* Perform a site or user sync manually.
*
* ## OPTIONS
*
* <mode>
* : Either 'sites' or 'users'.
*
* @when after_wp_load
*/
public function sync( $args, $assoc_args ) {
$mode = $args[0];

if ( 'sites' === $mode ) {
$sync = new Site\Sync( \WpMatomo::$settings );
$success = $sync->sync_all();
if ( ! $success ) {
WP_CLI::error( sprintf( 'Failed to execute site sync, enable logging for more info.' ) );
}
} elseif ( 'users' === $mode ) {
$sync = new User\Sync();
$sync->sync_all();
} else {
WP_CLI::error( sprintf( 'Invalid mode "%s".', $mode ) );
}

WP_CLI::success( sprintf( 'Done syncing %s.', $mode ) );
}

/**
* Uninstalls Matomo.
*
Expand Down
3 changes: 2 additions & 1 deletion classes/WpMatomo/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function __construct( Settings $settings ) {
}

public function register_hooks() {
add_action( 'activate_matomo', [ $this, 'install' ] );
add_action( 'activate_matomo/matomo.php', [ $this, 'install' ] ); // if activate_plugin is invoked with the path to the plugin entrypoint
add_action( 'activate_matomo', [ $this, 'install' ] ); // if activate_plugin is invoked with the plugin slug
}

public function looks_like_it_is_installed() {
Expand Down
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ services:
ports:
- "${PORT:-3000}:80"
environment:
WORDPRESS_VERSION: "$WORDPRESS_VERSION"
WORDPRESS_FOLDER: "$WORDPRESS_FOLDER"
RESET_DATABASE: "$RESET_DATABASE"
WP_DB_HOST: "${BACKEND:-mariadb}"
WOOCOMMERCE: "${WOOCOMMERCE:-}"
WP_ADMIN_USER: "${WP_ADMIN_USER:-root}"
Expand Down Expand Up @@ -55,6 +58,9 @@ services:
- ./docker/wp-cli:/.wp-cli
- "${WOOCOMMERCE_PIWIK_ANALYTICS:-/dev/null}:/var/www/html/woocommerce-piwik-analytics"
environment:
WORDPRESS_VERSION: "$WORDPRESS_VERSION"
WORDPRESS_FOLDER: "$WORDPRESS_FOLDER"
RESET_DATABASE: "$RESET_DATABASE"
WP_DB_HOST: "${BACKEND:-mariadb}"
WOOCOMMERCE: "$WOOCOMMERCE"
WP_ADMIN_USER: "${WP_ADMIN_USER:-root}"
Expand Down Expand Up @@ -97,13 +103,16 @@ services:
ports:
- "${PORT:-3000}:80"
environment:
WORDPRESS_VERSION: "$WORDPRESS_VERSION"
WORDPRESS_FOLDER: "$WORDPRESS_FOLDER"
RESET_DATABASE: "$RESET_DATABASE"
WP_DB_HOST: "${BACKEND:-mariadb}"
WOOCOMMERCE: "$WOOCOMMERCE"
WP_ADMIN_USER: "${WP_ADMIN_USER:-root}"
WP_ADMIN_EMAIL: "${WP_ADMIN_EMAIL:[email protected]}"
PAGER: 'more'
user: "${UID:-1000}:${GID:-1000}"
entrypoint: "/var/www/html/wp-cli.phar --path=/var/www/html/${WORDPRESS_VERSION:-6.3.1}"
entrypoint: "/var/www/html/wp-cli.phar --path=/var/www/html/${WORDPRESS_VERSION}"
depends_on:
- "${BACKEND:-mariadb}"
console:
Expand Down
118 changes: 46 additions & 72 deletions node_modules/chart.js/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c97c917

Please sign in to comment.