Skip to content

Commit 265572a

Browse files
committed
Add gif rendering
address review feedback
1 parent b63acf9 commit 265572a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+156
-118
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ jobs:
161161
run: .github/scripts/check_docs.sh
162162

163163
- name: Test gifs
164-
run: |
165-
SKIP_RENDER=true
166-
gifs/generate_gifs.sh $(ls gifs/scenarios/)
164+
run: gifs/generate_gifs.sh $(ls gifs/scenarios/)
167165

168166
checks:
169167
timeout-minutes: 15

gifs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ RUN dpkg -i scala-cli.deb
2626
COPY *.sh /data/
2727
COPY scenarios /data/scenarios
2828

29-
ENTRYPOINT ./run_scenario.sh $1
29+
ENTRYPOINT ./run_scenario.sh "$1"

gifs/generate_gifs.sh

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,113 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -exo pipefail
44

55
# Generate svg files for arguments based on create scripts with scenarios
66

77
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
88
OUT=$SCRIPT_DIR/.scala
99

10-
test -d $OUT || mkdir $OUT
11-
test -f $OUT/failures.txt && rm $OUT/failures.txt
10+
mkdir -p $OUT
11+
rm -f $OUT/failures.txt
1212

13-
docker build gifs --tag gif-renderer
14-
docker build gifs/svg_render/ --tag svg_rendrer
1513
tty && TTY_OPS="-it"
1614

15+
columns=70
16+
rows=20
17+
no_record=
18+
no_build=
19+
no_gifs=
20+
no_svgs=
21+
1722
for name in "$@"
1823
do
19-
echo processing $name
20-
svg_render_mappings="-v $SCRIPT_DIR/../website/static/img:/data -v $OUT/.scala:/out"
21-
svg_render_ops="--in /out/$name.cast --width 70 --height 20 --term iterm2 --padding 20"
22-
echo "start with $TTY_OPS"
23-
24-
# Run the scenario
25-
docker run --rm $TTY_OPS -v $OUT/.scala:/data/out gif-renderer ./run_scenario.sh $name || (
26-
echo "Scenario failed: $name" &&
27-
echo $name >> $OUT/failures.txt
28-
)
29-
30-
# do not render gifs without TTY
31-
if [ -n "$TTY_OPS" ]; then
32-
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/$name.svg --profile "/profiles/light"
33-
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/dark/$name.svg --profile "/profiles/dark"
34-
fi
3524

36-
echo "done"
25+
case $name in
26+
27+
"--no-record")
28+
no_record=true
29+
;;
30+
31+
"--no-gifs")
32+
no_gifs=true
33+
;;
34+
35+
"--no-svgs")
36+
no_svgs=true
37+
;;
38+
39+
"--no-build")
40+
no_build=true
41+
;;
42+
43+
44+
*)
45+
;;
46+
esac
47+
48+
done
49+
50+
if [ -z "$no_build" ]; then
51+
docker build $SCRIPT_DIR --tag gif-renderer
52+
docker build $SCRIPT_DIR/svg_render/ --tag svg_rendrer
53+
fi
54+
55+
echo "Option build $no_build gifs $no_gifs svg $no_svgs record $no_record"
56+
57+
for arg in "$@"
58+
do
59+
60+
61+
if [[ "$arg" == --* ]]; then
62+
echo "Skipping $name"
63+
else
64+
fileName=$(basename "$arg")
65+
name=${fileName%%.sh}
66+
67+
echo processing $name with $TTY_OPS
68+
svg_render_mappings="-v $SCRIPT_DIR/../website/static/img:/data -v $OUT/.scala:/out"
69+
svg_render_ops="--in /out/$name.cast --width $columns --height $rows --term iterm2 --padding 20"
70+
71+
# Run the scenario
72+
failure=
73+
74+
if [ -z "$no_record" ]; then
75+
docker run --rm $TTY_OPS -v $OUT/.scala:/data/out gif-renderer ./run_scenario.sh $name || (
76+
echo "Scenario failed: $name" &&
77+
echo $name >> $OUT/failures.txt &&
78+
failure=true
79+
)
80+
fi
81+
82+
# do not render gifs without TTY
83+
if [ -n "$TTY_OPS" ] && [ -z "$failure" ]; then
84+
if [ -z "$no_svgs" ]; then
85+
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/$name.svg --profile "/profiles/light" &&
86+
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/dark/$name.svg --profile "/profiles/dark" || (
87+
echo "Scenario failed: $name" &&
88+
echo $name >> $OUT/failures.txt &&
89+
failure=true
90+
)
91+
fi
92+
if [ -z "$no_gifs" ]; then
93+
docker run --rm $svg_render_mappings asciinema/asciicast2gif -w $columns -h $rows -t monokai /out/$name.cast /data/gifs/$name.gif || (
94+
echo "Scenario failed: $name" &&
95+
echo $name >> $OUT/failures.txt &&
96+
failure=true
97+
)
98+
fi
99+
fi
100+
echo "done"
101+
fi
37102
done
38103

