#!/bin/bash
mkdir -p release_5.5 || exit 1;
FIND_DIR=$(find -O3 $(pwd)/release_5.5 -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)/release_5.5/5.5.3-2-g9045368a9f-4833825/linux-debian13/bellesip|| exit 1;
mkdir -p $TEST_WORKSPACE_LOCATION || exit 1
PARENT_BRANCH=$(echo '')
if [[ $CREATED_COMMIT_REF_FOLDER = "YES" && -n $PARENT_BRANCH ]];
then
  LAST_MODIFIED_PATH=$(find -O3 $(pwd)/ -mindepth 5 -maxdepth 5 -type d -iregex '^.*//[0-9]+\.[0-9]+.*/linux-debian13/bellesip/allure-report/history$'| sort --version-sort --reverse | head -n 1)
  cp -r $LAST_MODIFIED_PATH $(pwd)/release_5.5/5.5.3-2-g9045368a9f-4833825/linux-debian13/bellesip/history;
else
  cp -r $(find -O3 $FIND_DIR/linux-debian13/bellesip/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)/release_5.5/quentin.arguillere/5.5.3-2-g9045368a9f-4833825/linux-debian13
ln -s $TEST_WORKSPACE_LOCATION $(pwd)/release_5.5/quentin.arguillere/5.5.3-2-g9045368a9f-4833825/linux-debian13
~/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
