Bazel 是个好用的编译工具,但是如果处在一个共享IP的环境,经常会遇到如下错误:

1
2
$ bazel                   
2020/08/31 17:10:27 could not resolve the version 'latest' to an actual version number: could not get releases from github.com/bazelbuild/bazel: could not download list of Bazel releases from github.com/bazelbuild: unexpected status code while reading https://api.github.com/repos/bazelbuild/bazel/releases: 403

导致编译过程受阻,非常麻烦。

原理

出现这个问题的原因是:

1
2
curl https://api.github.com/repos/bazelbuild/bazel/releases
{"message":"API rate limit exceeded for 100.101.102.103. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://developer.github.com/v3/#rate-limiting"}

说白了就是你和别人共用了 100.101.102.103 作为共用的出口代理,这个出口命中限流了。

解决方法

登陆 github

点击▽-Settings-Personal access tokens

点击 Generate-now-token 按钮,生成一个新的 token,譬如起名bazel

check box不用选,这个地方不需要什么权限。

export BAZELISK_GITHUB_TOKEN=37493ba********f32d4c4 添加到你的 .bash_profile 文件结尾:

1
2
echo 'export BAZELISK_GITHUB_TOKEN=37493ba********f32d4c4' >> ~/.bash_profile
source .bash_profile

然后就好了。

1
2
3
4
5
6
7
bazel version
Bazelisk version: v1.3.0
Build label: 3.4.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jul 14 06:32:14 2020 (1594708334)
Build timestamp: 1594708334
Build timestamp as int: 1594708334