Travis 設定 Github Access Token

Problem

Travis 在 run composer install 會出現類似以下錯誤:

1
2
3
4
5
Failed to clone the git@github.com:jquery/jquery-dist.git repository, try running in interactive mode so that you can enter your GitHub credentials

[Composer\Repository\InvalidRepositoryException]
No valid bower.json was found in any branch or tag of https://github.com/jq
uery/jquery-dist.git, could not load a package from it.

失敗的 repository 不一定,可能這次 jquery 下次別的。

找了一陣,說是踩到 Github 的 rate limit(我理解是 composer install 會一直從 github 抓東西所以容易踩到),但又有文章說這個問題已經被修正。我還是踩到了啊

Solution

  1. 在 Github 產生 Personal access token
  2. 在 Travis 設定有使用 Travis 的 project 的環境變數(environment variable),指定變數名稱,值是剛剛在 Github 產生的 access token。
  3. 修改 .travis.yml,在 composer install 前加入 composer config github-oauth.github.com ${環境變數名稱}

Ref