|
| 1 | +name: CI PHP Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + extensions: |
| 7 | + type: string |
| 8 | + description: The comma-separated list of extensions to install. |
| 9 | + default: "" |
| 10 | + required: false |
| 11 | + php-versions: |
| 12 | + type: string |
| 13 | + description: The space sparated list of PHP versions to use for the tests. |
| 14 | + default: "8.1 8.0" |
| 15 | + required: false |
| 16 | + min-php-version: |
| 17 | + type: string |
| 18 | + description: The minimal PHP version to use for the tests. |
| 19 | + default: "all" |
| 20 | + required: false |
| 21 | + suite-with-coverage: |
| 22 | + type: string |
| 23 | + description: The test suite which is used to check the code coverage. |
| 24 | + default: "unit-test" |
| 25 | + required: false |
| 26 | + |
| 27 | +jobs: |
| 28 | + prepare-matrix: |
| 29 | + name: Prepare build matrix |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v2 |
| 34 | + |
| 35 | + - name: Checkout shared workflow files |
| 36 | + uses: actions/checkout@v2 |
| 37 | + with: |
| 38 | + repository: BluePsyduck/github-workflows |
| 39 | + path: .shared |
| 40 | + |
| 41 | + - name: Setup PHP |
| 42 | + uses: shivammathur/setup-php@v2 |
| 43 | + with: |
| 44 | + php-version: "8.0" |
| 45 | + coverage: none |
| 46 | + extensions: ${{ inputs.extensions }} |
| 47 | + |
| 48 | + - name: Get composer cache directory |
| 49 | + id: composer-cache |
| 50 | + run: echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 51 | + |
| 52 | + - name: Cache composer dependencies |
| 53 | + uses: actions/cache@v2 |
| 54 | + with: |
| 55 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 56 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} |
| 57 | + restore-keys: ${{ runner.os }}-composer- |
| 58 | + |
| 59 | + - name: Install dependencies |
| 60 | + run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader |
| 61 | + |
| 62 | + - name: Generate build matrix |
| 63 | + id: matrix |
| 64 | + env: |
| 65 | + PHP_VERSIONS: ${{ inputs.php-versions }} |
| 66 | + MIN_PHP_VERSION: ${{ inputs.min-php-version }} |
| 67 | + run: | |
| 68 | + echo "::set-output name=matrix::$(php .shared/.github/scripts/build-matrix.php)" |
| 69 | +
|
| 70 | + - name: Print matrix |
| 71 | + run: echo '${{ steps.matrix.outputs.matrix }}' |
| 72 | + outputs: |
| 73 | + matrix: ${{ steps.matrix.outputs.matrix }} |
| 74 | + |
| 75 | + test: |
| 76 | + name: PHPUnit |
| 77 | + needs: prepare-matrix |
| 78 | + if: needs.prepare-matrix.outputs.matrix != '[]' |
| 79 | + strategy: |
| 80 | + fail-fast: false |
| 81 | + matrix: |
| 82 | + include: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }} |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - name: Checkout |
| 86 | + uses: actions/checkout@v2 |
| 87 | + |
| 88 | + - name: Checkout shared workflow files |
| 89 | + uses: actions/checkout@v2 |
| 90 | + with: |
| 91 | + repository: BluePsyduck/github-workflows |
| 92 | + path: .shared |
| 93 | + |
| 94 | + - name: Setup PHP |
| 95 | + uses: shivammathur/setup-php@v2 |
| 96 | + with: |
| 97 | + php-version: ${{ matrix.version }} |
| 98 | + coverage: ${{ matrix.suite == inputs.suite-with-coverage && 'xdebug' || 'none' }} |
| 99 | + extensions: ${{ inputs.extensions }} |
| 100 | + |
| 101 | + - name: Get composer cache directory |
| 102 | + id: composer-cache |
| 103 | + run: echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 104 | + |
| 105 | + - name: Cache composer dependencies |
| 106 | + uses: actions/cache@v2 |
| 107 | + with: |
| 108 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 109 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} |
| 110 | + restore-keys: ${{ runner.os }}-composer- |
| 111 | + |
| 112 | + - name: Setup problem matchers |
| 113 | + run: | |
| 114 | + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" |
| 115 | + echo "::add-matcher::.shared/.github/problem-matchers/coverage-check.json" |
| 116 | +
|
| 117 | + - name: Install dependencies |
| 118 | + run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader |
| 119 | + |
| 120 | + - name: Run phpunit |
| 121 | + run: vendor/bin/phpunit --testsuite=${{ matrix.suite }} ${{ matrix.suite == inputs.suite-with-coverage && '--coverage-clover=coverage.xml' || '' }} |
| 122 | + |
| 123 | + - name: Check coverage.xml existence |
| 124 | + id: check-coverage-file |
| 125 | + uses: andstor/file-existence-action@v1 |
| 126 | + with: |
| 127 | + files: coverage.xml |
| 128 | + |
| 129 | + - name: Run coverage-check |
| 130 | + if: steps.check-coverage-file.outputs.files_exists == 'true' |
| 131 | + run: vendor/bin/coverage-check coverage.xml 100 |
| 132 | + |
| 133 | + - name: Upload coverage as artifacts |
| 134 | + if: steps.check-coverage-file.outputs.files_exists == 'true' |
| 135 | + uses: actions/upload-artifact@v2 |
| 136 | + with: |
| 137 | + name: coverage-${{ matrix.version }} |
| 138 | + path: coverage.xml |
| 139 | + |
| 140 | + - name: Upload coverage to Codecov |
| 141 | + if: steps.check-coverage-file.outputs.files_exists == 'true' |
| 142 | + uses: codecov/codecov-action@v1 |
| 143 | + with: |
| 144 | + name: coverage-${{ matrix.version }} |
| 145 | + file: coverage.xml |
0 commit comments