【问题标题】:Why Travis CI can't connect to GitHub API?为什么 Travis CI 无法连接到 GitHub API?
【发布时间】:2015-09-25 10:16:31
【问题描述】:

我正在 Travis CI 中为我的 build 运行以下命令:

before_install:
  - curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

script:
  - sudo composer -nqq update

我正在手动安装composer,因为我想使用sudo,因为它只为用户安装。

我遇到的错误是:

Updating dependencies (including require-dev)
  - Installing jakub-onderka/php-console-color (0.1)
    Downloading: Connecting...    Failed to download jakub-onderka/php-console-color from dist: The "https://api.github.com/repos/JakubOnderka/PHP-Console-Color/zipball/e0b393dacf7703fc36a4efc3df1435485197e6c1" file could not be downloaded (HTTP/1.1 403 Forbidden)
    Now trying to download from source

  - Installing symfony/yaml (v2.7.4)
    Downloading: Connecting...    Failed to download symfony/yaml from dist: The "https://api.github.com/repos/symfony/Yaml/zipball/2dc7b06c065df96cc686c66da2705e5e18aef661" file could not be downloaded (HTTP/1.1 403 Forbidden)
    Now trying to download from source

我已经尝试了这些链接,它们工作正常。

这是否意味着 Travis 出于某种原因阻止了 GitHub API?如果没有,我该如何解决?

通过修复,我的意思是要么知道发生了什么,要么抑制这些错误消息(例如,通过使用 composer 中的一些特殊参数或更改 JSON 文件以强制从源下载)。

我的composer.json 文件是:

{
    "config": {
        "vendor-dir": "/var/lib/vendor",
        "bin-dir": "/usr/local/bin"
    },
    "require": {
        "drush/drush": "dev-master"
    }
}

作为参考,完整的.travis.yml 看起来像:

before_install:
  - env
  - curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
  - sudo apt-get -qy update
install:
  - sudo apt-get install vagrant
script:
  - set -e # This makes build to fail on first error.
  - sudo composer -nqq update
  - make
  - make vm
after_failure:
 - sudo apt-get -qy install tree && - tree -d -L 6 # Print directory structure in the form of a tree.
 - env
sudo: true
language: php
python:
  - "5.5"

【问题讨论】:

    标签: continuous-integration composer-php travis-ci http-status-code-403 github-api


    【解决方案1】:

    错误的最可能原因是从 github 下载的数量有限。您需要做的是在您的 github 帐户中 create a token 并使用

    将其全局添加到您的作曲家

    composer config -g github-oauth.github.com <your-token>

    来源:https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens

    【讨论】:

      【解决方案2】:

      我的建议是:

      删除:

      • curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
      • sudo composer -nqq update

      第一行:不需要,因为 Composer 是预装的,当你使用language: php时。

      第二行:最好执行composer install,因为update 使用来自composer.lock 的数据,如果你的repo 包含一个。而且这里不需要 sudo。

      (关于在 Travis-CI 上使用 sudo 的旁注: sudo 仅在基于非容器的基础架构中可用。我不知道你是否真的需要这个,但也许你可以通过在travis.yml 中设置sudo: false 来切换到更快的基于容器的基础设施,请参阅http://docs.travis-ci.com/user/workers/container-based-infrastructure/。只是一个提示。)


      添加到travis.yml

      before_install:
        - composer self-update
        - composer install --no-interaction --optimize-autoloader
      

      第一行:更新这个 Travis 实例的(可能)过时的作曲家。

      第二行:使用 Composer 安装 composer.json 中描述的依赖项。


      在下载“Dist”或下载“Source”之间切换的附加参数是--prefer-dist--prefer-source

      所以它要么

      • - composer install --prefer-dist --no-interaction --optimize-autoloader

      • - composer install --prefer-source --no-interaction --optimize-autoloader

      这是否意味着 Travis 出于某种原因阻止了 GitHub API?

      如果不是临时问题,那么您的 Composer 似乎遇到了 Github API 速率限制。 GitHub API 只允许未经身份验证的用户的少量请求。您可以通过 Travis 在 Github 上进行身份验证来提高 API 限制。

      查看常见问题解答:https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens

      请先尝试prefer-source

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-15
        • 2017-10-09
        • 2015-03-28
        • 2018-03-14
        相关资源
        最近更新 更多