39-
test -f $OUT/failures.txt && (
104+
failures=
105+
test -f "$OUT/failures.txt" && failures=$(cat "$OUT/failures.txt")
106+
107+
if [ -n "$failures" ]; then
40108
echo "Scenarios failed:" &&
41-
cat $OUT/failures.txt &&
109+
echo "$failures" &&
42110
exit 1
43-
) || echo "All scenarios succeded!"
111+
else
112+
echo "All scenarios succeded!"
113+
fi

gifs/run_scenario.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euxo pipefail
44

55
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
66

@@ -10,7 +10,7 @@ if [ "$#" != "1" ]; then
1010
fi
1111

1212

13-
fileName=${1##*/}
13+
fileName=$(basename $1)
1414
name=${fileName%%.sh}
1515
script=$SCRIPT_DIR/scenarios/$name.sh
1616

@@ -23,19 +23,18 @@ echo "Done with $?"
2323
test -f status.txt && rm status.txt
2424

2525
#do recording
26-
tty &&
27-
# do recording with tty
28-
asciinema rec --overwrite --command="$script -n" $SCRIPT_DIR/out/$name.cast ||
29-
# without just run the command
30-
(
31-
export ASCIINEMA_REC=true &&
32-
# remove magic from demo...
33-
cp $SCRIPT_DIR/demo-no-magic.sh $SCRIPT_DIR/demo-magic.sh &&
34-
$script -n
35-
)
26+
( # do recording with tty
27+
tty &&
28+
asciinema rec --overwrite --command="$script -n" $SCRIPT_DIR/out/$name.cast
29+
) || ( # without tty just run the command
30+
export ASCIINEMA_REC=true &&
31+
# remove magic from demo...
32+
cp $SCRIPT_DIR/demo-no-magic.sh $SCRIPT_DIR/demo-magic.sh &&
33+
$script -n
34+
)
3635

3736
test -f status.txt || (
38-
echo "Scenarion $sctip failed." &&
37+
echo "Scenario $script failed." &&
3938
echo "In case logs show that is should succeed check if it creates a status.txt file at the end" &&
4039
exit 1
4140
)

gifs/scenarios/complete-install.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
1010

1111
if [[ -z "${ASCIINEMA_REC}" ]]; then
1212
# Warm up scala-cli
13-
apt-get purge -y scala-cli
13+
apt-get purge -y scala-cli || true
1414
# or do other preparation (e.g. create code)
1515
else
1616
. $SCRIPT_DIR/../demo-magic.sh
1717
# # hide the evidence
1818
clearConsole
1919

2020
# Put your stuff here
21-
p scala-cli
22-
scala-cli
23-
p java
24-
java
21+
pe scala-cli || true
22+
23+
pe java || true
2524

2625
doSleep 2
2726

gifs/scenarios/debug.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

gifs/scenarios/demo.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ EOF
2020
else
2121
. $SCRIPT_DIR/../demo-magic.sh
2222
# # hide the evidence
23-
clearConsoleConsole
23+
clearConsole
2424

2525
cat <<EOF | updateFile demo.scala
2626
@main def demo(args: String *) =
@@ -31,7 +31,7 @@ EOF
3131

3232
doSleep 5
3333

34-
clearConsoleConsole
34+
clearConsole
3535

3636
cat <<EOF | updateFile demo.scala
3737
def niceArgs(args: String*): String =
@@ -44,7 +44,7 @@ EOF
4444

4545
doSleep 5
4646

47-
clearConsoleConsole
47+
clearConsole
4848

4949
cat <<EOF | updateFile demo.test.scala
5050
// using lib "org.scalameta::munit:0.7.29"

gifs/scenarios/learning_curve.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
1111
if [[ -z "${ASCIINEMA_REC}" ]]; then
1212
# Warm up scala-cli
1313
echo "println(1)" | scala-cli -S 3.0.2 -
14-
echo "println(1)" | scala-cli -S 2 -
1514
# or do other preparation (e.g. create code)
1615
else
1716
. $SCRIPT_DIR/../demo-magic.sh
@@ -32,7 +31,7 @@ EOF
3231
clearConsole
3332

3433
cat <<EOF | updateFile Hello.scala
35-
// using scala 2
34+
// using scala 2.13.6
3635
3736
object Hello extends App {
3837
println("Hello world from ScalaCLI")

gifs/scenarios/prototyping.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ EOF
3333

3434
doSleep 2
3535

36-
pe "scala-cli Enum.scala -S 2.13.6"
36+
pe "scala-cli Enum.scala -S 2.13.6" || true
37+
3738

3839
# Wait a bit to read output of last command
3940
doSleep 5

gifs/scenarios/self-contained-examples.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ else
2323
doSleep 3
2424
clearConsole
2525

26-
pe "scala-cli https://gist.github.com/lwronski/99bb89d1962d2c5e21da01f1ad60e92f"
26+
pe "scala-cli https://gist.github.com/lwronski/99bb89d1962d2c5e21da01f1ad60e92f" || true
2727

2828
doSleep 2
2929

0 commit comments

Comments
 (0)