1bf215546Sopenharmony_ci#!/usr/bin/env bash 2bf215546Sopenharmony_ci 3bf215546Sopenharmony_ciFOSSILS_SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" 4bf215546Sopenharmony_ciFOSSILS_YAML="$(readlink -f "$1")" 5bf215546Sopenharmony_ciFOSSILS_RESULTS="$2" 6bf215546Sopenharmony_ci 7bf215546Sopenharmony_ciclone_fossils_db() 8bf215546Sopenharmony_ci{ 9bf215546Sopenharmony_ci local repo="$1" 10bf215546Sopenharmony_ci local commit="$2" 11bf215546Sopenharmony_ci rm -rf fossils-db 12bf215546Sopenharmony_ci git clone --no-checkout "$repo" fossils-db 13bf215546Sopenharmony_ci (cd fossils-db; git reset "$commit" || git reset "origin/$commit") 14bf215546Sopenharmony_ci} 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_ciquery_fossils_yaml() 17bf215546Sopenharmony_ci{ 18bf215546Sopenharmony_ci python3 "$FOSSILS_SCRIPT_DIR/query_fossils_yaml.py" \ 19bf215546Sopenharmony_ci --file "$FOSSILS_YAML" "$@" 20bf215546Sopenharmony_ci} 21bf215546Sopenharmony_ci 22bf215546Sopenharmony_cicreate_clean_git() 23bf215546Sopenharmony_ci{ 24bf215546Sopenharmony_ci rm -rf .clean_git 25bf215546Sopenharmony_ci cp -R .git .clean_git 26bf215546Sopenharmony_ci} 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_cirestore_clean_git() 29bf215546Sopenharmony_ci{ 30bf215546Sopenharmony_ci rm -rf .git 31bf215546Sopenharmony_ci cp -R .clean_git .git 32bf215546Sopenharmony_ci} 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cifetch_fossil() 35bf215546Sopenharmony_ci{ 36bf215546Sopenharmony_ci local fossil="${1//,/?}" 37bf215546Sopenharmony_ci echo -n "[fetch_fossil] Fetching $1... " 38bf215546Sopenharmony_ci local output=$(git lfs pull -I "$fossil" 2>&1) 39bf215546Sopenharmony_ci local ret=0 40bf215546Sopenharmony_ci if [[ $? -ne 0 || ! -f "$1" ]]; then 41bf215546Sopenharmony_ci echo "ERROR" 42bf215546Sopenharmony_ci echo "$output" 43bf215546Sopenharmony_ci ret=1 44bf215546Sopenharmony_ci else 45bf215546Sopenharmony_ci echo "OK" 46bf215546Sopenharmony_ci fi 47bf215546Sopenharmony_ci restore_clean_git 48bf215546Sopenharmony_ci return $ret 49bf215546Sopenharmony_ci} 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ciif [[ -n "$(query_fossils_yaml fossils_db_repo)" ]]; then 52bf215546Sopenharmony_ci clone_fossils_db "$(query_fossils_yaml fossils_db_repo)" \ 53bf215546Sopenharmony_ci "$(query_fossils_yaml fossils_db_commit)" 54bf215546Sopenharmony_ci cd fossils-db 55bf215546Sopenharmony_cielse 56bf215546Sopenharmony_ci echo "Warning: No fossils-db entry in $FOSSILS_YAML, assuming fossils-db is current directory" 57bf215546Sopenharmony_cifi 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci# During git operations various git objects get created which 60bf215546Sopenharmony_ci# may take up significant space. Store a clean .git instance, 61bf215546Sopenharmony_ci# which we restore after various git operations to keep our 62bf215546Sopenharmony_ci# storage consumption low. 63bf215546Sopenharmony_cicreate_clean_git 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_cifor fossil in $(query_fossils_yaml fossils) 66bf215546Sopenharmony_cido 67bf215546Sopenharmony_ci fetch_fossil "$fossil" || exit $? 68bf215546Sopenharmony_ci fossilize-replay --num-threads 4 $fossil 1>&2 2> $FOSSILS_RESULTS/fossil_replay.txt 69bf215546Sopenharmony_ci if [ $? != 0 ]; then 70bf215546Sopenharmony_ci echo "Replay of $fossil failed" 71bf215546Sopenharmony_ci grep "pipeline crashed or hung" $FOSSILS_RESULTS/fossil_replay.txt 72bf215546Sopenharmony_ci exit 1 73bf215546Sopenharmony_ci fi 74bf215546Sopenharmony_ci rm $fossil 75bf215546Sopenharmony_cidone 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ciexit $ret 78