-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup-benchmarks.sh
executable file
·78 lines (66 loc) · 2.91 KB
/
setup-benchmarks.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# A helper script to setup or update the repositories containing benchmark models under `benchmarks/`
set -eo pipefail
# Commit SHA for each repository:
REF_TIMES_model="b488fb07f0899ee8b7e710c230b1a9414fa06f7d"
REF_demos_xlsx="34a2a5c044cc0bbea1357de50db2f5f02d575181"
REF_demos_dd="2848a8a8e2fdcf0cdf7f83eefbdd563b0bb74e86"
REF_tim="e820d8002adc6b1526a3bffcc439219b28d0eed5"
REF_tim_gams="703f6a4e1d0bedd95c3ebdae534496f3a7e1b7cc"
REF_TIMES_NZ="d6d7b14f43a89ceca7c4e77ba9122a2c757cdae3"
# If no GitHub token is provided, try to clone using SSH
if [ -z "$GH_PAT_DEMOS_XLSX" ]; then
echo "Warning: no GitHub token provided, will try to clone private repos using SSH"
use_SSH=1
fi
# Move to the directory containing this script
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"
mkdir -p benchmarks
# Function to check out a repository at a specified commit
checkout_repo() {
local repo=$1
local dest_dir=$2
local commit=$3
local private=$4
if [ -d "$dest_dir" ]; then
echo "Directory $dest_dir already exists. Checking if on correct commit."
pushd "$dest_dir" > /dev/null
git fetch --depth=1 origin "$commit"
else
echo "Directory $dest_dir does not exist. Cloning repository."
if [ -n "$private" ]; then
if [ -n "$use_SSH" ]; then
repo_url="[email protected]:${repo}.git"
else
repo_url="https://[email protected]/${repo}/"
fi
else
repo_url="https://github.com/${repo}/"
fi
git clone --filter=blob:none "$repo_url" "$dest_dir"
pushd "$dest_dir" > /dev/null
fi
git checkout "$commit" || exit 1
popd > /dev/null
echo "$dest_dir: successfully checked out $repo at $commit"
}
# Array of repositories to check out, in the form repo|dest_dir|commit|private
repositories=(
"etsap-TIMES/TIMES_model|TIMES_model|$REF_TIMES_model"
"olejandro/demos-dd|benchmarks/dd|$REF_demos_dd"
"olejandro/demos-xlsx|benchmarks/xlsx|$REF_demos_xlsx|true"
"esma-cgep/tim|benchmarks/xlsx/Ireland|$REF_tim"
"esma-cgep/tim-gams|benchmarks/dd/Ireland|$REF_tim_gams"
"olejandro/TIMES-NZ-Model-Files|benchmarks/TIMES-NZ|$REF_TIMES_NZ"
)
# Setup / update the repositories
for repo_info in "${repositories[@]}"; do
IFS='|' read -r repo dest_dir commit private <<< "$repo_info"
checkout_repo "$repo" "$dest_dir" "$commit" "$private"
done
# Create symlinks for TIMES-NZ since xlsx & dd files are in same repo
ln -s "$SCRIPT_DIR/benchmarks/TIMES-NZ/TIMES-NZ" "$SCRIPT_DIR/benchmarks/xlsx/TIMES-NZ"
ln -s "$SCRIPT_DIR/benchmarks/TIMES-NZ/TIMES-NZ-GAMS/times_scenarios/kea-v2_1_3" "$SCRIPT_DIR/benchmarks/dd/TIMES-NZ-KEA"
ln -s "$SCRIPT_DIR/benchmarks/TIMES-NZ/TIMES-NZ-GAMS/times_scenarios/tui-v2_1_3" "$SCRIPT_DIR/benchmarks/dd/TIMES-NZ-TUI"
echo "All benchmark repositories are set up and up to date :)"