Skip to content

Commit

Permalink
Unified jobs in ci pipeline as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Dec 11, 2021
1 parent 5371524 commit de2d87a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 140 deletions.
156 changes: 29 additions & 127 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,18 @@ jobs:
- run: composer install --no-interaction --prefer-dist
- run: composer ${{ matrix.command }}

unit-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
extensions: openswoole-4.8.1
coverage: pcov
ini-values: pcov.directory=module
- run: composer install --no-interaction --prefer-dist
- run: composer test:unit:ci
- uses: actions/upload-artifact@v2
if: ${{ matrix.php-version == '8.0' }}
with:
name: coverage-unit
path: |
build/coverage-unit
build/coverage-unit.cov
db-tests-sqlite:
tests:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
test-group: ['unit', 'api']
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Start database server
if: ${{ matrix.test-group == 'api' }}
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_postgres
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -70,111 +48,32 @@ jobs:
coverage: pcov
ini-values: pcov.directory=module
- run: composer install --no-interaction --prefer-dist
- run: composer test:db:sqlite:ci
- run: composer test:${{ matrix.test-group }}:ci
- uses: actions/upload-artifact@v2
if: ${{ matrix.php-version == '8.0' }}
with:
name: coverage-db
name: coverage-${{ matrix.test-group }}
path: |
build/coverage-db
build/coverage-db.cov
db-tests-mysql:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Start database server
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
extensions: openswoole-4.8.1
coverage: none
- run: composer install --no-interaction --prefer-dist
- run: composer test:db:mysql

db-tests-maria:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Start database server
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_maria
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
extensions: openswoole-4.8.1
coverage: none
- run: composer install --no-interaction --prefer-dist
- run: composer test:db:maria

db-tests-postgres:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Start database server
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_postgres
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
extensions: openswoole-4.8.1
coverage: none
- run: composer install --no-interaction --prefer-dist
- run: composer test:db:postgres
build/coverage-${{ matrix.test-group }}
build/coverage-${{ matrix.test-group }}.cov
db-tests-ms:
db-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
platform: ['sqlite:ci', 'mysql', 'maria', 'postgres', 'ms']
env:
LC_ALL: C
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install MSSQL ODBC
if: ${{ matrix.platform == 'ms' }}
run: sudo ./data/infra/ci/install-ms-odbc.sh
- name: Start database server
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_ms
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
extensions: openswoole-4.8.1, pdo_sqlsrv-5.10.0beta2
coverage: none
- run: composer install --no-interaction --prefer-dist
- name: Create test database
run: docker-compose exec -T shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;"
- run: composer test:db:ms

api-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: ['8.0', '8.1']
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Start database server
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_postgres
if: ${{ matrix.platform != 'sqlite:ci' }}
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_${{ matrix.platform }}
- name: Use PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -184,20 +83,24 @@ jobs:
coverage: pcov
ini-values: pcov.directory=module
- run: composer install --no-interaction --prefer-dist
- run: bin/test/run-api-tests.sh
- uses: actions/upload-artifact@v2
if: ${{ matrix.php-version == '8.0' }}
- name: Create test database
if: ${{ matrix.platform == 'ms' }}
run: docker-compose exec -T shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;"
- name: Run tests
run: composer test:db:${{ matrix.platform }}
- name: Upload code coverage
uses: actions/upload-artifact@v2
if: ${{ matrix.php-version == '8.0' && matrix.platform == 'sqlite:ci' }}
with:
name: coverage-api
name: coverage-db
path: |
build/coverage-api
build/coverage-api.cov
build/coverage-db
build/coverage-db.cov
mutation-tests:
needs:
- unit-tests
- db-tests-sqlite
- api-tests
- tests
- db-tests
runs-on: ubuntu-20.04
strategy:
matrix:
Expand Down Expand Up @@ -227,9 +130,8 @@ jobs:

upload-coverage:
needs:
- unit-tests
- db-tests-sqlite
- api-tests
- tests
- db-tests
runs-on: ubuntu-20.04
strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions bin/test/run-api-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export APP_ENV=test
export DB_DRIVER=postgres
export TEST_ENV=api
export GENERATE_COVERAGE=${GENERATE_COVERAGE:-"no"}

