Redis failing in CI when running tests

I am getting an error when running tests in CI. The error is related to Redis.

Error

Here's the YAML file:

name: Tests
on:
  push:
    branches: [ "*" ]
  pull_request:
    branches: [ "*" ]
jobs:
  tests:
    runs-on: ubuntu-latest
    services:
      redis:
        image: redis
        ports:
          - 6379/tcp
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    steps:
      - name: Run Tests
        env:
          APP_ENV: "ci"
          REDIS_HOST: redis
          REDIS_PORT: 6379
          DB_CONNECTION: ${{ secrets.DB_CONNECTION }}
          DB_HOST: ${{ secrets.DB_HOST }}
          DB_PORT: ${{ secrets.DB_PORT }}
          DB_DATABASE: ${{ secrets.DB_DATABASE }}
          DB_USER: ${{ secrets.DB_USER }}
          DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
        run: vendor/bin/pest --exclude-group=integration --parallel

I have simplified this to only show the relevant parts.

It makes no difference whether I use redis, phpredis, or predis for the REDIS_CLIENT.

Haz Member
Haz
Moderator
0
6
496
alex Member
alex
Moderator

Have you considered using a pre-built GitHub action for Redis?

Generally I find them easier to set up and work with.

I’m not at my computer right now so can’t check, but pretty such I use this one!

https://github.com/marketplace/actions/actions-setup-redis

alex Member
alex
Moderator

Did you end up getting this to work Haz?

Haz Member
Haz
Moderator

Haven't got around to this yet. Might take some time. Will keep you posted.

alex Member
alex
Moderator
Solution

Here's my full Pest testing setup with Redis included. Hope this helps figure something out.

name: Pest

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  pest:
    services:
      redis:
        image: redis
        env:
          REDIS_HOST: localhost
          REDIS_PORT: 6379
        ports:
          - 6379:6379
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
      postgres:
        image: postgres:15
        env:
          POSTGRES_DB: codecourse_testing
          POSTGRES_PASSWORD: postgres
          POSTGRES_PORT: 5432
          POSTGRES_USER: codecourse
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432

    runs-on: ubuntu-latest

    steps:
    - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
      with:
        php-version: '8.3'
    - uses: actions/checkout@v3
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.pest.ci', '.env');"
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
    - name: Generate key
      run: php artisan key:generate
    - name: Execute tests
      run: ./vendor/bin/pest

In .env.pest.ci:

REDIS_HOST=localhost
REDIS_PASSWORD=
REDIS_PORT=6379
Haz Member
Haz
Moderator

Just got around to looking at this. Removing the null password and setting the correct REDIS_HOST in the .env.ci and YAML workflow did the trick.

REDIS_HOST=localhost
REDIS_PASSWORD=
alex Member
alex
Moderator

Awesome, glad it's sorted!