Craft v5 #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| pull_request: | |
| branches: [ master, v2 ] | |
| push: | |
| branches: [ master, v2 ] | |
| jobs: | |
| # Craft 5.x tests (master branch) - PHP 8.2+ | |
| craft5-tests: | |
| if: github.ref == 'refs/heads/master' || github.base_ref == 'master' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| php: [8.2, 8.3] | |
| name: Craft 5.x - PHP ${{ matrix.php }} Tests | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv | |
| coverage: xdebug | |
| - name: Cache Composer packages | |
| id: composer-cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: vendor | |
| key: craft5-${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| craft5-${{ runner.os }}-php-${{ matrix.php }}- | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress --dev | |
| - name: Build Codeception | |
| run: vendor/bin/codecept build | |
| - name: Run unit tests | |
| run: vendor/bin/codecept run unit --coverage --coverage-xml | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v3 | |
| if: matrix.php == '8.2' | |
| with: | |
| files: ./tests/_output/coverage.xml | |
| fail_ci_if_error: false | |
| verbose: true | |
| - name: Generate coverage text report | |
| if: github.event_name == 'pull_request' && matrix.php == '8.2' | |
| id: coverage | |
| run: | | |
| # Run coverage and strip ANSI color codes | |
| raw_output=$(vendor/bin/codecept run unit --coverage-text --no-ansi 2>&1) | |
| # Debug: show the actual lines | |
| echo "Raw coverage lines:" | |
| echo "$raw_output" | grep -E "(Classes|Methods|Lines):" | |
| # Extract coverage percentages more reliably | |
| classes=$(echo "$raw_output" | grep "Classes:" | grep -o '[0-9]*\.[0-9]*%' | head -1 || echo "N/A") | |
| methods=$(echo "$raw_output" | grep "Methods:" | grep -o '[0-9]*\.[0-9]*%' | head -1 || echo "N/A") | |
| lines=$(echo "$raw_output" | grep "Lines:" | grep -o '[0-9]*\.[0-9]*%' | head -1 || echo "N/A") | |
| # Get test results | |
| test_result=$(echo "$raw_output" | grep "OK (" || echo "Tests failed") | |
| # Use simple variable assignment | |
| echo "classes=${classes:-N/A}" >> "$GITHUB_OUTPUT" | |
| echo "methods=${methods:-N/A}" >> "$GITHUB_OUTPUT" | |
| echo "lines=${lines:-N/A}" >> "$GITHUB_OUTPUT" | |
| echo "test-result=${test_result:-Tests failed}" >> "$GITHUB_OUTPUT" | |
| - name: Comment PR with coverage | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: github.event_name == 'pull_request' && matrix.php == '8.2' | |
| with: | |
| recreate: true | |
| message: | | |
| ## 📊 Test Coverage Report (PHP ${{ matrix.php }}) | |
| | Metric | Coverage | | |
| |--------|----------| | |
| | **Classes** | `${{ steps.coverage.outputs.classes }}` | | |
| | **Methods** | `${{ steps.coverage.outputs.methods }}` | | |
| | **Lines** | `${{ steps.coverage.outputs.lines }}` | | |
| **Test Results:** ${{ steps.coverage.outputs.test-result }} | |
| # Craft 4.x tests (v2 branch) - PHP 8.0+ | |
| craft4-tests: | |
| if: github.ref == 'refs/heads/v2' || github.base_ref == 'v2' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| php: [8.0, 8.1, 8.2] | |
| name: Craft 4.x - PHP ${{ matrix.php }} Tests | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv | |
| coverage: xdebug | |
| - name: Cache Composer packages | |
| id: composer-cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: vendor | |
| key: craft4-${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| craft4-${{ runner.os }}-php-${{ matrix.php }}- | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress --dev | |
| - name: Build Codeception (if exists) | |
| run: | | |
| if [ -f "vendor/bin/codecept" ]; then | |
| vendor/bin/codecept build | |
| fi | |
| - name: Run unit tests (if exists) | |
| run: | | |
| if [ -f "vendor/bin/codecept" ]; then | |
| vendor/bin/codecept run unit | |
| else | |
| echo "No tests configured for this branch" | |
| fi | |
| code-quality: | |
| runs-on: ubuntu-latest | |
| name: Code Quality | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: 8.2 | |
| extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress --dev | |
| - name: Check PHP syntax | |
| run: find src tests -name "*.php" -exec php -l {} \; |