Skip to content

Commit ab52a8f

Browse files
committed
Again
1 parent 78c02d6 commit ab52a8f

2 files changed

Lines changed: 199 additions & 1 deletion

File tree

.github/workflows/cypress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
working-directory: react_frontend
2121
# Starts web server for E2E tests - replace with your own server invocation
2222
# https://docs.cypress.io/guides/continuous-integration/introduction#Boot-your-server
23-
start: cd /home/runner/work/RoboticsAcademy/RoboticsAcademy && ./scripts/develop_academy.sh
23+
start: /home/runner/work/RoboticsAcademy/RoboticsAcademy/scripts/test_academy.sh
2424
wait-on: "http://localhost:7164" # Waits for above
2525
# Records to Cypress Cloud
2626
# https://docs.cypress.io/guides/cloud/projects#Set-up-a-project-to-record

scripts/test_academy.sh

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#!/bin/bash
2+
3+
# Initialize variables with default values
4+
ram_version="https://github.com/JdeRobot/RoboticsApplicationManager.git"
5+
branch="humble-devel"
6+
radi_version="humble"
7+
gpu_mode="false"
8+
nvidia="false"
9+
compose_file="dev_humble_cpu"
10+
11+
# Function to display help message
12+
show_help() {
13+
echo "Options:"
14+
echo " -r Specify the RAM version repository URL (default: https://github.com/JdeRobot/RoboticsApplicationManager.git)"
15+
echo " -b Specify the branch of RAM (default: humble-devel)"
16+
echo " -i Specify the ROS2 version (default: humble)"
17+
echo " -g Enable GPU mode (default: false)"
18+
echo " -n Enable Nvidia support (default: false)"
19+
echo " -h Display this help message"
20+
}
21+
22+
# Function to clean up the containers
23+
cleanup() {
24+
echo "Cleaning up..."
25+
if [ "$nvidia" = "true" ]; then
26+
docker compose --compatibility down
27+
else
28+
docker compose down
29+
fi
30+
rm docker-compose.yaml
31+
rm react_frontend/checksum.txt
32+
33+
exit 0
34+
}
35+
36+
while [[ $# -gt 0 ]]; do
37+
case "$1" in
38+
-r)
39+
ram_version="$2"
40+
shift 2
41+
;;
42+
-b)
43+
branch="$2"
44+
shift 2
45+
;;
46+
-i)
47+
radi_version="$2"
48+
shift 2
49+
;;
50+
-g)
51+
gpu_mode="true"
52+
shift 1
53+
;;
54+
-n)
55+
nvidia="true"
56+
shift 1
57+
;;
58+
-h | --help) # display Help
59+
show_help
60+
exit 0
61+
;;
62+
*)
63+
echo "Invalid Option: $1"
64+
Help
65+
exit 1
66+
;;
67+
esac
68+
done
69+
70+
# Set up trap to catch interrupt signal (Ctrl+C) and execute cleanup function
71+
trap 'cleanup' INT
72+
73+
echo "RAM src: $ram_version"
74+
echo "RAM branch: $branch"
75+
echo "RoboticsBackend version: $radi_version"
76+
77+
# Check docker compose installation
78+
if ! command -v docker compose &> /dev/null; then
79+
echo "Docker Compose V2 is not installed. Please install it."
80+
fi
81+
82+
# Clone the desired RAM fork and branch
83+
if ! [ -d src ]; then
84+
git clone $ram_version -b $branch src;
85+
chown -R $(id -u):$(id -g) src/
86+
fi
87+
88+
# Prepare nvm
89+
export NVM_DIR=$HOME/.nvm;
90+
source $NVM_DIR/nvm.sh;
91+
if ! command -v nvm &> /dev/null; then
92+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
93+
export NVM_DIR=$HOME/.nvm;
94+
source $NVM_DIR/nvm.sh;
95+
fi
96+
97+
# Prepare yarn
98+
if ! command -v yarn &> /dev/null; then
99+
echo "Yarn is not installed. Installing Yarn..."
100+
101+
# Check if npm exists or not
102+
if command -v npm &> /dev/null; then
103+
npm install --global yarn
104+
else
105+
echo "npm is not installed. Installing Node.js and npm first..."
106+
107+
# Detect OS and install npm and node.js accordingly
108+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
109+
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
110+
sudo apt-get install -y nodejs
111+
elif [[ "$OSTYPE" == "darwin"* ]]; then
112+
if command -v brew &> /dev/null; then
113+
brew install node
114+
else
115+
echo "Homebrew not found. Please install Yarn manually: https://yarnpkg.com/getting-started/install"
116+
exit 1
117+
fi
118+
else
119+
echo "Unsupported OS. Please install Yarn manually: https://yarnpkg.com/getting-started/install"
120+
exit 1
121+
fi
122+
123+
npm install --global yarn
124+
fi
125+
echo "Yarn installed successfully."
126+
else
127+
echo "Yarn is already installed."
128+
fi
129+
130+
# Prepare the commons zip file
131+
cd /home/runner/work/RoboticsAcademy/RoboticsAcademy/common
132+
cd console_interfaces
133+
zip -r ../common.zip console_interfaces/
134+
cd ..
135+
cd gui_interfaces
136+
zip -r -u ../common.zip gui_interfaces/
137+
cd ..
138+
cd hal_interfaces
139+
zip -r -u ../common.zip hal_interfaces/
140+
cd ../..
141+
mv common/common.zip react_frontend/src/common.zip
142+
143+
# Prepare the frontend
144+
nvm install 20
145+
nvm use 20
146+
147+
# Checking if the frontend needs compilation
148+
cd react_frontend/
149+
DIRECTORY_TO_MONITOR="."
150+
151+
new_checksum=$(find "$DIRECTORY_TO_MONITOR" \( -path "*/node_modules" -o \
152+
-path "*/__pycache__" -o \
153+
-path "*/migrations" -o \
154+
-name "yarn.lock" -o \
155+
-name "checksum.txt" \) -prune \
156+
-o -type f -exec md5sum {} + | \
157+
sort | \
158+
md5sum | \
159+
awk '{print $1}')
160+
161+
existing_checksum_file="$DIRECTORY_TO_MONITOR/checksum.txt"
162+
163+
if [ -f "$existing_checksum_file" ]; then
164+
existing_checksum=$(cat "$existing_checksum_file")
165+
if [ "$existing_checksum" != "$new_checksum" ]; then
166+
echo "$new_checksum" > "$existing_checksum_file"
167+
yarn install
168+
yarn dev &
169+
sleep 10
170+
else
171+
echo "No Compilation needed"
172+
fi
173+
else
174+
echo "$new_checksum" > "$existing_checksum_file"
175+
yarn install
176+
yarn dev &
177+
sleep 10
178+
fi
179+
180+
cd ..
181+
182+
# Prepare the compose file
183+
if [ "$gpu_mode" = "true" ]; then
184+
compose_file="dev_humble_gpu"
185+
fi
186+
if [ "$nvidia" = "true" ]; then
187+
compose_file="dev_humble_nvidia"
188+
fi
189+
cp compose_cfg/$compose_file.yaml docker-compose.yaml
190+
191+
# Proceed with docker-compose commands
192+
if [ "$nvidia" = "true" ]; then
193+
docker compose --compatibility up
194+
else
195+
docker compose up
196+
fi
197+
198+
cleanup

0 commit comments

Comments
 (0)