rm -rf data/log/api-tests

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"test:db:postgres": "DB_DRIVER=postgres composer test:db:sqlite",
"test:db:ms": "DB_DRIVER=mssql composer test:db:sqlite",
"test:api": "bin/test/run-api-tests.sh",
"test:api:ci": "GENERATE_COVERAGE=yes composer test:api",
"infect:ci:base": "infection --threads=4 --log-verbosity=default --only-covered --only-covering-test-cases --skip-initial-tests",
"infect:ci:unit": "@infect:ci:base --coverage=build/coverage-unit --min-msi=83",
"infect:ci:db": "@infect:ci:base --coverage=build/coverage-db --min-msi=95 --configuration=infection-db.json",
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/entity-manager.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ return [
'user' => 'root',
'password' => 'root',
'driver' => 'pdo_mysql',
'host' => 'shlink_db',
'host' => 'shlink_db_mysql',
'dbname' => 'shlink',
'charset' => 'utf8',
],
Expand Down
7 changes: 3 additions & 4 deletions config/test/test_config.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
use const ShlinkioTest\Shlink\SWOOLE_TESTING_PORT;

$isApiTest = env('TEST_ENV') === 'api';
if ($isApiTest) {
$generateCoverage = env('GENERATE_COVERAGE') === 'yes';
if ($isApiTest && $generateCoverage) {
$filter = new Filter();
$filter->includeDirectory(__DIR__ . '/../../module/Core/src');
$filter->includeDirectory(__DIR__ . '/../../module/Rest/src');
Expand All @@ -40,7 +41,6 @@
$buildDbConnection = static function (): array {
$driver = env('DB_DRIVER', 'sqlite');
$isCi = env('CI', false);
$getMysqlHost = static fn (string $driver) => sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria');
$getCiMysqlPort = static fn (string $driver) => $driver === 'mysql' ? '3307' : '3308';

return match ($driver) {
Expand All @@ -66,7 +66,7 @@
],
default => [ // mysql and maria
'driver' => 'pdo_mysql',
'host' => $isCi ? '127.0.0.1' : $getMysqlHost($driver),
'host' => $isCi ? '127.0.0.1' : sprintf('shlink_db_%s', $driver),
'port' => $isCi ? $getCiMysqlPort($driver) : '3306',
'user' => 'root',
'password' => 'root',
Expand Down Expand Up @@ -124,7 +124,6 @@
if ($coverage) { // @phpstan-ignore-line
$basePath = __DIR__ . '/../../build/coverage-api';

// TODO Generate these coverages dynamically based on CLI options
(new PHP())->process($coverage, $basePath . '.cov');
(new Xml(Version::getVersionString()))->process($coverage, $basePath . '/coverage-xml');
(new Html())->process($coverage, $basePath . '/coverage-html');
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'

services:
shlink_db:
shlink_db_mysql:
environment:
MYSQL_DATABASE: shlink_test

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.override.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro

shlink_db:
shlink_db_mysql:
user: 1000:1000
volumes:
- /etc/passwd:/etc/passwd:ro
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- ./:/home/shlink/www
- ./data/infra/php.ini:/usr/local/etc/php/php.ini
links:
- shlink_db
- shlink_db_mysql
- shlink_db_postgres
- shlink_db_maria
- shlink_db_ms
Expand Down Expand Up @@ -57,7 +57,7 @@ services:
- ./:/home/shlink
- ./data/infra/php.ini:/usr/local/etc/php/php.ini
links:
- shlink_db
- shlink_db_mysql
- shlink_db_postgres
- shlink_db_maria
- shlink_db_ms
Expand All @@ -69,8 +69,8 @@ services:
extra_hosts:
- 'host.docker.internal:host-gateway'

shlink_db:
container_name: shlink_db
shlink_db_mysql:
container_name: shlink_db_mysql
image: mysql:5.7
ports:
- "3307:3306"
Expand Down
4 changes: 2 additions & 2 deletions module/Core/test/Config/SimplifiedConfigParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function properlyMapsSimplifiedConfig(): void
'entity_manager' => [
'connection' => [
'driver' => 'mysql',
'host' => 'shlink_db',
'host' => 'shlink_db_mysql',
'port' => '3306',
],
],
Expand Down Expand Up @@ -78,7 +78,7 @@ public function properlyMapsSimplifiedConfig(): void
'entity_manager' => [
'connection' => [
'driver' => 'mysql',
'host' => 'shlink_db',
'host' => 'shlink_db_mysql',
'dbname' => 'shlink',
'user' => 'foo',
'password' => 'bar',
Expand Down

0 comments on commit de2d87a

Please sign in to comment.