Skip to content

Commit

Permalink
fix draw progressbar
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn committed Aug 29, 2024
1 parent ce2185d commit 4997758
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions .github/scripts/flutter-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#!/bin/bash
# in our experience it takes about four mins on CI to startup the app
PROGRESS_BAR_WIDTH=50 # progress bar length in characters

draw_progress_bar() {
# Arguments: current value, max value, unit of measurement (optional)
local __value=$1
local __max=$2
local __unit=${3:-""} # if unit is not supplied, do not display it

# Calculate percentage
if (( $__max < 1 )); then __max=1; fi # anti zero division protection
local __percentage=$(( 100 - ($__max*100 - $__value*100) / $__max ))

# Rescale the bar according to the progress bar width
local __num_bar=$(( $__percentage * $PROGRESS_BAR_WIDTH / 100 ))

# Draw progress bar
printf "["
for b in $(seq 1 $__num_bar); do printf "#"; done
for s in $(seq 1 $(( $PROGRESS_BAR_WIDTH - $__num_bar ))); do printf " "; done
printf "] $__percentage%% ($__value / $__max $__unit)\r"
}

cd app
flutter run integration_test/main_test.dart \
--host-vmservice-port 9753 \
Expand All @@ -11,13 +35,9 @@ flutter run integration_test/main_test.dart \
&
subscript_pid=$!

# in our experience it takes about four mins on CI to startup the app

BAR='#######################' # this is full bar, e.g. 20 chars

for i in {1..24}; do
echo -ne "\r$i/24 ${BAR:0:$i}" # print $i chars of $BAR from 0 position
sleep 10 # wait 10s between "frames"
for i in {1..240}; do
draw_progress_bar $i 240 'seconds'
sleep 1
done
echo "\n"

Expand Down

0 comments on commit 4997758

Please sign in to comment.