-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros2_ws_same_versions
executable file
·87 lines (72 loc) · 1.79 KB
/
ros2_ws_same_versions
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
#!/bin/bash
set -e
# This checks all ROS packages in the workspace have the same version
# Arguments parsing
# Example:
# ./ros2_ws_same_versions_lint --src="./workspace/src"
help() {
usage="$(basename "$0") --src=<SRC> [--regex=<REGEX>] [ --help ]
Check all ROS packages in the workspace have the same version
Arguments:
--help Show this help text
--src Source folder of all ros packages (mandatory)
--regex Package name need to match a regex (optional, Default=\".*\")
"
echo "${usage}"
}
for i in "$@"
do
case $i in
--src=*)
SRC="${i#*=}"
shift # past argument=value
;;
--regex=*)
REGEX="${i#*=}"
shift # past argument=value
;;
--help)
HELP=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
# Arguments check
if [ -n "${HELP}" ]; then
help
exit 0
fi
if [ -z "${SRC}" ]; then
help
exit 1
fi
if [ -z "${REGEX}" ]; then
REGEX=".*"
fi
# Will throw an error if not installed
if ! command -v xmllint &> /dev/null
then
echo "xmllint could not be found. Please install it"
exit 1
fi
# Checking package.xml
result=$(find "${SRC}" -maxdepth 2 -regextype egrep -regex ".*${REGEX}/package.xml" -exec xmllint --xpath 'package/version/text()' {} \; | tr '\n' ' ')
array=()
IFS=', ' read -r -a array <<< "${result}"
version="${array[0]}"
if [ ! "${#array[@]}" -gt 0 ] && [ "$(printf "%s\000" "${array[@]}" | LC_ALL=C sort -z -u | grep -z -c .)" -eq 1 ] ; then
echo "Version is different in all packages: ${result}"
exit 1
fi
# Checking setup.py
# shellcheck disable=SC2044
for file in $(find "${SRC}" -name setup.py); do
if ! grep -q "version=\"${version}\"" "${file}"; then
cat "${file}"
echo "Version is incorrect in ${file}. Should be ${version}"
exit 1
fi
done