Skip to content

Commit 94ff291

Browse files
committed
Run tests with github actions
1 parent fa59aca commit 94ff291

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
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

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

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.*
33
!/.gitignore
44
!/.gitattributes
5+
!/.github
56

67
# Composer
78
/vendor

0 commit comments

Comments
 (0)