Add GitHub action for tests #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR checks and tests | |
on: | |
pull_request: | |
branches: | |
- master | |
jobs: | |
run: | |
name: PHP ${{ matrix.php-versions }} (Redis ${{ matrix.redis-versions }}) | |
runs-on: ubuntu-latest | |
container: shivammathur/node | |
services: | |
redis: | |
image: redis:${{ matrix.redis-versions }}-alpine | |
# Set health checks to wait until redis has started | |
options: >- | |
--health-cmd "redis-cli ping" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
strategy: | |
fail-fast: false | |
matrix: | |
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] | |
redis-versions: ['5', '6', '7'] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
- name: Get composer cache directory | |
id: composercache | |
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" | |
- name: Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composercache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: ${{ runner.os }}-composer- | |
- name: Configure Redis for CI | |
run: | | |
apt-get update && apt-get install -y redis-tools | |
redis-cli -h redis -p 6379 CONFIG SET stop-writes-on-bgsave-error no | |
redis-cli -h redis -p 6379 CONFIG SET save "" | |
- name: Install dependencies | |
run: | | |
composer install --no-interaction --no-ansi --no-progress | |
- name: Run phpcs | |
run: | | |
./vendor/bin/phpcs src | |
- name: Run phpstan | |
run: | | |
./vendor/bin/phpstan analyse src | |
- name: Run phpunit tests | |
env: | |
REDIS_HOST: redis | |
REDIS_PORT: 6379 | |
REDIS_TIMEOUT: 0.0 | |
run: | | |
./vendor/bin/phpunit --disallow-test-output --no-coverage |