Skip to content

Commit 2111a9e

Browse files
authored
feat: enhance watch tasks with improved messaging and structure (#41)
1 parent d8a46e7 commit 2111a9e

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

Taskfile.yaml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,81 +87,95 @@ tasks:
8787
- echo "Creating zip with version {{.APP_VERSION}}"
8888
- cd build && zip -r scratch-arduino-app-{{.APP_VERSION}}.zip scratch-arduino-app && cd ..
8989

90+
watch:
91+
desc: "wath cfile changes for both python and sketch, and upload the changes to the board and restart"
92+
deps:
93+
- python:watch
94+
- sketch:watch
95+
9096
python:watch:
9197
desc: "Watch Python folder for changes and auto-upload/restart"
98+
silent: true
9299
cmds:
93-
- echo "Press Ctrl+C to stop watching"
94100
- |
95101
while true; do
96-
echo "Waiting for changes in python/ folder..."
102+
echo "🐍 Waiting for changes in python folder..."
97103
inotifywait -r -e modify,create,delete,move python/ 2>/dev/null || {
98104
echo "inotifywait failed, retrying..."
99105
sleep 2
100106
continue
101107
}
102108
103-
sleep 1 #W aiting 1 second for file writes to complete..."
104-
109+
sleep 1 # Waiting 1 second for file writes to complete..."
110+
echo "🐍 Change detected: uploading and restarting service..."
105111
task python:upload-and-restart || {
106112
echo "Upload/restart failed, continuing to watch..."
107113
continue
108114
}
109115
110-
echo "[ok] Upload and restart completed!"
111116
done
112117
113118
python:upload-and-restart:
114119
desc: "Upload Python files and restart container"
120+
silent: true
115121
cmds:
116122
- |
117123
adb push ./python/ /home/arduino/ArduinoApps/scratch-arduino-app/
118-
echo "Python files uploaded successfully"
119124
120125
CONTAINER_ID=$(adb shell "docker ps -q --filter 'ancestor=ghcr.io/arduino/app-bricks/python-apps-base:0.5.0'")
121126
if [ -n "$CONTAINER_ID" ]; then
122-
adb shell "docker restart $CONTAINER_ID"
123-
echo "[ok] Container restarted successfully"
127+
/usr/bin/time -f "🐍 Restarted in %es" adb shell "docker restart $CONTAINER_ID"
124128
else
125129
echo "[warning] No running container found with image ghcr.io/arduino/app-bricks/python-apps-base"
126130
fi
127131
128132
sketch:watch:
129133
desc: "Watch sketch folder for changes and auto-compile/upload"
134+
silent: true
130135
cmds:
131136
- |
132-
echo "Press Ctrl+C to stop watching"
133137
while true; do
134-
echo "Waiting for changes in sketch folder..."
138+
echo "♾️ Waiting for changes in sketch folder..."
135139
inotifywait -r -e modify,create,delete sketch/ --include '\.(ino|cpp|h|c)$' 2>/dev/null || {
136140
echo "inotifywait failed, retrying..."
137141
sleep 2
138142
continue
139143
}
140144
141145
sleep 1 # Waiting 1 second for file writes to complete
142-
146+
echo "♾️ Change detected: compiling and uploading..."
143147
task sketch:compile-and-upload|| {
144148
echo "Compile/upload failed, continuing to watch..."
145149
continue
146150
}
151+
echo
147152
done
148153
149154
sketch:compile-and-upload:
150155
desc: "Compile and upload Arduino sketch"
156+
silent: true
151157
cmds:
152-
- arduino-cli compile --build-path .cache -b arduino:zephyr:unoq sketch/
153-
- arduino-cli upload -p /dev/ttyACM0 -b arduino:zephyr:unoq:flash_mode=ram --input-dir .cache sketch/
158+
- |
159+
TOTAL_START=$(date +%s)
160+
/usr/bin/time -f "♾️ Compiled in %es" arduino-cli compile --build-path .cache -b arduino:zephyr:unoq sketch/
161+
/usr/bin/time -f "♾️ Uploaded in %es" arduino-cli upload -p /dev/ttyACM0 -b arduino:zephyr:unoq:flash_mode=ram --input-dir .cache sketch/
162+
TOTAL_END=$(date +%s)
163+
echo "♾️ Total time: $((TOTAL_END - TOTAL_START))s"
164+
# even if not necessary: the sketch folder is sync into the board to have the updated version
165+
- adb push ./sketch/ /home/arduino/ArduinoApps/scratch-arduino-app/
154166

155167
sketch:monitor:
156168
desc: "Open serial monitor for Arduino debugging"
169+
silent: true
157170
cmds:
158-
- echo "Opening serial monitor (Press Ctrl+C to exit)..."
171+
- echo " ♾️ Opening serial monitor (Press Ctrl+C to exit)..."
159172
- arduino-cli monitor -p /dev/ttyACM0
160173

161174
python:monitor:
162175
desc: "Watch sketch folder for changes and auto-compile/upload"
163176
cmds:
164177
- |
178+
echo "🐍 Python container logs"
165179
while true; do
166180
CONTAINER_ID=$(adb shell "docker ps -q --filter 'ancestor=ghcr.io/arduino/app-bricks/python-apps-base:0.5.0'")
167181
if [ -n "$CONTAINER_ID" ]; then

0 commit comments

Comments
 (0)