composer-php - Github-actions - 作曲家因“sh:git:not found”而失败?
问题描述
我有一个 wordpress 插件,我使用 composer 来定义我的依赖库和 github-actions 来构建可安装的包。我计划将供应商文件夹发布到 github 中的“构建”分支,以便可以安装整个应用程序。
我的composer.json文件有这个内容并且在本地工作
{
"name" : "emeraldjava/bhaa_wordpress_plugin",
"description" : "bhaa_wordpress_plugin",
"type" : "wordpress-plugin",
"require": {
"scribu/scb-framework": "dev-master",
"scribu/lib-posts-to-posts": "dev-master",
"mustache/mustache": "2.12.0",
"league/csv": "^9.1",
"michelf/php-markdown": "^1.8"
},
并且我的 github-actions build.yml文件使用“ MilesChou/composer-action ”在 docker 容器中安装 composer env
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Composer install
uses: MilesChou/composer-action/7.3@master
with:
args: install --no-dev
- uses: docker://php:7.3-alpine
- uses: docker://alpine/git:latest
从构建日志中,我可以看到这些作曲家工件的 zip 文件已下载到缓存中
36/38: https://codeload.github.com/scribu/wp-scb-framework/legacy.zip/95b23ac342fce16bf5eb8d939ac5a361b94b104b
37/38: https://codeload.github.com/sebastianbergmann/phpunit/legacy.zip/a7834993ddbf4b0ed2c3b2dc1f3b1d093ef910a9
38/38: https://codeload.github.com/scribu/wp-lib-posts-to-posts/legacy.zip/a695438e455587fa228e993d05b4431cde99af1b
Finished: success: 38, skipped: 0, failure: 0, total: 38
然后构建失败并出现此“sh:git:未找到”错误
Package operations: 5 installs, 0 updates, 0 removals
- Installing scribu/scb-framework (dev-master 95b23ac): Cloning 95b23ac342
Failed to download scribu/scb-framework from source: Failed to clone https://github.com/scribu/wp-scb-framework.git, git was not found, check that it is installed and in your PATH env.
sh: git: not found
Now trying to download from dist
- Installing scribu/scb-framework (dev-master 95b23ac): Loading from cache
- Installing scribu/lib-posts-to-posts (dev-master a695438): Cloning a695438e45
Failed to download scribu/lib-posts-to-posts from source: Failed to clone https://github.com/scribu/wp-lib-posts-to-posts.git, git was not found, check that it is installed and in your PATH env.
sh: git: not found
Now trying to download from dist
- Installing scribu/lib-posts-to-posts (dev-master a695438): Loading from cache
- Installing mustache/mustache (v2.12.0): Loading from cache
- Installing michelf/php-markdown (1.8.0): Loading from cache
- Installing league/csv (9.4.1): Loading from cache
我假设我需要确保 docker 容器安装了 git,但是 composer 可以访问 legacy.zip 文件似乎很奇怪,那么为什么在这个阶段需要 git?
编辑 1
我想这里的快速修复是这个问题的副本,正如下面的答案所述。
为了完整起见,假设我不能调用 'composer --prefer-dist' 我怎么能确保 docker 容器有 git 可用?
解决方案
默认情况下,Composer 使用 dist (zip 文件) 标记发布版本和 source (git clone) 分支。由于您master
的依赖项的目标是分支,因此 Composer 会首先尝试克隆存储库。您可以使用--prefer-dist
switch 覆盖此行为:
with:
args: install --prefer-dist --no-dev
--prefer-dist
: 的反面--prefer-source
,Composer 将dist
尽可能安装。这可以大大加快构建服务器和其他通常不运行供应商更新的用例的安装速度。如果您没有正确的设置,这也是一种规避 git 问题的方法。
推荐阅读
- firefox - Firefox 网址栏字体
- cassandra - 我应该如何在 Cassandra 中实现数据访问/权限管理
- typescript - 当 Vuex 的“router.currentRoute.name”改变时更新计算属性
- python - 删除熊猫列中的部分字符串
- c++ - 如果 libpcap 的环形缓冲区快满了,我怎么能得到
- excel - 如何防止在宏套件中打开每个工作簿时屏幕闪烁灰色
- entity-framework - EF Core Include、Where 和 ThenInclude
- javascript - 如何从 URL 获取 JSON 并将其存储在变量中(Node.js)
- python-3.x - 使用带有滚动框架的 postscript 方法出现问题
- python-3.x - 具有 Concatenate AttributeError 的 Keras:“NoneType”对象没有属性“_inbound_nodes”