4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel用のGithubActionsがいきなり落ちるようになった。[ Process completed with exit code 2. ]

Last updated at Posted at 2020-12-15

結論

PHPのデフォルトのバージョンが勝手に変わっていた。
PHP7.4使っていたが8.0になっていた。

何が起きたか

つい先日まで正常に動いていたgithub actionsが落ちるようになった。

Process completed with exit code 2.がでて落ちてる。

下記が実行してるaction。

落ちてるのはInstall Dependenciesの箇所
composerから依存関係インストールしてるだけ。

github-actions
name: Laravel

on:
  push:
    branches: [master, develop]
  pull_request:
    branches: [master, develop]

jobs:
  laravel-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Copy .env
        run: php -r "file_exists('.env') || copy('.env.example', '.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: 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: php artisan test

直し方

まずは原因を探る。
composerを実行しているコマンドから-qまたは--quietを削除します。
これはメッセージを出力しないようにするものなのですが、エラーの現在は状況がわからなくなります。

composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
# -qを抜く
composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

それを再度pushし直すと当然エラーが出ますので、ようやく原因がわかります。

一部ですが下記のようなエラーが出ていました。
PHPのバージョンが違うので入れれないてきなメッセージです。

Problem 1
    - Root composer.json requires php ^7.2.5 but your php version (8.0.0) does not satisfy that requirement.
  Problem 2
    - asm89/stack-cors is locked to version v2.0.1 and an update of this package was not requested.
    - asm89/stack-cors v2.0.1 requires php ^7.0 -> your php version (8.0.0) does not satisfy that requirement.
  Problem 3
    - bensampo/laravel-enum is locked to version v1.38.0 and an update of this package was not requested.
    - bensampo/laravel-enum v1.38.0 requires php ~7.1 -> your php version (8.0.0) does not satisfy that requirement.
  Problem 4
    - composer/composer is locked to version 1.10.13 and an update of this package was not requested.
    - composer/composer 1.10.13 requires php ^5.3.2 || ^7.0 -> your php version (8.0.0) does not satisfy that 

なので、PHPのバージョンを切り替えてあげます

shivammathur/setup-php@v2を使い簡単にPHPのバージョンを切り替えられます。(参考)

下記をワークフローに追加

 - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.4"

最終的に下記のようになりました。
どうせ折り畳めるので-qはそのままなくすことにしました。

github-actions
name: Laravel

on:
  push:
    branches: [master, develop]
  pull_request:
    branches: [master, develop]

jobs:
  laravel-tests:
    runs-on: ubuntu-latest
    steps:
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.4"
      - uses: actions/checkout@v2
      - name: Copy .env
        run: php -r "file_exists('.env') || copy('.env.example', '.env');"
      - name: Install Dependencies
        run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
      - name: Generate key
        run: php artisan key:generate
      - 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: php artisan test
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?