Github Actions のubuntuコンテナのPHPとComposerのバージョンが上がっていた話

github actionsでLaravelのtestを動かしていたのですが、ある時から突然落ちるようになりました。

原因を調べると、PHPのバージョンが8.0に、Composerのバージョンが2.xに上がっていたことが原因でした。

流れていたログはこんな感じ。

> Run composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ^7.2 but your PHP version (8.0.0) does not satisfy that requirement.
...
...

workflowではubuntu-latestを指定しており、このようにすると18.04がコンテナとして使用されます。

参考: https://github.com/actions/virtual-environments

詳しくは調べていませんが、PHP8.0が正式リリースされたので、ubuntu18.04のPHPのデフォルトバージョンが8.0にアップデートされたのだと思います。

PHPとcomposerのバージョンを変更する方法を調べた所、こちらのライブラリを使うと、簡単に設定することができることがわかりました。

具体的には、workflowの設定ファイルに以下の行を追加するだけです。

...
jobs:
  laravel-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup PHP                                      # 追加
      uses: shivammathur/setup-php@v2      # 追加
      with:                                                           # 追加
        php-version: '7.4'                                   # 追加
        tools: composer:v1                                # 追加
    - 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-progress --prefer-dist
....
...

今回原因を探っている時にハマった点としては、github actionsから作成したlaravel testのworkflowのデフォルト設定ではcomposer installの際にログを表示しないオプションがついており、それのせいでログが一切表示されなかった所です。

ログが表示されない理由が分からず、actionsのデバッグを有効化してみたり。。。と1時間ほど溶かしてしまいました。

見慣れないオプションにはこれから気をつけようと思いました。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です