如何测试 composer.lock 是否是最新的?

2022-01-21 00:00:00 bash php composer-php

在开发过程中(团队中有多人)有时 composer install 返回:

During development (multiple people in the team) sometimes composer install returns:

警告:锁文件不是最新的 composer.json 中的最新更改.您可能会得到过时的依赖项.运行 update 以更新它们.

有没有办法快速检查(以毫秒为单位,无需进行任何更改)?

Is there a way to check for this very quickly (in milliseconds, without making any changes)?

我了解作曲家的工作原理.但是,当代码合并时,不一定会导致 composer.jsoncomposer.lock 文件发生合并冲突,并且运行 composer install 几乎没有任何更改并且该命令需要几分钟的时间.

I understand how composer works. However when code merges in it doesn't necessarily cause merge conflicts on the composer.json or composer.lock file and it's not fun to run composer install all the time when theres almost never any changes and that command takes several minutes.

如果我能够快速测试锁定失败是否不同步,我可以将其构建到 bash 环境中以通知每个命令.类似于人们喜欢将他们的 git status 内置到他们的 bash 提示符中.

If I'm able to quick test if the lock fail has fallen out of sync I can build it into the bash environment to notify every command. Similar to how people like their git status to be built into their bash prompt.

这在 CI 中更有意义,以确保它确实潜入稳定分支.

Further more this makes sense in CI to make sure it does sneak it's way into the stable branch.

推荐答案

对于作曲家 <1.3.0

For composer < 1.3.0

从@Domster扩展,纯bash中的解决方案:

Extending from @Domster, the solution in pure bash:

COMPOSER_IN_SYNC=$(expr "`cat composer.lock | grep '"hash":' | cut -d'"' -f4`" = "`md5sum composer.json | cut -d ' ' -f 1`")

$COMPOSER_IN_SYNC 将分别为 01.

相关文章