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

murilo's avatar
Level 10

Laravel Test with Git hub Actions, error on install Composer

I am trying to run a Git Hub Actions for laravel tenting . I have seen this video -

https://www.youtube.com/watch?v=631l4XCkQvs&t=226s

it has a example like that - /.github/workflows/build.yml

# GitHub Action for Laravel with MySQL and Redis
name: API
on: [push, pull_request]
jobs:
  laravel:
    name: Laravel (PHP ${{ matrix.php-versions }})
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: 'secret'
          MYSQL_DATABASE: 'icodestuff_testing'
          MYSQL_USER: 'homestead'
          MYSQL_PASSWORD: 'secret'
        ports:
          - 3306/tcp
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
      redis:
        image: redis
        ports:
          - 6379/tcp
        options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
    strategy:
      fail-fast: false
      matrix:
        php-versions: ['8.0']
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup PHP, with composer and extensions
        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
        with:
          php-version: ${{ matrix.php-versions }}
          extensions: mbstring, dom, fileinfo, mysql
          coverage: xdebug #optional
      - name: Start mysql service
        run: sudo /etc/init.d/mysql start
      - name: Get composer cache directory
        id: composercache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composercache.outputs.dir }}
          # Use composer.json for key, if composer.lock is not committed.
          # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-
      - name: Install Composer dependencies
        run: composer install --no-progress --prefer-dist --optimize-autoloader
      - name: Copy Env File
        run: cp .env.testing .env
      - name: Migrate Test Database
        run: php artisan migrate --env=testing --seed --force
        env:
          DB_PORT: ${{ job.services.mysql.ports['3306'] }}
          REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
      - name: Change Directory Permissions
        run: chmod -R 777 storage bootstrap/cache
      - name: Static Analysis via PHPStan
        run: ./vendor/bin/phpstan analyse --memory-limit=2G
      - name: Execute tests (Unit and Feature tests) via PHPUnit
        run: vendor/bin/phpunit
        env:
          DB_PORT: ${{ job.services.mysql.ports['3306'] }}
          REDIS_PORT: ${{ job.services.redis.ports['6379'] }}

It is giving this error on running the action, on Install Composer Dependencies -

Install Composer Dependencies 

Run composer install --no-progress --prefer-dist --optimize-autoloader
Composer could not find a composer.json file in /home/runner/work/laravel-docker-enviroment/laravel-docker-enviroment
To initialize a project, please create a composer.json file. See https://getcomposer.org/basic-usage
Error: Process completed with exit code 1.
0 likes
2 replies
Sinnbeck's avatar

So there is no composer.json file in your project on github?

1 like
murilo's avatar
murilo
OP
Best Answer
Level 10

my source code is in src/ . So I fixed adding this line command line-

working-directory: ./src

Please or to participate in this conversation.