Search code examples
laravelgithubcomposer-phpgithub-actionslaravel-vapor

Github action deployment fails because of not matching composer-runtime-api ^2.0.0 but actions/checkout@v2 is used


Github action deployment fails because of not matching composer-runtime-api ^2.0.0 even though actions/checkout@v2 is used that uses composer v2

laravel.yml:

name: Deploy to staging

on:
  push:
    branches: [ staging ]

jobs:
  vapor:
    name: Check out, build and deploy using Vapor
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: ubient/laravel-vapor-action@master
        env:
          VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
        with:
          args: "deploy staging"

composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.4",
        "aws/aws-sdk-php": "3.166.2",
        "barryvdh/laravel-dompdf": "^0.8.7",
        "bensampo/laravel-enum": "^3.2.0",
        "doctrine/dbal": "^2.10",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.0",
        "laravel/helpers": "^1.3",
        "laravel/sanctum": "^2.4",
        "laravel/tinker": "^2.5",
        "laravel/vapor-cli": "^1.12",
        "laravel/vapor-core": "^2.8",
        "laravel/vapor-ui": "^1.0",
        "owen-it/laravel-auditing": "^10.0",
        "pusher/pusher-php-server": "^4.1",
        "sentry/sentry-laravel": "^2.3",
        "spatie/laravel-permission": "^3.16",
        "spatie/laravel-tags": "^2.7"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.8",
        "beyondcode/laravel-dump-server": "^1.4",
        "facade/ignition": "^2.5",
        "fzaninotto/faker": "^1.9.1",
        "laravel/horizon": "^5.6",
        "laravel/sail": "^1.1",
        "laravel/telescope": "^4.4.0",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": [
                "barryvdh/laravel-ide-helper",
                "laravel/telescope"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "classmap": [
        ],
        "files": [
            "bootstrap/helpers.php"
        ]
    },
    "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-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "@php artisan ide-helper:generate",
            "@php artisan ide-helper:meta"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

error:

Building project...
==> Validating Manifest File
==> Copying Application Files
==> Harmonizing Configuration Files
==> Setting Build Environment
==> Executing Build Commands
==> Running Command: composer install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for jean85/pretty-package-versions 2.0.3 -> satisfiable by jean85/pretty-package-versions[2.0.3].
    - jean85/pretty-package-versions 2.0.3 requires composer-runtime-api ^2.0.0 -> no matching package found.
  Problem 2
    - jean85/pretty-package-versions 2.0.3 requires composer-runtime-api ^2.0.0 -> no matching package found.
    - sentry/sentry 3.2.0 requires jean85/pretty-package-versions ^1.5|^2.0.1 -> satisfiable by jean85/pretty-package-versions[2.0.3].
    - Installation request for sentry/sentry 3.2.0 -> satisfiable by sentry/sentry[3.2.0].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

The deployment command is 'composer install --no-dev' . At first, I was using actions/checkout@v1 when having this error, then I moved to actions/checkout@v2 once I understood that composer v2 is on checkout@v2 vs v1 on checkout@v1, but the problem persists... Any hints on why this is happening would be welcome.

Edit: I am able to run the deployment from my local device without any issues(once I moved to composer v2).


Solution

  • as @bk2204 helped me to realize my faulty assumption that checkout@v2 sets composer to v2 I was able to resolve my problem by changing the laravel.yml deployment instructions as follows:

    name: Deploy to staging
    
    on:
      push:
        branches: [ staging ]
    
    jobs:
      vapor:
        name: Check out, build and deploy using Vapor
        runs-on: ubuntu-latest
        steps:
        - name: Checkout
          uses: actions/checkout@v2
    
        - name: Setup PHP (w/ extensions) & Composer
          uses: shivammathur/setup-php@v2
          with:
            php-version: 7.4
            tools: pecl
            extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo, tokenizer, xml, zip, pcntl
            coverage: none
    
        - name: Obtain Composer cache directory
          id: composer-cache
          run: echo "::set-output name=dir::$(composer config cache-files-dir)"
    
        - name: Cache Composer dependencies
          uses: actions/cache@v1
          with:
            path: ${{ steps.composer-cache.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 Vapor CLI Globally
          run: composer global require laravel/vapor-cli
    
        - name: Install Composer dependencies
          run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader --no-dev
    
        - name: Deploy using Laravel Vapor
          env:
            VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
          run: /home/runner/.composer/vendor/bin/vapor deploy staging