Merge pull request #1507 from acelaya-forks/feature/improve-ci-uploads

Feature/improve ci uploads
This commit is contained in:
Alejandro Celaya 2022-08-12 20:52:50 +02:00 committed by GitHub
commit be82204df2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 42 deletions

View File

@ -16,6 +16,7 @@ jobs:
php-version: [ '8.1' ] php-version: [ '8.1' ]
env: env:
LC_ALL: C LC_ALL: C
extensions: openswoole-4.11.1, pdo_sqlsrv-5.10.1
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -25,12 +26,25 @@ jobs:
- name: Start database server - name: Start database server
if: ${{ inputs.platform != 'sqlite:ci' }} if: ${{ inputs.platform != 'sqlite:ci' }}
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_${{ inputs.platform }} run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_${{ inputs.platform }}
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: db-tests-extensions-${{ inputs.platform }}
- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: Use PHP - name: Use PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
tools: composer tools: composer
extensions: openswoole-4.11.1, pdo_sqlsrv-5.10.1 extensions: ${{ env.extensions }}
coverage: pcov coverage: pcov
ini-values: pcov.directory=module ini-values: pcov.directory=module
- name: Install dependencies - name: Install dependencies
@ -41,7 +55,7 @@ jobs:
- name: Run tests - name: Run tests
run: composer test:db:${{ inputs.platform }} run: composer test:db:${{ inputs.platform }}
- name: Upload code coverage - name: Upload code coverage
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
if: ${{ matrix.php-version == '8.1' && inputs.platform == 'sqlite:ci' }} if: ${{ matrix.php-version == '8.1' && inputs.platform == 'sqlite:ci' }}
with: with:
name: coverage-db name: coverage-db

View File

@ -14,20 +14,35 @@ jobs:
strategy: strategy:
matrix: matrix:
php-version: [ '8.1' ] php-version: [ '8.1' ]
env:
extensions: openswoole-4.11.1
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: mutation-tests-extensions-${{ inputs.test-group }}
- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: Use PHP - name: Use PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
tools: composer tools: composer
extensions: openswoole-4.11.1 extensions: ${{ env.extensions }}
coverage: pcov coverage: pcov
ini-values: pcov.directory=module ini-values: pcov.directory=module
- name: Install dependencies - name: Install dependencies
run: composer install --no-interaction --prefer-dist run: composer install --no-interaction --prefer-dist
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v3
with: with:
path: build path: build
- if: ${{ inputs.test-group == 'unit' }} - if: ${{ inputs.test-group == 'unit' }}

View File

@ -14,6 +14,8 @@ jobs:
strategy: strategy:
matrix: matrix:
php-version: ['8.1'] php-version: ['8.1']
env:
extensions: openswoole-4.11.1
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -23,18 +25,31 @@ jobs:
- name: Start maria database server - name: Start maria database server
if: ${{ inputs.test-group == 'cli' }} if: ${{ inputs.test-group == 'cli' }}
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_maria run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_maria
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: tests-extensions-${{ inputs.test-group }}
- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: Use PHP - name: Use PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
tools: composer tools: composer
extensions: openswoole-4.11.1 extensions: ${{ env.extensions }}
coverage: pcov coverage: pcov
ini-values: pcov.directory=module ini-values: pcov.directory=module
- name: Install dependencies - name: Install dependencies
run: composer install --no-interaction --prefer-dist run: composer install --no-interaction --prefer-dist
- run: composer test:${{ inputs.test-group }}:ci - run: composer test:${{ inputs.test-group }}:ci
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
if: ${{ matrix.php-version == '8.1' }} if: ${{ matrix.php-version == '8.1' }}
with: with:
name: coverage-${{ inputs.test-group }} name: coverage-${{ inputs.test-group }}

View File

@ -15,15 +15,30 @@ jobs:
matrix: matrix:
php-version: ['8.1'] php-version: ['8.1']
command: ['cs', 'stan', 'swagger:validate'] command: ['cs', 'stan', 'swagger:validate']
env:
extensions: openswoole-4.11.1
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: tests-extensions-${{ matrix.command }}
- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: Use PHP - name: Use PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
tools: composer tools: composer
extensions: openswoole-4.11.1 extensions: ${{ env.extensions }}
coverage: none coverage: none
- name: Install dependencies - name: Install dependencies
run: composer install --no-interaction --prefer-dist run: composer install --no-interaction --prefer-dist
@ -116,7 +131,7 @@ jobs:
php-version: ${{ matrix.php-version }} php-version: ${{ matrix.php-version }}
coverage: pcov coverage: pcov
ini-values: pcov.directory=module ini-values: pcov.directory=module
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v3
with: with:
path: build path: build
- run: mv build/coverage-unit/coverage-unit.cov build/coverage-unit.cov - run: mv build/coverage-unit/coverage-unit.cov build/coverage-unit.cov

