|
| 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 | + RUN_BENCHMARK: false |
| 21 | + - PHP_VERSION: 7.2 |
| 22 | + CODE_COVERAGE: true |
| 23 | + RUN_PHPSTAN: false |
| 24 | + RUN_PSALM: false |
| 25 | + RUN_BENCHMARK: false |
| 26 | + - PHP_VERSION: 7.3 |
| 27 | + CODE_COVERAGE: true |
| 28 | + RUN_PHPSTAN: false |
| 29 | + RUN_PSALM: false |
| 30 | + RUN_BENCHMARK: false |
| 31 | + - PHP_VERSION: 7.4 |
| 32 | + CODE_COVERAGE: true |
| 33 | + RUN_PHPSTAN: true |
| 34 | + RUN_PSALM: true |
| 35 | + RUN_BENCHMARK: true |
| 36 | + - PHP_VERSION: 8.0-rc |
| 37 | + CODE_COVERAGE: true |
| 38 | + RUN_PHPSTAN: true |
| 39 | + RUN_PSALM: true |
| 40 | + RUN_BENCHMARK: true |
| 41 | + COMPOSER_EXTRA_ARGS: --ignore-platform-reqs |
| 42 | + |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v2 |
| 45 | + |
| 46 | + - name: Cache Docker Image |
| 47 | + id: cache-docker-image |
| 48 | + uses: actions/cache@v2 |
| 49 | + with: |
| 50 | + path: /tmp/docker-image.tar |
| 51 | + key: cache-docker-image-test:${{ matrix.PHP_VERSION }} |
| 52 | + |
| 53 | + - name: Load Docker Image |
| 54 | + if: steps.cache-docker-image.outputs.cache-hit == 'true' |
| 55 | + run: docker load --input /tmp/docker-image.tar |
| 56 | + |
| 57 | + - name: Build Docker Image |
| 58 | + if: steps.cache-docker-image.outputs.cache-hit != 'true' |
| 59 | + run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' . |
| 60 | + |
| 61 | + - name: Cache Composer Cache Files |
| 62 | + uses: actions/cache@v2 |
| 63 | + with: |
| 64 | + path: /tmp/composer-cache-files |
| 65 | + key: cache-composer-cache-files-${{ matrix.PHP_VERSION }} |
| 66 | + restore-keys: | |
| 67 | + cache-composer-cache-files- |
| 68 | +
|
| 69 | + - name: Install Composer Dependencies |
| 70 | + run: | |
| 71 | + if [ "${{ matrix.RUN_PHPSTAN }}" != "true" ]; then composer remove --dev phpstan/phpstan --no-update --no-interaction; fi |
| 72 | + if [ "${{ matrix.RUN_PSALM }}" != "true" ]; then composer remove --dev vimeo/psalm --no-update --no-interaction; fi |
| 73 | + if [ "${{ matrix.RUN_BENCHMARK }}" != "true" ]; then composer remove --dev phpbench/phpbench --no-update --no-interaction; fi |
| 74 | + 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 }} |
| 75 | +
|
| 76 | + - name: Run Unit Test |
| 77 | + run: | |
| 78 | + if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then |
| 79 | + 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 |
| 80 | + else |
| 81 | + docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Upload Codecov Report |
| 85 | + uses: codecov/codecov-action@v1 |
| 86 | + if: ${{ matrix.CODE_COVERAGE }} |
| 87 | + with: |
| 88 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 89 | + file: .clover.xml |
| 90 | + |
| 91 | + - name: Run PHPStan |
| 92 | + if: ${{ matrix.RUN_PHPSTAN }} |
| 93 | + 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/ |
| 94 | + |
| 95 | + - name: Run psalm |
| 96 | + if: ${{ matrix.RUN_PSALM }} |
| 97 | + 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 |
| 98 | + |
| 99 | + - name: Run benchmark |
| 100 | + if: ${{ matrix.RUN_BENCHMARK }} |
| 101 | + run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=-1' ./vendor/bin/phpbench run --no-interaction --revs=1 --retry-threshold=100 --progress=travis |
| 102 | + |
| 103 | + - name: Export Docker Image |
| 104 | + if: steps.cache-docker-image.outputs.cache-hit != 'true' |
| 105 | + run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}' |
0 commit comments