#!/bin/bash
mkdir -p fix_prevent_dtmf_stream_from_removing_vibrate_only_mode || exit 1;
FIND_DIR=$(find -O3 $(pwd)/fix_prevent_dtmf_stream_from_removing_vibrate_only_mode -mindepth 1 -maxdepth 1 -type d -iregex '^.*[0-9]+\.[0-9]+.*$' | sort --version-sort --reverse | head -n 1)
if [[ -n $FIND_DIR ]];
  then CREATED_COMMIT_REF_FOLDER="NO"
else
  CREATED_COMMIT_REF_FOLDER="YES"
fi
TEST_WORKSPACE_LOCATION=$(pwd)/fix_prevent_dtmf_stream_from_removing_vibrate_only_mode/5.5.0-beta-98-g9f597c7bce-4669862/linux-rocky8/liblinphone|| exit 1;
mkdir -p $TEST_WORKSPACE_LOCATION || exit 1
PARENT_BRANCH=$(echo 'release_5.5')
if [[ $CREATED_COMMIT_REF_FOLDER = "YES" && -n $PARENT_BRANCH ]];
then
  LAST_MODIFIED_PATH=$(find -O3 $(pwd)/release_5.5 -mindepth 5 -maxdepth 5 -type d -iregex '^.*/release_5.5/[0-9]+\.[0-9]+.*/linux-rocky8/liblinphone/allure-report/history$'| sort --version-sort --reverse | head -n 1)
  cp -r $LAST_MODIFIED_PATH $(pwd)/fix_prevent_dtmf_stream_from_removing_vibrate_only_mode/5.5.0-beta-98-g9f597c7bce-4669862/linux-rocky8/liblinphone/history;
else
  cp -r $(find -O3 $FIND_DIR/linux-rocky8/liblinphone/allure-report/history -maxdepth 0) $TEST_WORKSPACE_LOCATION/history;
fi;
mv $(pwd)/environment.properties $TEST_WORKSPACE_LOCATION && mv $(pwd)/BCUnit* $TEST_WORKSPACE_LOCATION
mkdir -p $(pwd)/fix_prevent_dtmf_stream_from_removing_vibrate_only_mode/SylvainBerfini/5.5.0-beta-98-g9f597c7bce-4669862/linux-rocky8
ln -s $TEST_WORKSPACE_LOCATION $(pwd)/fix_prevent_dtmf_stream_from_removing_vibrate_only_mode/SylvainBerfini/5.5.0-beta-98-g9f597c7bce-4669862/linux-rocky8
~/allure-2.16.1/bin/allure generate --clean $TEST_WORKSPACE_LOCATION -o $TEST_WORKSPACE_LOCATION/allure-report
pwd
ls -lah
du -h $TEST_WORKSPACE_LOCATION
rm -r $TEST_WORKSPACE_LOCATION/history || echo 'deletion of temp history failed. History could not be gathered ?'
du -h $TEST_WORKSPACE_LOCATION
