Skip to content

Commit 6be9241

Browse files
committed
GH workflow "test"
1 parent 6b5f56d commit 6be9241

File tree

3 files changed

+123
-83
lines changed

3 files changed

+123
-83
lines changed

.github/workflows/test.Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ARG PHP_VERSION=latest
2+
FROM php:${PHP_VERSION}-cli-alpine
3+
4+
WORKDIR /workdir
5+
6+
# install composer
7+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
8+
ENV COMPOSER_ALLOW_SUPERUSER=1
9+
ENV COMPOSER_HTACCESS_PROTECT=0
10+
ENV COMPOSER_CACHE_DIR=/.composer
11+
12+
# install PHP extension pcov
13+
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
14+
&& mkdir -p /usr/src/php/ext/pcov && curl -fsSL https://pecl.php.net/get/pcov | tar xvz -C /usr/src/php/ext/pcov --strip 1 \
15+
&& docker-php-ext-install pcov \
16+
&& docker-php-ext-enable pcov \
17+
&& rm -Rf /usr/src/php/ext/pcov \
18+
&& apk del --no-cache .build-deps

.github/workflows/test.yml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 ./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 }}'

.travis.yml

-83
This file was deleted.

0 commit comments

Comments
 (0)