-
Notifications
You must be signed in to change notification settings - Fork 15
/
run_cacher.sh
executable file
·118 lines (93 loc) · 4.26 KB
/
run_cacher.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
# Get the absolute path to the directory containing this script. Source: https://stackoverflow.com/a/246128.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Include common functions and constants.
source "${SCRIPT_DIR}"/common.sh
STAGE='Cache Artifact Dependencies'
USAGE='Usage: bash run_cacher.sh --ci <ci> -i <input-json> [-t <threads>] [-c <component-directory>] [--no-push] [-a "<caching-args>"]'
# Extract command line arguments.
OPTS=$(getopt -o c:i:t:a: --long component-directory:,input-json:,threads:,no-push,caching-args:,ci: -n 'run-cacher' -- "$@")
if [[ $? -ne 0 ]]; then
echo "$USAGE"
exit 1
fi
eval set -- "$OPTS"
while true; do
case "$1" in
# Shift twice for options that take an argument.
-c | --component-directory ) component_directory="$2"; shift; shift ;;
-i | --input-json ) input_json="$(realpath "$2")"; shift; shift ;;
-t | --threads ) threads="$2"; shift; shift ;;
--no-push ) no_push='--no-push'; shift ;;
-a | --caching-args ) caching_args="$2"; shift; shift ;;
--ci ) ci_service="$2"; shift; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
# Perform checks and set defaults for command line arguments.
if [[ ${ci_service} != 'travis' && ${ci_service} != 'github' ]]; then
echo '--ci must be one of "travis" or "github". Exiting.'
exit 1
fi
if [[ ! -f "${input_json}" ]]; then
echo "$input_json is not a file. Exiting."
exit 1
fi
if [[ -z "${threads}" ]]; then
echo 'The number of threads is not specified. Defaulting to 1 thread.'
threads=1
fi
if [[ -z "${component_directory}" ]]; then
component_directory="$SCRIPT_DIR"
elif [[ -d "${component_directory}" ]]; then
component_directory="$(realpath "${component_directory}")"
else
echo "The path '${component_directory}' does not exist or is not a directory. Exiting."
exit 1
fi
if [[ ${no_push} ]]; then
TOTAL_STEPS=1 # CacheDependency
else
TOTAL_STEPS=4 # CacheDependency, MetadataPackager, ArtifactLogPackager, ArtifactDiffAdder
fi
# The task name is the basename of the input JSON file, without the extension.
task_name="$(basename "${input_json%.*}")"
reproducer_dir="${component_directory}/${ci_service}-reproducer"
cache_dep_dir="${component_directory}/${ci_service}-cacher"
# Check for existence of the required repositories.
check_repo_exists "${reproducer_dir}" 'reproducer'
check_repo_exists "${cache_dep_dir}" 'cache-dependency'
print_step "${STAGE}" ${TOTAL_STEPS} 'CacheDependency'
cd "${reproducer_dir}"
echo "Running: python3 get_reproducer_output.py -i $input_json -o $task_name"
python3 get_reproducer_output.py -i "${input_json}" -o "${task_name}"
cacher_input_file="${reproducer_dir}/input/${task_name}"
if [[ ! -s $cacher_input_file ]]; then
print_red "$cacher_input_file does not exist or is empty."
print_red "Either all reproducible artifacts have been cached, or there were no reproducible artifacts to begin with."
print_red "Exiting."
exit
fi
echo
echo 'Attempting to cache the following artifacts:'
cat "${reproducer_dir}/input/${task_name}"
cd "${cache_dep_dir}"
echo
echo "Running: python3 entry.py ${cacher_input_file} ${task_name} --workers ${threads} --task-json ${input_json} ${no_push} ${caching_args}"
python3 entry.py "${cacher_input_file}" "${task_name}" --workers "${threads}" --task-json "${input_json}" ${no_push} ${caching_args}
exit_if_failed 'CacheDependency encountered an error.'
if [[ ! ${no_push} ]]; then
cd "${reproducer_dir}"
# MetadataPackager (push artifact metadata to the database)
print_step "${STAGE}" ${TOTAL_STEPS} 'MetadataPackager'
python3 packager.py -i "output/result_json/${task_name}.json"
exit_if_failed 'MetadataPackager encountered an error.'
print_step "${STAGE}" ${TOTAL_STEPS} 'ArtifactLogPackager'
python3 add_artifact_logs.py "${task_name}"
exit_if_failed 'ArtifactLogPackager encountered an error.'
print_step "${STAGE}" ${TOTAL_STEPS}, 'ArtifactDiffAdder'
python3 add_artifact_diffs.py -j "${input_json}" -c "${cacher_output_path}" -p "${repo_clone_path}"
exit_if_failed 'ArtifactDiffAdder encountered an error.'
fi
print_stage_done "${STAGE}"