CIのComposerバージョンが2になる(composer self-updateさせてた)せいでテストがコケてた話



今回の目標

CIをphp7.4に対応したい
(Herokuでは既に7.4.7だったので)

 

.circleci/config.ymlのimageをcircleci/php:7.4-node-browsers
にしたところ、composer-plugin-apiに関するエラーが発生しました。

Composer2でcomposer installを実行したのに、composer.lockでcomposer-plugin-apiは1系って書いてあるから互換性ないやないかーみたいなこと言ってる、おそらく。Composer2はcomposer-plugin-api2系使えってこと?

($ composer install -n –prefer-dist以下)

$ php --version
PHP 7.4.9 (cli) (built: Dec 26 2020 23:21:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans

$ composer --version
Composer version 2.0.8 2020-12-03 17:20:38

$ composer install -n --prefer-dist
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

Problem 1
- ocramius/package-versions is locked to version 1.4.2 and an update of this package was not requested.
- ocramius/package-versions 1.4.2 requires composer-plugin-api ^1.0.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
Problem 2
- symfony/flex is locked to version v1.5.3 and an update of this package was not requested.
- symfony/flex v1.5.3 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
Problem 3
- ocramius/package-versions 1.4.2 requires composer-plugin-api ^1.0.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
- ocramius/proxy-manager 2.1.1 requires ocramius/package-versions ^1.1.1 -> satisfiable by ocramius/package-versions[1.4.2].
- ocramius/proxy-manager is locked to version 2.1.1 and an update of this package was not requested.

ocramius/package-versions only provides support for Composer 2 in 1.8+, which requires PHP 7.4.
If you can not upgrade PHP you can require composer/package-versions-deprecated to resolve this with PHP 7.0+.

You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.

 

そもそもCircleCIを導入しようとしてましたが、すでにTravis導入済みだったのでCircleCI導入はやめました。すみません💦(ただエラー内容はだいたい一緒だったと思います。)

当時設定していた.travis.ymlのPHPバージョンが7.1~7.3だったので7.4にしようと思います。

ローカルではcomposer1.8系を使っていたのでエラーはみられませんでしたが、
.travis.yamlではbefore_install: composer self-updateにしてたのでcomposer2系でcomposer installを実行しようとしていました。

エラー内容:

xxx/yyy n.n.n requires composer-plugin-api ^1.0.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.

composer.jsonのrequireにcomposer-plugin-api: "^1.0 || ^2.0"を追記で↑のエラーは回避できました!!!

参考:https://github.com/composer/composer/issues/8726

 

[おまけ]composer validate追記したらエラーでた

実際にでてたエラーログです。

$ composer validate
./composer.json is valid for simple usage with composer but has
strict errors that make it unable to be published as a package:
See https://getcomposer.org/doc/04-schema.md for details on the schema
name : The property name is required
description : The property description is required
symfony/debug-pack, symfony/maker-bundle, symfony/profiler-pack, symfony/test-pack are required both in require and require-dev, this can lead to unexpected behavior
require.symfony/debug-pack : unbound version constraints (*) should be avoided
require.symfony/orm-pack : unbound version constraints (*) should be avoided
require.symfony/profiler-pack : unbound version constraints (*) should be avoided
require.symfony/serializer-pack : unbound version constraints (*) should be avoided
require.symfony/test-pack : unbound version constraints (*) should be avoided
require.symfony/twig-pack : unbound version constraints (*) should be avoided

 

1) エラー内容:
xxx/yyy are required both in require and require-dev, this can lead to unexpected behavior

→ requireとrequire-devに同じpackageが書いてあるのがダメみたいなのでrequire-devから重複削除しました。

 

2) エラー内容:
name : The property name is required
description : The property description is required

→ composer.jsonにnameとdescriptionが必要とのことなので、追加しました。

 

3) エラー内容:
require.xxx/yyy: unbound version constraints (*) should be avoided

→ xxx/yyy: "*"はやめるべきとのことなのでバージョン指定をしました。

 

すべて(今回は3つ)のエラーを解消させ、

composer updateでcomposer.lockを更新して再度composer validateするvalidになりました〜🙌

$ composer validate
./composer.json is valid

 

メモ

  • 今回対応での差分

https://github.com/kin29/dj-kin29/pull/10/files

 

 

  • 後々考えてみたら、ローカル環境のcomposerバージョンを2にして、composer updateでcomposer.lockを更新してcommitで良かったのかも😅

composer-plugin-api:^2.0に対応してないpackageだったら、composer.jsonのrequireにcomposer-plugin-api: "^1.0 || ^2.0"追記が必要なのかも。