From 7abb1f99b810d1249f376e5b870493ec63fc9f41 Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 4 Oct 2023 16:59:45 +0200 Subject: [PATCH] Split GH workflow for tests and Code-style checks --- .github/workflows/ci.yml | 90 +++++++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 49 -------------------- .php-cs-fixer.dist.php | 5 +-- composer.json | 6 +++ 4 files changed, 98 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..9b6dc674 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,90 @@ +name: tests + +on: + push: + pull_request: + +jobs: + run_tests: + runs-on: ubuntu-20.04 + + strategy: + matrix: + php: ['8.0', '8.1', '8.2'] + stability: ['prefer-lowest', 'prefer-stable'] + + name: PHP Tests ${{ matrix.php }} - ${{ matrix.stability }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, gd + tools: composer + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-progress + + - name: Execute tests in default environment + run: vendor/bin/phpunit --verbose + + - name: Execute tests in hardened environment + run: php -d allow_url_fopen=0 -d memory_limit=256M -d register_globals=0 vendor/bin/phpunit --verbose + + run_code_checks: + runs-on: ubuntu-20.04 + name: PHP Code-Checks + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + extensions: dom, curl, libxml, mbstring, zip, bcmath, gd + tools: composer + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Check composer files + run: composer validate --strict + + - name: Check coding standard + run: composer cs:diff + + - name: Static analysis + run: composer phpstan diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 2a0d638c..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: tests - -on: - push: - pull_request: - -jobs: - linux_tests: - runs-on: ubuntu-20.04 - - strategy: - matrix: - php: ['8.0', '8.1', '8.2'] - stability: ['prefer-lowest', 'prefer-stable'] - - name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, gd - tools: composer:v2 - coverage: none - - - name: Check for syntax errors in PHP files - run: find ./ -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l - - - name: Check composer files - run: composer validate --strict - - - name: Install dependencies - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - - name: Execute tests in default environment - run: vendor/bin/phpunit --verbose - - - name: Execute tests in hardened environment - run: php -d allow_url_fopen=0 -d memory_limit=256M -d register_globals=0 vendor/bin/phpunit --verbose - - - name: Check coding standard - run: vendor/bin/php-cs-fixer --no-interaction --dry-run --diff -v fix src/ - - - name: Static analysis - run: vendor/bin/phpstan analyse diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2c858358..2cdaaf9c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,12 +1,11 @@ in(__DIR__) + ->in(__DIR__.'/src') ; return (new PhpCsFixer\Config()) ->setRules([ '@PSR2' => true ]) - ->setFinder($finder) - ; + ->setFinder($finder); diff --git a/composer.json b/composer.json index 1ec66f81..0baccf2a 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,12 @@ "setasign/fpdf": "^1.8.2", "tecnickcom/tcpdf": "^6.3.2" }, + "scripts": { + "cs:fix": "vendor/bin/php-cs-fixer fix --verbose", + "cs:diff": "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose", + "phpstan": "vendor/bin/phpstan analyse", + "phpunit": "vendor/bin/phpunit --verbose" + }, "conflict": { "khanamiryan/qrcode-detector-decoder": "1.0.6" },