Browse Source

Cache CI dependencies (#827)

Motivation:

The CI quite often fails because we get rate limited when downloading
protobuf from GitHub. Let's try sticking it in the Travis cache; it
still has to be downloaded from there but hopefully we won't get rate
limited.

Modifications:

- Cache protobuf
- Remove .build cache (the cache is currently *huge* and fetching this probably
  slows things down)

Result:

- Maybe fewer CI failures?
George Barnett 5 năm trước cách đây
mục cha
commit
bc51201399
2 tập tin đã thay đổi với 25 bổ sung8 xóa
  1. 24 7
      .travis-install.sh
  2. 1 1
      .travis.yml

+ 24 - 7
.travis-install.sh

@@ -31,6 +31,7 @@
 
 # Update .travis.yml if this changes.
 BIN_CACHE="$HOME"/bin_cache
+ZIP_CACHE="$HOME"/zip_cache
 
 PROTOBUF_VERSION=3.9.1
 # We need this to build gRPC C++ for the interop test server(s).
@@ -54,18 +55,33 @@ install_protoc() {
   echo -en 'travis_fold:start:install.protoc\\r'
   info "Installing protoc $PROTOBUF_VERSION"
 
-  # Install protoc
+  # Which protoc are we using?
   if [ "$TRAVIS_OS_NAME" = "osx" ]; then
-    PROTOC_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-osx-x86_64.zip
+    PROTOC_ZIP=protoc-${PROTOBUF_VERSION}-osx-x86_64.zip
   else
-    PROTOC_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
+    PROTOC_ZIP=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
   fi
 
-  info "Downloading protoc from: $PROTOC_URL"
-  curl -fSsL $PROTOC_URL -o protoc.zip
+  CACHED_PROTOC_ZIP="$ZIP_CACHE/$PROTOC_ZIP"
+
+  # Is it cached?
+  if [ ! -f "$CACHED_PROTOC_ZIP" ]; then
+    # No: download it.
+    PROTOC_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_ZIP}
+    info "Downloading protoc from: $PROTOC_URL"
+    if curl -fSsL "$PROTOC_URL" -o "$CACHED_PROTOC_ZIP"; then
+      info "Downloaded protoc from: $PROTOC_URL"
+    else
+      info "Downloading protoc failed, removing artifacts"
+      rm "$CACHED_PROTOC_ZIP"
+      exit 1
+    fi
+  else
+    info "Using cached protoc"
+  fi
 
-  info "Extracting protoc from protoc.zip"
-  unzip -q protoc.zip -d local
+  info "Extracting protoc from $CACHED_PROTOC_ZIP"
+  unzip -q "$CACHED_PROTOC_ZIP" -d local
   success "Installed protoc $PROTOBUF_VERSION"
   echo -en 'travis_fold:end:install.protoc\\r'
 }
@@ -169,6 +185,7 @@ build_grpc_cpp_server() {
 main() {
   cd
   mkdir -p local "$BIN_CACHE"
+  mkdir -p local "$ZIP_CACHE"
 
   install_protoc
   install_swift

+ 1 - 1
.travis.yml

@@ -87,8 +87,8 @@ stages:
 cache:
   apt: true
   directories:
-    - .build
     - $HOME/bin_cache
+    - $HOME/zip_cache
 
 addons:
   apt: