背景
我们有一个 PHP project这与 Travis CI 配合得很好直到某一点,从那时起就完全停止工作了。该项目无法使用 Composer 进行构建。
详情
最后一次成功构建是: this one
最近失败的构建是:
this one, in the branch Naming Collisions
这是this commit
不断出现的错误是:
Failed to execute git clone --mirror 'git@github.com:edmondscommerce/Faker.git' '/home/travis/.composer/cache/vcs/git-github.com-edmondscommerce-Faker.git/'
最新分支是NamingCollisions
, 这是 latest commit
通知在composer.json我们正在使用 fork对于Faker library :
"repositories": [
{
"type": "vcs",
"url": "https://github.com/edmondscommerce/Faker.git"
}
],
这一切都适用于我们的本地测试,它只在 Travis 中失败。
我们尝试过的事情:
刷新 Travis 缓存
在执行安装之前清除 Composer 缓存 -
.travis.bash
添加:
"github-protocols": ["https"]
- 希望它会消失...
到目前为止运气不好。
不幸的是,我们现在只是在本地测试并忽略了 Travis,因为它现在一直在失败,即使代码运行良好。
希望你们中的一位读者能帮助解决这个问题!
我们做了什么
最后我们决定按照 Everon 的建议将 "no-api": true
添加到 repositories
配置中。
这会强制 Composer 不再使用 github API (docs):
If you set the no-api key to true on a github repository it will clone the repository as it would with any other git repository instead of using the GitHub API.
最佳答案
我查看了这个,这不是 Travis 本身的问题。
在查看 Travis 并在 Docker 实例中本地运行 Travis 环境后,我能够重现该问题。
Travis 提示它无法通过 Github 进行身份验证。
您需要使用 Travis 环境变量,该变量随后可用于设置访问 token ,以便 Composer 可以执行安装 Faker 的 VCS 存储库分支所需的操作。
您可以在 Travis 的存储库设置中定义该变量,然后它可以作为标准 Bash 变量在您的 travis before_script
数组或您的 shell 脚本中使用。
构建日志中的 token :
Setting environment variables from repository settings
$ export GITHUB_TOKEN=[secure]
您在此处定义所需的访问 token : https://github.com/settings/tokens/new?scopes=repo
然后可以像这样在之前的脚本中设置它:
before_script:
- composer config github-oauth.github.com ${GITHUB_TOKEN};
- bash -x .travis.bash
另一种选择是将“no-api”添加到您的 Faker 分支 - 见下文。
...
"repositories": [
{
"type": "vcs",
"url": "https://github.com/edmondscommerce/Faker.git",
"no-api": true
}
]
...
构建(失败但已超过您遇到的问题) https://travis-ci.org/everon/doctrine-static-meta/jobs/352620456
关于php - Travis CI 构建 PHP 项目并从 Composer 中提取依赖项,尝试使用 git@ 而不是 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49175167/