This repository has been archived by the owner on Nov 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdocker-entrypoint.sh
executable file
·134 lines (124 loc) · 3.56 KB
/
docker-entrypoint.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
export RESET="\e[0m"
export CYAN="\e[36m"
export RED="\e[31m"
export BOLD"=\e[1m"
export YELLOW="\e[93m"
WS_PATH="/home/root/ros2_ws"
HRIM_FULL_PATH="/home/root/ros2_ws/src/hrim"
HRIM_FULL_GENERATED_PATH="/home/root/ros2_ws/src/hrim/generated"
INSTALLATOR_PATH="${HRIM_FULL_PATH}/installator"
ROS2_SOURCE="/opt/ros/${ROS2_DISTRO}/setup.bash"
MODULES_SCHEMA="${HRIM_FULL_PATH}/models/schemas/module.xsd"
TEST_LOG_PATH=""
function installDependencies()
{
echo -e "${CYAN}Checking for missing dependencies${RESET}"
apt update -qq
rosdep update -q
rosdep install -q -y --from-paths "${HRIM_FULL_PATH}" --rosdistro "${ROS2_DISTRO}" --as-root=apt:false || true
echo -e "${CYAN}All dependencies installed!${RESET}"
}
function validateSchemas()
{
echo -e "${CYAN}Validating xml files!${RESET}"
XML_FILES=$(find -name "*.xml" -not -path "./src/hrim/datasheet_generator/*" "./src/hrim/datasheet_templates/*" | grep -v topics | grep -v dataMapping | grep -v package.xml)
ERROR_XML=( )
index=0
for i in ${XML_FILES}; do
xmllint --schema ${MODULES_SCHEMA} "${i}" --noout --xinclude 2>/dev/null
result=$?
if [ ${result} -ne 0 ]; then
ERROR_XML[index]=$i
index=$((index+1))
fi
done
if [ "${#ERROR_XML[@]}" -gt 0 ]; then
for i in "${ERROR_XML[@]}"; do
echo "Error on file: ${i}"
done
echo -e "${RED}Number of fails: ${#ERROR_XML[@]}${RESET}"
exit 1
else
echo -e "${CYAN}All xml files validated!${RESET}"
fi
}
function qaCode()
{
echo -e "${CYAN}Linter checks for python code, using: pep8 ${BOLD}$(pep8 --version)${RESET}"
pep8 ${INSTALLATOR_PATH}/hrim/
result=$?
if [ $result -ne 0 ]; then
echo "${RED}pep8 error/s found, please review it!${RESET}"
exit 2
else
echo -e "${CYAN}No pep8 errors found!${RESET}"
fi
}
function installHRIM()
{
echo -e "${CYAN}Installing HRIM command line utility${RESET}"
cd ${INSTALLATOR_PATH} || exit
pip3 install -r requirements.txt
python3 setup.py install
result=$?
if [ $result -eq 0 ]; then
echo -e "${CYAN}HRIM tool successfully installed!${RESET}"
else
echo -e "${RED}Failed to install HRIM tool!${RESET}"
exit 3
fi
}
function generatePackages()
{
cd ${HRIM_FULL_PATH} || exit
hrim generate --platform ros2 all
result=$?
if [ $result -eq 0 ]; then
echo -e "${CYAN}All packages generated successfully!${RESET}"
else
echo -e "${RED} Error creating the packages, please review it!${RESET}"
exit 4
fi
}
function compileWS()
{
echo -e "${CYAN}Compiling the work space for HRIM!${RESET}"
source "${ROS2_SOURCE}"
cd ${WS_PATH} || exit
colcon build --merge-install --cmake-args -DHRIM_DIRECTORY=${HRIM_FULL_GENERATED_PATH}
result=$?
if [ $result -eq 0 ]; then
echo -e "${CYAN}ROS2 ws compiled successfully!${RESET}"
else
echo -e "${RED}Failed to build ROS2 ws, please review it!${RESET}"
exit 5
fi
}
function testWorkspace()
{
echo -e "${CYAN}Testing the work space${RESET}"
cd ${WS_PATH} || exit
colcon test --merge-install --packages-select hrim_qa
TEST_FAILURES=$(grep -HiRE '\(FAILED\)' ${TEST_LOG_PATH} | cut -d '(' -f 2 | cut -d '-' -f 2 | grep -v 'Failed)')
count=0
if [ -z "${TEST_FAILURES}" ]; then
echo -e "${CYAN}All tests passed!${RESET}"
exit 0
else
echo -e "${YELLOW}Detected failures in the test/s${RESET}"
for i in ${TEST_FAILURES}; do
echo -e "${RED}${i}${RESET}"
count=$((count+1))
done
echo -e "${YELLOW}Total failure result: ${count}${RESET}"
exit 6
fi
}
installDependencies
validateSchemas
qaCode
installHRIM
generatePackages
compileWS
testWorkspace