Github-actions - composer 因 'sh: git: not found' 而失败?

Github-actions - composer fails with 'sh: git: not found'?

我有一个 wordpress 插件,我在其中使用 composer 来定义我的依赖库,并使用 github-actions 来构建可安装包。我计划将 vendors 文件夹发布到 github 中的 'build' 分支,以便可以安装整个应用程序。

我的 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 file uses 'MilesChou/composer-action' 在 docker 容器

中安装作曲家环境
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: not found' 错误

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

我想这里的快速修复是 this issue 的副本,正如下面的答案所述。

为了完整起见,假设我无法调用 'composer --prefer-dist' 我如何确保 docker 容器有 git 可用?

默认情况下,Composer 使用 dist(zip 文件)作为标记版本,使用 source(git 克隆)作为分支。由于您的目标是 master 分支作为依赖项,Composer 会首先尝试克隆存储库。您可以使用 --prefer-dist 开关覆盖此行为:

with:
  args: install --prefer-dist --no-dev

--prefer-dist: Reverse of --prefer-source, Composer will install from dist if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup.

https://getcomposer.org/doc/03-cli.md#install-i