|
| 1 | +name: 🏃 tests |
| 2 | + |
| 3 | +on: [ push, pull_request, workflow_call ] |
| 4 | + |
| 5 | +jobs: |
| 6 | + compute: |
| 7 | + uses: ./.github/workflows/compute.yml |
| 8 | + |
| 9 | + build: |
| 10 | + name: 'Build COVERAGE: ${{ matrix.coverage }} - PHP: ${{ matrix.php }}' |
| 11 | + |
| 12 | + needs: [ compute ] |
| 13 | + |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + os: ${{ fromJson(needs.compute.outputs.os) }} |
| 18 | + coverage: ${{ fromJson(needs.compute.outputs.coverage) }} |
| 19 | + php: ${{ fromJson(needs.compute.outputs.php) }} |
| 20 | + exclude: ${{ fromJson(needs.compute.outputs.exclude) }} |
| 21 | + |
| 22 | + runs-on: ${{ matrix.os }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Store Composer cache directory |
| 29 | + id: composer-cache |
| 30 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 31 | + |
| 32 | + - name: Store PHP code coverage version |
| 33 | + id: version-cache |
| 34 | + env: |
| 35 | + COVERAGE: ${{ matrix.coverage }} |
| 36 | + run: | |
| 37 | + echo "version=$(echo $COVERAGE | tr -d -c 0-9)" >> $GITHUB_OUTPUT |
| 38 | + echo "major=$(echo $COVERAGE | tr -d -c 0-9 | sed 's/.\{2\}$//')" >> $GITHUB_OUTPUT |
| 39 | +
|
| 40 | + - uses: actions/cache/restore@v4 |
| 41 | + id: restore-composer-cache |
| 42 | + with: |
| 43 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 44 | + key: ${{ runner.os }}-${{ matrix.php }}-${{ steps.version-cache.outputs.major }}-${{ matrix.coverage }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-${{ matrix.php }}-${{ steps.version-cache.outputs.major }}- |
| 47 | + ${{ runner.os }}-${{ matrix.php }}- |
| 48 | + ${{ runner.os }}- |
| 49 | +
|
| 50 | + - name: Set up PHP Version ${{ matrix.php }} |
| 51 | + uses: shivammathur/setup-php@v2 |
| 52 | + with: |
| 53 | + php-version: ${{ matrix.php }} |
| 54 | + coverage: xdebug |
| 55 | + tools: composer:v2 |
| 56 | + |
| 57 | + - name: Environment Check |
| 58 | + run: | |
| 59 | + php --version |
| 60 | + composer --version |
| 61 | + mkdir -p .Log/coverage/ .Log/log/ |
| 62 | +
|
| 63 | + - name: Validate composer.json |
| 64 | + run: composer validate |
| 65 | + |
| 66 | + - name: Composer install |
| 67 | + run: composer update --with "phpunit/php-code-coverage:${{ matrix.coverage }}" --no-interaction |
| 68 | + |
| 69 | + - name: Save composer cache |
| 70 | + uses: actions/cache/save@v4 |
| 71 | + with: |
| 72 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 73 | + key: ${{ steps.restore-composer-cache.outputs.cache-primary-key }} |
| 74 | + |
| 75 | + - name: Lint PHP |
| 76 | + run: php .Build/bin/parallel-lint --exclude .Build . |
| 77 | + |
| 78 | + - name: Run PHPUnit |
| 79 | + if: ${{ success() || failure() }} |
| 80 | + run: find 'tests' -wholename '*Test.php' | parallel --gnu 'echo -e "\n\nRunning test {}"; HASH=${{ steps.version-cache.outputs.version }}_$( echo {} | md5sum | cut -d " " -f 1); .Build/bin/phpunit --log-junit .Log/log/junit_$HASH.xml --coverage-php .Log/coverage/coverage_$HASH.cov --coverage-filter src/ {}' |
| 81 | + |
| 82 | + - name: Archive PHPUnit logs |
| 83 | + uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: phpunit-logs-${{ runner.os }}-${{ matrix.php }}-${{ steps.version-cache.outputs.major }}-${{ matrix.coverage }} |
| 86 | + path: .Log/* |
| 87 | + retention-days: 1 |
| 88 | + |
| 89 | + merge: |
| 90 | + name: 'Merge COVERAGE: ${{ matrix.coverage }} - PHP: ${{ matrix.php }}' |
| 91 | + |
| 92 | + needs: [ compute, build ] |
| 93 | + |
| 94 | + strategy: |
| 95 | + fail-fast: false |
| 96 | + matrix: |
| 97 | + os: ${{ fromJson(needs.compute.outputs.os) }} |
| 98 | + coverage: ${{ fromJson(needs.compute.outputs.major) }} |
| 99 | + php: ${{ fromJson(needs.compute.outputs.php) }} |
| 100 | + exclude: ${{ fromJson(needs.compute.outputs.exclude) }} |
| 101 | + |
| 102 | + runs-on: ${{ matrix.os }} |
| 103 | + |
| 104 | + steps: |
| 105 | + - name: Checkout |
| 106 | + uses: actions/checkout@v4 |
| 107 | + |
| 108 | + - name: Download PHPUnit logs |
| 109 | + uses: actions/download-artifact@v4 |
| 110 | + with: |
| 111 | + path: .Log |
| 112 | + pattern: phpunit-logs-${{ runner.os }}-${{ matrix.php }}-${{ matrix.coverage }}-* |
| 113 | + merge-multiple: true |
| 114 | + |
| 115 | + - name: Store Composer cache directory |
| 116 | + id: composer-cache |
| 117 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 118 | + |
| 119 | + - uses: actions/cache/restore@v4 |
| 120 | + id: restore-composer-cache |
| 121 | + with: |
| 122 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 123 | + key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.coverage }} |
| 124 | + restore-keys: | |
| 125 | + ${{ runner.os }}-${{ matrix.php }}- |
| 126 | + ${{ runner.os }}- |
| 127 | +
|
| 128 | + - name: Set up PHP Version ${{ matrix.php }} |
| 129 | + uses: shivammathur/setup-php@v2 |
| 130 | + with: |
| 131 | + php-version: ${{ matrix.php }} |
| 132 | + coverage: xdebug |
| 133 | + tools: composer:v2 |
| 134 | + |
| 135 | + - name: Environment Check |
| 136 | + run: | |
| 137 | + php --version |
| 138 | + composer --version |
| 139 | +
|
| 140 | + - name: Validate composer.json |
| 141 | + run: composer validate |
| 142 | + |
| 143 | + - name: Composer install |
| 144 | + run: composer update --with "phpunit/php-code-coverage:^${{ matrix.coverage }}.0" --no-interaction |
| 145 | + |
| 146 | + - name: Save composer cache |
| 147 | + uses: actions/cache/save@v4 |
| 148 | + with: |
| 149 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 150 | + key: ${{ steps.restore-composer-cache.outputs.cache-primary-key }} |
| 151 | + |
| 152 | + - name: Merge log files |
| 153 | + run: bin/phpunit-merger log .Log/log/ .Log/junit.xml |
| 154 | + |
| 155 | + - name: Merge coverage files |
| 156 | + run: bin/phpunit-merger coverage .Log/coverage/ .Log/coverage.xml |
| 157 | + |
| 158 | + - name: Archive PHPUnit logs |
| 159 | + uses: actions/upload-artifact@v4 |
| 160 | + with: |
| 161 | + name: phpunit-logs-merged-${{ runner.os }}-${{ matrix.php }}-${{ matrix.coverage }} |
| 162 | + path: .Log/* |
| 163 | + retention-days: 1 |
0 commit comments