aboutsummaryrefslogtreecommitdiff
path: root/.jenkins/get_cache.sh
blob: a589bd2101e9ad7b18b3f829b1e12f0f2875695f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash

# Validating number of arguments
if [ "$#" -ne 2 ]; then
    echo "Expected 2 arguments"
    echo "Syntax: ./get_cache.sh <PR_NUMBER> <BRANCH>"
    echo "Use PR_NUMBER=0 if not a PR"
    exit 1
fi

RELEASE=$(lsb_release -c -s)
PYTHON_VERSION=$(python -c "import sys; print('py%d%d' % (sys.version_info.major, sys.version_info.minor))")

# Trying to download PR cache
if [ "$1" != "0" ]; then
    CACHE_FILE="cache-pr_$1-$PYTHON_VERSION-$RELEASE.zip"
    CACHE_PATH="gs://ppaquette-diplomacy/cache-jenkins/game-$CACHE_FILE"
    gsutil -q stat "$CACHE_PATH"
    RET_VALUE=$?

    if [ $RET_VALUE == 0 ]; then
        echo "Downloading cache from $CACHE_PATH"
        gsutil cp $CACHE_PATH .
        unzip -qo $CACHE_FILE -d /
        exit 0
    else
        echo "No cache found at $CACHE_PATH"
    fi
fi

# Trying to download branch cache
CACHE_FILE="cache-$2-$PYTHON_VERSION-$RELEASE.zip"
CACHE_PATH="gs://ppaquette-diplomacy/cache-jenkins/game-$CACHE_FILE"
gsutil -q stat "$CACHE_PATH"
RET_VALUE=$?

if [ $RET_VALUE == 0 ]; then
    echo "Downloading cache from $CACHE_PATH"
    gsutil cp $CACHE_PATH .
    unzip -qo $CACHE_FILE -d /
    exit 0
else
    echo "No cache found at $CACHE_PATH"
fi