|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + - '[0-9]+.x' |
| 9 | + |
| 10 | +jobs: |
| 11 | + php: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + - PHP_VERSION: 7.1 |
| 17 | + CODE_COVERAGE: false |
| 18 | + RUN_PHPSTAN: false |
| 19 | + RUN_PSALM: false |
| 20 | + - PHP_VERSION: 7.2 |
| 21 | + CODE_COVERAGE: true |
| 22 | + RUN_PHPSTAN: false |
| 23 | + RUN_PSALM: false |
| 24 | + - PHP_VERSION: 7.3 |
| 25 | + CODE_COVERAGE: true |
| 26 | + RUN_PHPSTAN: false |
| 27 | + RUN_PSALM: false |
| 28 | + - PHP_VERSION: 7.4 |
| 29 | + CODE_COVERAGE: true |
| 30 | + RUN_PHPSTAN: false |
| 31 | + RUN_PSALM: false |
| 32 | + - PHP_VERSION: 8.0 |
| 33 | + CODE_COVERAGE: true |
| 34 | + RUN_PHPSTAN: false |
| 35 | + RUN_PSALM: false |
| 36 | + #COMPOSER_EXTRA_ARGS: --ignore-platform-reqs |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v2 |
| 40 | + |
| 41 | + - name: Cache Docker Image |
| 42 | + id: cache-docker-image |
| 43 | + uses: actions/cache@v2 |
| 44 | + with: |
| 45 | + path: /tmp/docker-image.tar |
| 46 | + key: cache-docker-image-test:${{ matrix.PHP_VERSION }} |
| 47 | + |
| 48 | + - name: Load Docker Image |
| 49 | + if: steps.cache-docker-image.outputs.cache-hit == 'true' |
| 50 | + run: docker load --input /tmp/docker-image.tar |
| 51 | + |
| 52 | + - name: Build Docker Image |
| 53 | + if: steps.cache-docker-image.outputs.cache-hit != 'true' |
| 54 | + run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' . |
| 55 | + |
| 56 | + - name: Cache Composer Cache Files |
| 57 | + uses: actions/cache@v2 |
| 58 | + with: |
| 59 | + path: /tmp/composer-cache-files |
| 60 | + key: cache-composer-cache-files-${{ matrix.PHP_VERSION }} |
| 61 | + restore-keys: | |
| 62 | + cache-composer-cache-files- |
| 63 | +
|
| 64 | + - name: Install Composer Dependencies |
| 65 | + run: | |
| 66 | + if [ "${{ matrix.RUN_PHPSTAN }}" != "true" ]; then composer remove --dev phpstan/phpstan --no-update --no-interaction; fi |
| 67 | + if [ "${{ matrix.RUN_PSALM }}" != "true" ]; then composer remove --dev vimeo/psalm --no-update --no-interaction; fi |
| 68 | + if [ "${{ matrix.RUN_BENCHMARK }}" != "true" ]; then composer remove --dev phpbench/phpbench --no-update --no-interaction; fi |
| 69 | + docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v '/tmp/composer-cache-files:/.composer' 'test:${{ matrix.PHP_VERSION }}' composer install --no-interaction --no-progress --prefer-dist ${{ matrix.COMPOSER_EXTRA_ARGS }} |
| 70 | +
|
| 71 | + - name: Run Unit Test |
| 72 | + run: | |
| 73 | + if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then |
| 74 | + docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' -d 'pcov.enabled=1' ./vendor/bin/phpunit --coverage-clover=.clover.xml |
| 75 | + else |
| 76 | + docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Upload Codecov Report |
| 80 | + uses: codecov/codecov-action@v1 |
| 81 | + if: ${{ matrix.CODE_COVERAGE }} |
| 82 | + with: |
| 83 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 84 | + file: .clover.xml |
| 85 | + |
| 86 | + - name: Run PHPStan |
| 87 | + if: ${{ matrix.RUN_PHPSTAN }} |
| 88 | + run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'memory_limit=2G' ./vendor/bin/phpstan analyse --level max src/ tests/ |
| 89 | + |
| 90 | + - name: Run psalm |
| 91 | + if: ${{ matrix.RUN_PSALM }} |
| 92 | + run: mkdir -p "$HOME/.cache/psalm" && docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v "$HOME/.cache/psalm:/.cache/psalm" 'test:${{ matrix.PHP_VERSION }}' php ./vendor/bin/psalm |
| 93 | + |
| 94 | + - name: Export Docker Image |
| 95 | + if: steps.cache-docker-image.outputs.cache-hit != 'true' |
| 96 | + run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}' |
0 commit comments