somenet77's avatar

Github actions error.

name: build

on:
  push:
    branches: main

jobs:
  test-php:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Copy .env
        run: php -r "file_exists('.env') || copy('.env.ci', '.env');"
      - name: Install Dependencies
        run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
      - name: Generate key
        run: |
          php artisan key:generate
      - name: Cache Clear
        run: |
          php artisan cache:clear
          php artisan clear-compiled
      - name: Directory Permissions
        run: chmod -R 777 storage bootstrap/cache
      - name: Create Database
        run: |
          mkdir -p database
          touch database/database.sqlite
      - name: Execute tests (Unit and Feature tests) via PHPUnit
        env:
          DB_CONNECTION: sqlite
          DB_DATABASE: database/database.sqlite
        run: vendor/bin/phpunit

What error in this jobs. There is no error 2 days before but I got error when I push my code today.

0 likes
9 replies
ms1987's avatar

Can you share the error you are receiving?

somenet77's avatar
Run php artisan key:generate

   Illuminate\Contracts\Container\BindingResolutionException 

  Target class [Illuminate\Console\Scheduling\ScheduleListCommand] does not exist.

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:832
    828▕ 
    829▕         try {
    830▕             $reflector = new ReflectionClass($concrete);
    831▕         } catch (ReflectionException $e) {
  ➜ 832▕             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    833▕         }
    834▕ 
    835▕         // If the type is not instantiable, the developer is attempting to resolve
    836▕         // an abstract type such as an Interface or Abstract Class and there is

      +15 vendor frames 
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
Error: Process completed with exit code 1
ms1987's avatar

The best I can do for you, for the moment, is share a composer.json file that is working

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.4",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "globalcitizen/php-iban": "^4.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/fortify": "^1.7",
        "laravel/framework": "^8.0",
        "laravel/tinker": "^2.0",
        "wildbit/postmark-php": "^4.0"
    },
    "require-dev": {
        "roave/security-advisories": "dev-master",
        "barryvdh/laravel-ide-helper": "^2.8",
        "facade/ignition": "^2.3.6",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

Some things that catch my eye

  • Have a look at your autoloading entries and compare those to mine
  • Choose a php version you want to stabilize on. (7 or 8 in this case).

Hope this helps

somenet77's avatar
somenet77
OP
Best Answer
Level 3

I fixed my self

name: build

on:
  push:
    branches: main

jobs:
  test-php:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Copy .env
        run: php -r "file_exists('.env') || copy('.env.ci', '.env');"
      - name: Remove vendor
        run: rm -rf vendor
      - name: Remove composer file
        run: rm composer.lock 
      - name: Install Dependencies
        run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
      - name: Generate key
        run: |
          php artisan key:generate
      - name: Cache Clear
        run: |
          php artisan cache:clear
          php artisan clear-compiled
      - name: Directory Permissions
        run: chmod -R 777 storage bootstrap/cache
      - name: Create Database
        run: |
          mkdir -p database
          touch database/database.sqlite
      - name: Execute tests (Unit and Feature tests) via PHPUnit
        env:
          DB_CONNECTION: sqlite
          DB_DATABASE: database/database.sqlite
        run: vendor/bin/phpunit

ms1987's avatar

The rm composer.local only now caught my eye... This is actually a very bad idea.

Your composer.lock file should always reside in your repo and be used in your CI. You want to install predictable dependency versions that you have implemented and tested.

By removing the composer.lock file, running composer install in your CI might install another version that matches within the version constraint that you defined in composer.json and thus yield unexpected results.

somenet77's avatar

If I remove rm composer.lock

My jobs always failed. I don't understand.

ms1987's avatar

what is the error you are getting then?

If you do the same process locally (clean install of your project) and run tests, does that fail also?

Please or to participate in this conversation.