Skip to content

Run PostgreSQL Tests on GitHub Actions #6

@stefanzweifel

Description

@stefanzweifel

The package supports PostgreSQL (pgsql) and has tests written for it. However, these tests are not executed on GitHub Actions, as @stefanzweifel had trouble setting things up so that it worked.

To always have full coverage and confidence that a change doesn't break anything, pgsql tests should run on GitHub Actions too.

If you have experienc with PostgreSQL and GitHub Actions, feel free to submit a Pull Request that resolves this issue.


Last time @stefanzweifel tried to set PostgreSQL up with GitHub Actions, the test suite could not be executed due to the following thrown error.

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?

The run-tests.yml workflow was updated with a postgres-service and additional. It looked like this:

name: run-tests

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

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-latest]
        php: [8.2, 8.1]
        laravel: [9.*]
        stability: [prefer-lowest, prefer-stable]
        include:
          - laravel: 9.*
            testbench: 7.*
            carbon: ^2.63

    env:
      DB_DATABASE: laravel_backup_restore
      DB_USERNAME: root

    services:
      mysql:
        image: mysql:latest
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: true
          MYSQL_DATABASE: laravel_backup_restore
        ports:
          - 3306/tcp
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

      postgres:
        image: postgres:latest
        env:
          POSTGRES_USER: root
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: laravel_backup_restore
        ports:
          - 5432/tcp
        options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3

    name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
          coverage: none

      - name: Setup problem matchers
        run: |
          echo "::add-matcher::${{ runner.tool_cache }}/php.json"
          echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Install dependencies
        run: |
          composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
          composer update --${{ matrix.stability }} --prefer-dist --no-interaction

      - name: List Installed Dependencies
        run: composer show -D

      - name: Execute tests
        run: vendor/bin/pest
        env:
          MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
          MYSQL_USERNAME: root
          MYSQL_PASSWORD: ''
          MYSQL_DATABASE: laravel_backup_restore
          PGSQL_PORT: ${{ job.services.postgres.ports['5432'] }}
          PGSQL_USERNAME: root
          PGSQL_PASSWORD: postgres
          PGSQL_DATABASE: laravel_backup_restore

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions