From 3c054e975400dc9abc6da1a8fae643f9f03b4bf0 Mon Sep 17 00:00:00 2001 From: lotyp Date: Sun, 26 May 2024 15:45:12 +0300 Subject: [PATCH 1/2] ci: add code coverage --- .github/workflows/testing.yml | 76 +++++++++++++++++++++++++++++++++++ composer.json | 4 +- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000..d19b73d9 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,76 @@ +--- + +name: ๐Ÿงช Unit testing + +on: # yamllint disable-line rule:truthy + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + code-coverage: + timeout-minutes: 4 + runs-on: ${{ matrix.os }} + concurrency: + cancel-in-progress: true + group: code-coverage-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}-${{ matrix.dependencies }} + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + php-version: + - '8.2' + dependencies: + - locked + steps: + - name: ๐Ÿ“ฆ Check out the codebase + uses: actions/checkout@v4.1.5 + + - name: ๐Ÿ› ๏ธ Setup PHP + uses: shivammathur/setup-php@2.30.4 + with: + php-version: ${{ matrix.php-version }} + extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql pdo_sqlite + ini-values: error_reporting=E_ALL + coverage: xdebug + + - name: ๐Ÿ› ๏ธ Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: ๐Ÿค– Validate composer.json and composer.lock + run: composer validate --ansi --strict + + - name: ๐Ÿ” Get composer cache directory + uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0 + + - name: โ™ป๏ธ Restore cached dependencies installed with composer + uses: actions/cache@v4.0.2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} + restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- + + - name: ๐Ÿ“ฅ Install "${{ matrix.dependencies }}" dependencies + uses: wayofdev/gh-actions/actions/composer/install@v3.1.0 + with: + dependencies: ${{ matrix.dependencies }} + + - name: ๐Ÿงช Collect code coverage with Xdebug and pestphp/pest + env: + XDEBUG_MODE: coverage + DB_CONNECTION: sqlite + DB_DATABASE: ':memory:' + run: composer test:cc + + - name: ๐Ÿ“ค Upload code coverage report to Codecov + uses: codecov/codecov-action@v4.3.0 + with: + files: .build/phpunit/logs/clover.xml + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true diff --git a/composer.json b/composer.json index 6501e0e4..343cdc50 100644 --- a/composer.json +++ b/composer.json @@ -159,11 +159,11 @@ "stan:ci": "php vendor/bin/phpstan analyse --memory-limit=2G --error-format=github", "test": [ "@putenv XDEBUG_MODE=coverage", - "php vendor/bin/pest" + "php vendor/bin/pest --color=always" ], "test:cc": [ "@putenv XDEBUG_MODE=coverage", - "php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml" + "php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always" ] } } From bb3ab21f5214dfd121d18ebfe225a8c21162f2ed Mon Sep 17 00:00:00 2001 From: lotyp Date: Sun, 26 May 2024 15:49:12 +0300 Subject: [PATCH 2/2] ci: fix typo in setup php --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d19b73d9..620b76cb 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -34,7 +34,7 @@ jobs: uses: shivammathur/setup-php@2.30.4 with: php-version: ${{ matrix.php-version }} - extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql pdo_sqlite + extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, pdo_sqlite ini-values: error_reporting=E_ALL coverage: xdebug