From f7f55ae90608f3be4b982006af65600e27258cb9 Mon Sep 17 00:00:00 2001 From: Alexandre Tranchant Date: Fri, 5 Apr 2024 10:24:55 +0200 Subject: [PATCH] CI Added --- .github/workflows/ci.yml | 118 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2ca0f8e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,118 @@ +name: CI + +on: + push: + pull_request: + branches: + - main + - develop + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-version: ['8.1', '8.2', '8.3'] + + name: PHP ${{ matrix.php-version }} + env: + HAS_CC_SECRET: ${{secrets.CC_TEST_REPORTER_ID != '' }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Validate composer.json + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php + + - name: Set up PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + coverage: pcov + tools: composer:v2 + + - name: Install dependencies + run: composer --prefer-source update + + - name: Run test with coverage + uses: paambaati/codeclimate-action@v5.0.0 + if: env.HAS_CC_SECRET == 'true' + env: + CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} + with: + coverageCommand: vendor/bin/phpunit --coverage-clover=.phpunit.cache/clover-${{ matrix.php-version }}.xml + coverageLocations: ${{github.workspace}}/.phpunit.cache/clover*.xml:clover + + - name: Run tests for forks + if: env.HAS_CC_SECRET != 'true' + run: vendor/bin/phpunit + + ## Quality checks + ## PHP-CS-Fixer + - name: Cache Composer PHP-CS-FIXER packages + if: ${{ matrix.php-version == '8.3' }} + id: composer-phpcsfixer-cache + uses: actions/cache@v4 + with: + path: quality/php-cs-fixer/vendor/ + key: ${{ runner.os }}-phpcsfixer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-phpcsfixer- + + - name: Install PHP-CS-Fixer + if: ${{ matrix.php-version == '8.3' }} + run: composer update --working-dir=quality/php-cs-fixer + + - name: Run PHP-CS-Fixer + if: ${{ matrix.php-version == '8.3' }} + run: ./quality/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=quality/php-cs-fixer/.php-cs-fixer.php --dry-run --allow-risky=yes + + ## PHP-MESS-DETECTOR + - name: Cache Composer PHP-MESS-DETECTOR packages + if: ${{ matrix.php-version == '8.3' }} + id: composer-phpmd-cache + uses: actions/cache@v4 + with: + path: quality/php-cs-fixer/vendor/ + key: ${{ runner.os }}-phpmd-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-phpmd- + - name: Install PHP-MESS-DETECTOR + if: ${{ matrix.php-version == '8.3' }} + run: composer update --working-dir=quality/php-mess-detector + - name: Run PHP-MESS-DETECTOR on lib directory + if: ${{ matrix.php-version == '8.3' }} + run: ./quality/php-mess-detector/vendor/bin/phpmd lib text quality/php-mess-detector/ruleset.xml + - name: Run PHP-MESS-DETECTOR on tests directory + if: ${{ matrix.php-version == '8.3' }} + run: ./quality/php-mess-detector/vendor/bin/phpmd tests text quality/php-mess-detector/test-ruleset.xml + + ## PHP-STAN + - name: Cache Composer PHP-STAN packages + if: ${{ matrix.php-version == '8.3' }} + id: composer-php-stan-cache + uses: actions/cache@v4 + with: + path: quality/php-cs-fixer/vendor/ + key: ${{ runner.os }}-php-stan-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-stan- + - name: Install PHP-STAN + if: ${{ matrix.php-version == '8.3' }} + run: composer update --working-dir=quality/php-stan + - name: Run PHP-STAN + if: ${{ matrix.php-version == '8.3' }} + run: ./quality/php-stan/vendor/bin/phpstan analyse --configuration=quality/php-stan/php-stan.neon lib tests --error-format=table --no-progress --no-interaction --no-ansi --level=9 --memory-limit=256M -v