Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

talel's avatar
Level 16

Cypress GitHub workflow

Any good reference to set up a GitHub workflow for Cypress with Laravel?

The main issue I am facing is that on local development I am using Laravel Herd - which generates a secured TLS for my domain.

With Cypress, setting the baseUrl configuration parameter causes the workflow to wait for a server to response before running the tests (GH Workflow). If I try to run npm run vite it fails cause it cannot find the secure TLS based on the vite.config.js param detectTls: true - so I am stuck.

Any ideas?

The current workflow

name: End-to-End Test

on: [ push, pull_request ]

jobs:
  Tests:
    runs-on: ubuntu-latest

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.3
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
          tools: composer:v2
          coverage: coverage

      - name: Add HTTP basic auth credentials
        run: echo '${{ secrets.COMPOSER_AUTH_JSON }}' > $GITHUB_WORKSPACE/auth.json

      - name: Install Composer dependencies
        run: composer install --no-interaction --prefer-dist --optimize-autoloader

      - name: Install NPM dependencies
        run: npm install

      - name: Compile assets
        run: npm run build

      - name: Copy .env
        run: cp .env.example .env

      - name: Generate key
        run: php artisan key:generate

      - name: Clear Config
        run: php artisan config:clear
        
      - name: Run Vite Server
        run: npm run dev

      - name: Cypress run
        uses: cypress-io/github-action@v6
        env:
          STRIPE_SECRET: ${{ secrets.STRIPE_SECRET }}
0 likes
1 reply
talel's avatar
talel
OP
Best Answer
Level 16

End up setting up a workflow using macos-latest and installing Valet. This is the workflow:

name: End-to-End Test

on: [ push, pull_request ]

jobs:
  Tests:
    runs-on: macos-latest

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.3
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
          tools: composer:v2
          coverage: coverage

      - name: Add HTTP basic auth credentials
        run: echo '${{ secrets.COMPOSER_AUTH_JSON }}' > $GITHUB_WORKSPACE/auth.json

      - name: Install Composer dependencies
        run: composer install --no-interaction --prefer-dist --optimize-autoloader

      - name: Install NPM dependencies
        run: npm install

      - name: Copy .env
        run: cp .env.example .env

      - name: Generate key
        run: php artisan key:generate

      - name: Clear Config
        run: php artisan config:clear

      - name: Install MySQL
        run: |
          brew install mysql
          sudo chown -R _mysql:mysql /usr/local/var/mysql
          sudo mysql.server start

      - name: Set up MySQL database
        run: |
          mysql -u root -e 'CREATE DATABASE IF NOT EXISTS laravel;'
          mysql -u root -e "GRANT ALL PRIVILEGES ON laravel.* TO 'root'@'localhost';"
          mysql -u root -e 'FLUSH PRIVILEGES;'

      - name: Migrate MySQL database
        env:
          DB_CONNECTION: mysql
          DB_DATABASE: laravel
          DB_PORT: 3306
          DB_USER: root
          STRIPE_SECRET: ${{ secrets.STRIPE_SECRET }}
        run: php artisan migrate:fresh

      - name: Require Laravel Valet
        run: composer global require laravel/valet

      - name: Install Valet
        run: valet install

      - name: Start Valet
        run: valet start

      - name: Secure Valet
        run: valet secure mydomain.test

      - name: Link Valet
        run: valet link

      - name: Start Vite server
        run: npm run dev &
        env:
          LARAVEL_BYPASS_ENV_CHECK: 1

      - name: Cypress run
        run: npx cypress run

Please or to participate in this conversation.