View File

@ -25,7 +25,7 @@ jobs:
run: ./build.sh ${GITHUB_REF#refs/tags/v} run: ./build.sh ${GITHUB_REF#refs/tags/v}
- if: ${{ matrix.swoole == 'no' }} - if: ${{ matrix.swoole == 'no' }}
run: ./build.sh ${GITHUB_REF#refs/tags/v} --no-swoole run: ./build.sh ${GITHUB_REF#refs/tags/v} --no-swoole
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
with: with:
name: dist-files-${{ matrix.php-version }}-${{ matrix.swoole }} name: dist-files-${{ matrix.php-version }}-${{ matrix.swoole }}
path: build path: build
@ -36,7 +36,7 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v3
with: with:
path: build path: build
- name: Publish release with assets - name: Publish release with assets

View File

@ -123,8 +123,7 @@ Depending on the kind of contribution, maybe not all kinds of tests are needed,
* Run `./indocker composer test:api` to run API E2E tests. For these, the Postgres database engine is used. * Run `./indocker composer test:api` to run API E2E tests. For these, the Postgres database engine is used.
* Run `./indocker composer test:cli` to run CLI E2E tests. For these, the Maria DB database engine is used. * Run `./indocker composer test:cli` to run CLI E2E tests. For these, the Maria DB database engine is used.
* Run `./indocker composer infect:test` to run both unit and database tests (over sqlite) and then apply mutations to them with [infection](https://infection.github.io/). * Run `./indocker composer infect:test` to run both unit and database tests (over sqlite) and then apply mutations to them with [infection](https://infection.github.io/).
* Run `./indocker composer ci` to run all previous commands together. This command is run during the project's continuous integration. * Run `./indocker composer ci` to run all previous commands together, parallelizing non-conflicting tasks as much as possible.
* Run `./indocker composer ci:parallel` to do the same as in previous case, but parallelizing non-conflicting tasks as much as possible.
## Pull request process ## Pull request process
@ -136,7 +135,7 @@ Once everything is clear, to provide a pull request to this project, you should
The base branch should always be `develop`, and the target branch for the pull request should also be `develop`. The base branch should always be `develop`, and the target branch for the pull request should also be `develop`.
Before your branch can be merged, all the checks described in [Running code checks](#running-code-checks) have to be passing. You can verify that manually by running `./indocker composer ci:parallel`, or wait for the build to be run automatically after the pull request is created. Before your branch can be merged, all the checks described in [Running code checks](#running-code-checks) have to be passing. You can verify that manually by running `./indocker composer ci`, or wait for the build to be run automatically after the pull request is created.
## Architectural Decision Records ## Architectural Decision Records

View File

@ -99,13 +99,6 @@
}, },
"scripts": { "scripts": {
"ci": [ "ci": [
"@cs",
"@stan",
"@swagger:validate",
"@test:ci",
"@infect:ci"
],
"ci:parallel": [
"@parallel cs stan swagger:validate test:unit:ci test:db:sqlite:ci test:db:mysql test:db:maria test:db:postgres test:db:ms", "@parallel cs stan swagger:validate test:unit:ci test:db:sqlite:ci test:db:mysql test:db:maria test:db:postgres test:db:ms",
"@parallel infect:test:api infect:test:cli infect:ci:unit infect:ci:db" "@parallel infect:test:api infect:test:cli infect:ci:unit infect:ci:db"
], ],
@ -113,19 +106,11 @@
"cs:fix": "phpcbf", "cs:fix": "phpcbf",
"stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/config config docker/config data/migrations --level=8", "stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/config config docker/config data/migrations --level=8",
"test": [ "test": [
"@test:unit", "@parallel test:unit test:db",
"@test:db", "@parallel test:api test:cli"
"@test:api",
"@test:cli"
], ],
"test:ci": [ "test:unit": "@php vendor/bin/phpunit --order-by=random --colors=always --testdox",
"@test:unit:ci", "test:unit:ci": "@test:unit --coverage-php=build/coverage-unit.cov --coverage-xml=build/coverage-unit/coverage-xml --log-junit=build/coverage-unit/junit.xml",
"@test:db",
"@test:api:ci",
"@test:cli:ci"
],
"test:unit": "@php vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox",
"test:unit:ci": "@test:unit --coverage-xml=build/coverage-unit/coverage-xml --log-junit=build/coverage-unit/junit.xml",
"test:unit:pretty": "@test:unit --coverage-html build/coverage-unit/coverage-html", "test:unit:pretty": "@test:unit --coverage-html build/coverage-unit/coverage-html",
"test:db": "@parallel test:db:sqlite:ci test:db:mysql test:db:maria test:db:postgres test:db:ms", "test:db": "@parallel test:db:sqlite:ci test:db:mysql test:db:maria test:db:postgres test:db:ms",
"test:db:sqlite": "APP_ENV=test php vendor/bin/phpunit --order-by=random --colors=always --testdox -c phpunit-db.xml", "test:db:sqlite": "APP_ENV=test php vendor/bin/phpunit --order-by=random --colors=always --testdox -c phpunit-db.xml",
@ -136,8 +121,10 @@
"test:db:ms": "DB_DRIVER=mssql composer test:db:sqlite", "test:db:ms": "DB_DRIVER=mssql composer test:db:sqlite",
"test:api": "bin/test/run-api-tests.sh", "test:api": "bin/test/run-api-tests.sh",
"test:api:ci": "GENERATE_COVERAGE=yes composer test:api", "test:api:ci": "GENERATE_COVERAGE=yes composer test:api",
"test:cli": "APP_ENV=test DB_DRIVER=maria TEST_ENV=cli php vendor/bin/phpunit --order-by=random --colors=always --testdox -c phpunit-cli.xml", "test:api:pretty": "GENERATE_COVERAGE=pretty composer test:api",
"test:cli:ci": "GENERATE_COVERAGE=yes composer test:cli -- --log-junit=build/coverage-cli/junit.xml", "test:cli": "APP_ENV=test DB_DRIVER=maria TEST_ENV=cli php vendor/bin/phpunit --order-by=random --colors=always --testdox -c phpunit-cli.xml --log-junit=build/coverage-cli/junit.xml",
"test:cli:ci": "GENERATE_COVERAGE=yes composer test:cli",
"test:cli:pretty": "GENERATE_COVERAGE=pretty composer test:cli",
"infect:ci:base": "infection --threads=4 --log-verbosity=default --only-covered --only-covering-test-cases --skip-initial-tests", "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=84", "infect:ci:unit": "@infect:ci:base --coverage=build/coverage-unit --min-msi=84",
"infect:ci:db": "@infect:ci:base --coverage=build/coverage-db --min-msi=95 --configuration=infection-db.json", "infect:ci:db": "@infect:ci:base --coverage=build/coverage-db --min-msi=95 --configuration=infection-db.json",
@ -166,12 +153,10 @@
}, },
"scripts-descriptions": { "scripts-descriptions": {
"ci": "<fg=blue;options=bold>Alias for \"cs\", \"stan\", \"swagger:validate\", \"test:ci\" and \"infect:ci\"</>", "ci": "<fg=blue;options=bold>Alias for \"cs\", \"stan\", \"swagger:validate\", \"test:ci\" and \"infect:ci\"</>",
"ci:parallel": "<fg=blue;options=bold>Same as \"ci\", but parallelizing tasks as much as possible</>",
"cs": "<fg=blue;options=bold>Checks coding styles</>", "cs": "<fg=blue;options=bold>Checks coding styles</>",
"cs:fix": "<fg=blue;options=bold>Fixes coding styles, when possible</>", "cs:fix": "<fg=blue;options=bold>Fixes coding styles, when possible</>",
"stan": "<fg=blue;options=bold>Inspects code with phpstan</>", "stan": "<fg=blue;options=bold>Inspects code with phpstan</>",
"test": "<fg=blue;options=bold>Runs all test suites</>", "test": "<fg=blue;options=bold>Runs all test suites</>",
"test:ci": "<fg=blue;options=bold>Runs all test suites, generating all needed reports and logs for CI envs</>",
"test:unit": "<fg=blue;options=bold>Runs unit test suites</>", "test:unit": "<fg=blue;options=bold>Runs unit test suites</>",
"test:unit:ci": "<fg=blue;options=bold>Runs unit test suites, generating all needed reports and logs for CI envs</>", "test:unit:ci": "<fg=blue;options=bold>Runs unit test suites, generating all needed reports and logs for CI envs</>",
"test:unit:pretty": "<fg=blue;options=bold>Runs unit test suites and generates an HTML code coverage report</>", "test:unit:pretty": "<fg=blue;options=bold>Runs unit test suites and generates an HTML code coverage report</>",
@ -183,7 +168,11 @@
"test:db:postgres": "<fg=blue;options=bold>Runs database test suites on a PostgreSQL database</>", "test:db:postgres": "<fg=blue;options=bold>Runs database test suites on a PostgreSQL database</>",
"test:db:ms": "<fg=blue;options=bold>Runs database test suites on a Microsoft SQL Server database</>", "test:db:ms": "<fg=blue;options=bold>Runs database test suites on a Microsoft SQL Server database</>",
"test:api": "<fg=blue;options=bold>Runs API test suites</>", "test:api": "<fg=blue;options=bold>Runs API test suites</>",
"test:api:ci": "<fg=blue;options=bold>Runs API test suites, and generates code coverage reports</>", "test:api:ci": "<fg=blue;options=bold>Runs API test suites, and generates code coverage for CI</>",
"test:api:pretty": "<fg=blue;options=bold>Runs API test suites, and generates code coverage in HTML format</>",
"test:cli": "<fg=blue;options=bold>Runs CLI test suites</>",
"test:cli:ci": "<fg=blue;options=bold>Runs CLI test suites, and generates code coverage for CI</>",
"test:cli:pretty": "<fg=blue;options=bold>Runs CLI test suites, and generates code coverage in HTML format</>",
"infect:ci": "<fg=blue;options=bold>Checks unit and db tests quality applying mutation testing with existing reports and logs</>", "infect:ci": "<fg=blue;options=bold>Checks unit and db tests quality applying mutation testing with existing reports and logs</>",
"infect:ci:unit": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing with existing reports and logs</>", "infect:ci:unit": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing with existing reports and logs</>",
"infect:ci:db": "<fg=blue;options=bold>Checks db tests quality applying mutation testing with existing reports and logs</>", "infect:ci:db": "<fg=blue;options=bold>Checks db tests quality applying mutation testing with existing reports and logs</>",

View File

@ -28,6 +28,7 @@ use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use function file_exists; use function file_exists;
use function Functional\contains;
use function Laminas\Stratigility\middleware; use function Laminas\Stratigility\middleware;
use function Shlinkio\Shlink\Config\env; use function Shlinkio\Shlink\Config\env;
use function sprintf; use function sprintf;
@ -39,7 +40,8 @@ use const ShlinkioTest\Shlink\SWOOLE_TESTING_PORT;
$isApiTest = env('TEST_ENV') === 'api'; $isApiTest = env('TEST_ENV') === 'api';
$isCliTest = env('TEST_ENV') === 'cli'; $isCliTest = env('TEST_ENV') === 'cli';
$isE2eTest = $isApiTest || $isCliTest; $isE2eTest = $isApiTest || $isCliTest;
$generateCoverage = env('GENERATE_COVERAGE') === 'yes'; $coverageType = env('GENERATE_COVERAGE');
$generateCoverage = contains(['yes', 'pretty'], $coverageType);
$coverage = null; $coverage = null;
if ($isE2eTest && $generateCoverage) { if ($isE2eTest && $generateCoverage) {
@ -52,7 +54,7 @@ if ($isE2eTest && $generateCoverage) {
/** /**
* @param 'api'|'cli' $type * @param 'api'|'cli' $type
*/ */
$exportCoverage = static function (string $type = 'api') use (&$coverage): void { $exportCoverage = static function (string $type = 'api') use (&$coverage, $coverageType): void {
if ($coverage === null) { if ($coverage === null) {
return; return;
} }
@ -66,9 +68,12 @@ $exportCoverage = static function (string $type = 'api') use (&$coverage): void
$coverage->merge(require $covPath); $coverage->merge(require $covPath);
} }
(new PHP())->process($coverage, $covPath); if ($coverageType === 'pretty') {
(new Xml(Version::getVersionString()))->process($coverage, $basePath . '/coverage-xml'); (new Html())->process($coverage, $basePath . '/coverage-html');
(new Html())->process($coverage, $basePath . '/coverage-html'); } else {
(new PHP())->process($coverage, $covPath);
(new Xml(Version::getVersionString()))->process($coverage, $basePath . '/coverage-xml');
}
}; };
$buildDbConnection = static function (): array { $buildDbConnection = static function (): array {