pre_cache.sh 999 Bytes
Newer Older
Denis_P's avatar
Denis_P committed
1
2
3
4
5
6
7
#!/bin/bash

set -u

# if there is no directory for this $CI_COMMIT_REF_NAME/$CI_JOB_NAME
# create such directory and
# copy recursively all the files from the newest dir which has $CI_JOB_NAME, if it exists
Denis_P's avatar
Denis_P committed
8

9
# cache lives in /ci-cache/${CI_PROJECT_NAME}/${2}/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}
Denis_P's avatar
Denis_P committed
10
11
12
13
14
15
16
17
18
19
20
21

function prepopulate {
  if [[ ! -d $1 ]]; then
    mkdir -p "/ci-cache/$CI_PROJECT_NAME/$2/$CI_COMMIT_REF_NAME";
    FRESH_CACHE=$(find "/ci-cache/$CI_PROJECT_NAME/$2" -mindepth 2 -maxdepth 2 \
      -type d -name "$CI_JOB_NAME"  -exec stat --printf="%Y\t%n\n" {} \; |sort -n -r |head -1 |cut -f2);
    if [[ -d $FRESH_CACHE ]]; then
      echo "____Using" "$FRESH_CACHE" "to prepopulate the cache____";
      time cp -r "$FRESH_CACHE" "$1";
    else
      echo "_____No such $2 dir, proceeding from scratch_____";
    fi
Denis_P's avatar
Denis_P committed
22
  else
Denis_P's avatar
Denis_P committed
23
    echo "____No need to prepopulate $2 cache____";
Denis_P's avatar
Denis_P committed
24
  fi
Denis_P's avatar
Denis_P committed
25
26
}

27
# CARGO_HOME cache is still broken so would be handled some other way.
Denis_P's avatar
Denis_P committed
28
prepopulate "$CARGO_TARGET_DIR" targets