mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Parallel testing to github
This commit is contained in:
parent
d708d054f2
commit
89956c7ff8
115
.github/workflows/parallel.yml
vendored
Normal file
115
.github/workflows/parallel.yml
vendored
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- v5-develop
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- v5-develop
|
||||||
|
|
||||||
|
name: parallel
|
||||||
|
jobs:
|
||||||
|
run:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
operating-system: ['ubuntu-20.04', 'ubuntu-22.04']
|
||||||
|
php-versions: ['8.1']
|
||||||
|
phpunit-versions: ['latest']
|
||||||
|
ci_node_total: [ 4 ]
|
||||||
|
ci_node_index: [ 0, 1, 2, 3 ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
DB_DATABASE1: ninja
|
||||||
|
DB_USERNAME1: root
|
||||||
|
DB_PASSWORD1: ninja
|
||||||
|
DB_HOST1: '127.0.0.1'
|
||||||
|
DB_DATABASE: ninja
|
||||||
|
DB_USERNAME: root
|
||||||
|
DB_PASSWORD: ninja
|
||||||
|
DB_HOST: '127.0.0.1'
|
||||||
|
BROADCAST_DRIVER: log
|
||||||
|
CACHE_DRIVER: file
|
||||||
|
QUEUE_CONNECTION: sync
|
||||||
|
SESSION_DRIVER: file
|
||||||
|
NINJA_ENVIRONMENT: hosted
|
||||||
|
MULTI_DB_ENABLED: false
|
||||||
|
NINJA_LICENSE: 123456
|
||||||
|
TRAVIS: true
|
||||||
|
MAIL_MAILER: log
|
||||||
|
|
||||||
|
services:
|
||||||
|
mariadb:
|
||||||
|
image: mariadb:latest
|
||||||
|
ports:
|
||||||
|
- 32768:3306
|
||||||
|
env:
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
|
MYSQL_USER: ninja
|
||||||
|
MYSQL_PASSWORD: ninja
|
||||||
|
MYSQL_DATABASE: ninja
|
||||||
|
MYSQL_ROOT_PASSWORD: ninja
|
||||||
|
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Add hosts to /etc/hosts
|
||||||
|
run: |
|
||||||
|
sudo echo "127.0.0.1 ninja.test" | sudo tee -a /etc/hosts
|
||||||
|
|
||||||
|
- name: Start mysql service
|
||||||
|
run: |
|
||||||
|
sudo systemctl start mysql.service
|
||||||
|
- name: Verify MariaDB connection
|
||||||
|
env:
|
||||||
|
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
|
||||||
|
DB_PORT1: ${{ job.services.mariadb.ports[3306] }}
|
||||||
|
|
||||||
|
run: |
|
||||||
|
while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php-versions }}
|
||||||
|
extensions: mysql, mysqlnd, sqlite3, bcmath, gmp, gd, curl, zip, openssl, mbstring, xml
|
||||||
|
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
ref: v5-develop
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Copy .env
|
||||||
|
run: |
|
||||||
|
cp .env.ci .env
|
||||||
|
- name: Install composer dependencies
|
||||||
|
run: |
|
||||||
|
composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
composer install
|
||||||
|
- name: Prepare Laravel Application
|
||||||
|
run: |
|
||||||
|
php artisan key:generate
|
||||||
|
php artisan optimize
|
||||||
|
php artisan cache:clear
|
||||||
|
php artisan config:cache
|
||||||
|
- name: Create DB and schemas
|
||||||
|
run: |
|
||||||
|
mkdir -p database
|
||||||
|
touch database/database.sqlite
|
||||||
|
- name: Migrate Database
|
||||||
|
run: |
|
||||||
|
php artisan migrate:fresh --seed --force && php artisan db:seed --force
|
||||||
|
- name: Prepare JS/CSS assets
|
||||||
|
run: |
|
||||||
|
npm i
|
||||||
|
npm run production
|
||||||
|
- name: Run Testsuite
|
||||||
|
run: |
|
||||||
|
cat .env
|
||||||
|
vendor/bin/snappdf download
|
||||||
|
run: ./tests/ci
|
||||||
|
env:
|
||||||
|
DB_PORT: ${{ job.services.mysql.ports[3306] }}
|
||||||
|
PHP_CS_FIXER_IGNORE_ENV: true
|
||||||
|
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
|
||||||
|
# Use the index from matrix as an environment variable
|
||||||
|
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
|
49
tests/ci
Executable file
49
tests/ci
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This script assumes you're in a Laravel project that has access
|
||||||
|
* to the Str, Collection and Symfony's Process class.
|
||||||
|
*/
|
||||||
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists PHPunit tests in the following format:
|
||||||
|
* - Tests\Support\UuidTest::it_can_create_a_uuid_from_a_string
|
||||||
|
* - Tests\Support\UuidTest::it_can_not_create_a_uuid_from_null
|
||||||
|
* - ...
|
||||||
|
*/
|
||||||
|
$process = new \Symfony\Component\Process\Process([__DIR__ . '/vendor/bin/phpunit', '--list-tests']);
|
||||||
|
$process->mustRun();
|
||||||
|
|
||||||
|
$tests = \Illuminate\Support\Str::of($process->getOutput())
|
||||||
|
->explode("\n") // Break the output from new lines into an array
|
||||||
|
->filter(fn (string $test) => str_contains($test, ' - ')) // Only lines with " - "
|
||||||
|
->map(fn (string $test) => addslashes(
|
||||||
|
\Illuminate\Support\Str::of($test)
|
||||||
|
->replace('- ', '') // Strip the "- "
|
||||||
|
->trim()
|
||||||
|
->explode('::') // Only the class, not the method
|
||||||
|
->get(0)
|
||||||
|
))
|
||||||
|
->filter(fn (string $test) => !empty($test)) // Make sure there are no empty lines
|
||||||
|
->unique() // We only need unique classes
|
||||||
|
->split((int) getenv('CI_NODE_TOTAL')) // Split it into equally sized chunks
|
||||||
|
->get((int) getenv('CI_NODE_INDEX')); // Get the index we need for this instance
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run phpunit with a filter:
|
||||||
|
* phpunit --filter 'TestClass|AnotherTestClass|...'
|
||||||
|
*/
|
||||||
|
$process = new \Symfony\Component\Process\Process(['./vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null);
|
||||||
|
$process->start();
|
||||||
|
|
||||||
|
// Make sure we have live data output
|
||||||
|
foreach ($process as $type => $data) {
|
||||||
|
echo $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$process->wait();
|
||||||
|
|
||||||
|
// Exit using PHPUnit's exit code to have the action pass/fail
|
||||||
|
exit($process->getExitCode());
|
Loading…
x
Reference in New Issue
Block a user