为什么Travis CI无法连接到GitHub API?

问题描述:

我跑在特拉维斯CI以下命令我build为什么Travis CI无法连接到GitHub API?

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

script: 
    - sudo composer -nqq update 

我手动安装作曲家我想用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" 

我的建议是:

删除:

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

第一行:不需要的,因为作曲家是预安装,当您使用language: php

第二行:它更好地执行composer install,因为update使用的数据来自composer.lock,如果您的回购包含一个。这里不需要sudo。

(上sudo上特拉维斯-CI使用旁注: 须藤只有在非containainer基础架构可我不知道你是否真的需要这一点,但也许你可以切换到基于更快的容器infrastrucutre通过在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 

第一line:更新此Travis实例(可能)过时的作曲家。

第二行:在Composer中安装composer.json中描述的依赖关系。


的其他参数,以下载“DIST”或下载“源”是--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先试用一下。

错误的最可能原因是来自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