代码之家  ›  专栏  ›  技术社区  ›  edmondscommerce

Travis CI构建PHP项目并从Composer中提取依赖项,尝试使用git@而不是https

  •  4
  • edmondscommerce  · 技术社区  · 8 年前

    出身背景

    我们有一个 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"]
    

    到 创作者json

    • 希望它会消失。。。

    目前没有运气。

    不幸的是,我们现在只是在本地进行测试,而忽略了Travis,因为即使代码运行良好,它现在仍然不断失败。

    希望你们中的一位读者能帮我解决这个问题!

    我们一起去的

    最后,我们决定添加 "no-api": true 到 repositories 按照Evron的建议进行配置。

    这将迫使composer不再使用github API( docs ):

    如果在github存储库上将no-api键设置为true,那么它将克隆存储库,就像克隆任何其他git存储库一样,而不是使用github api。

    1 回复  |  直到 7 年前
        1
  •  4
  •   Everon    8 年前

    我看了一下,这与特拉维斯本身无关。

    在查看Travis并在Docker实例中本地运行Travis环境后,我能够重现该问题。

    Travis抱怨它无法通过Github进行身份验证。

    您需要使用Travis环境变量来设置访问令牌,以便Composer可以执行安装Faker的VCS存储库fork所需的操作。

    您可以在Travis中的存储库设置中定义该变量,然后它可以作为标准Bash变量在Travis中使用 before_script 数组或在shell脚本中。

    生成日志中的令牌:

    Setting environment variables from repository settings
    $ export GITHUB_TOKEN=[secure]
    

    您可以在此处定义所需的访问令牌: https://github.com/settings/tokens/new?scopes=repo

    然后可以在before脚本中进行如下设置:

    before_script:
      - composer config github-oauth.github.com ${GITHUB_TOKEN};
      - bash -x .travis.bash
    

    另一种选择是向Faker fork添加“无api”-见下文。

    ...
    "repositories": [
        {
          "type": "vcs",
          "url": "https://github.com/edmondscommerce/Faker.git",
          "no-api": true
        }
    ]
    ...
    

    生成(失败,但已超过您遇到的问题点) https://travis-ci.org/everon/doctrine-static-meta/jobs/352620456