Select Git revision
gatekeeperd.te
run.sh 2.30 KiB
#!/usr/bin/env bash
set -e -u -x -o pipefail
#
# Run QIR, add results to logs.json, prune old log files
#
# the current start date
QIR_CURRENT_RUN=$(date --rfc-3339=date)
# the base directory for logs
LOGS_BASE_DIR="./web/logs/"
# the name of the logs directory we are using in this run
LOGS_DIR_NAME="logs_sat_${QIR_CURRENT_RUN}"
# the path of the logs directory we are using in this run
LOGS_DIR="${LOGS_BASE_DIR}/${LOGS_DIR_NAME}/"
# the path of the latest logs directory symlink
LATEST_LOGS_DIR="${LOGS_BASE_DIR}/latest"
# the temporary result json file
RESULT_JSON_TMP="${LOGS_BASE_DIR}/result-${QIR_CURRENT_RUN}.json"
# the final destination of the result json file of this run
RESULT_JSON="${LOGS_DIR}/result.json"
# the json file that includes a list of log directory names of the last runs
LOGS_JSON="${LOGS_BASE_DIR}/logs.json"
# amount of runs to keep
KEEP_LAST=10
# run test cases T,SAT,SATL with debug output
# write result json to a file outside the log directory
# (QIR in master does not support writing it directly to log directory)
./.venv/bin/python3 ./run.py \
-d \
-t terrestrial,sat,satloss \
-l "${LOGS_DIR}" \
-j "${RESULT_JSON_TMP}"
# just to be safe
mkdir -p "${LOGS_DIR}"
# move the result.json to its target location inside the log directory
mv "${RESULT_JSON_TMP}" "${RESULT_JSON}"
# replace the log dir in result.json (this replacement makes no sense, but the official runner uses the basename, too)
jq ".log_dir=\"${LOGS_DIR_NAME}\"" < "${RESULT_JSON}" | sponge "${RESULT_JSON}"
# use last 10 entries and add current log dir
if [[ -e "${LOGS_JSON}" ]]; then
jq ".[-${KEEP_LAST}:] + [\"${LOGS_DIR_NAME}\"]" < "${LOGS_JSON}" | sponge "${LOGS_JSON}"
else
echo "[\"${LOGS_DIR_NAME}\"]" > "${LOGS_JSON}"
fi
# update latest symlink
rm -f "${LATEST_LOGS_DIR}"
ln -s "${LOGS_DIR_NAME}" "${LATEST_LOGS_DIR}"
# prune log files
while IFS= read -r -d '' dir
do
dir_name=$(basename "${dir}")
if grep -q -F "\"${dir_name}\"" "${LOGS_JSON}"; then
# $dir_name is in logs.json
echo "keeping ${dir_name}"
else
# $dir_name is not in logs.json -> delete logs (but keep result.json)
echo "pruning logs in ${dir_name}"
find "${dir}" -mindepth 1 -maxdepth 1 -type d -delete
fi
done < <(find ./web/logs -maxdepth 1 -mindepth 1 -type d -print0)
echo "Done"