Skip to content

Commit b63acf9

Browse files
committed
Make gif generation CI compatible
1 parent 3faa3f3 commit b63acf9

21 files changed

+157
-63
lines changed

.github/workflows/ci.yml

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

163163
- name: Test gifs
164-
run: gifs/generate_gifs.sh $(ls gifs/scenarios/)
164+
run: |
165+
SKIP_RENDER=true
166+
gifs/generate_gifs.sh $(ls gifs/scenarios/)
165167
166168
checks:
167169
timeout-minutes: 15

gifs/demo-magic.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,18 @@ function updateFile(){
196196

197197
p "cat $1"
198198
rougify --theme tulip $1
199+
199200
sleep 1
200201
}
201202

203+
function clearConsole(){
204+
clear
205+
}
206+
207+
function doSleep(){
208+
sleep $1
209+
}
210+
202211
check_pv
203212
#
204213
# handle some default params

gifs/demo-no-magic.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Mock of demo magic, for running on CI
2+
3+
function p() {
4+
echo "running: $@"
5+
}
6+
7+
function pe() {
8+
p "$@"
9+
run_cmd "$@"
10+
}
11+
12+
function pei {
13+
NO_WAIT=true pe "$@"
14+
}
15+
16+
function cmd() {
17+
run_cmd "${command}"
18+
}
19+
20+
function run_cmd() {
21+
eval "$@"
22+
}
23+
24+
function updateFile(){
25+
rm -f $1
26+
if [ $# -eq 1 ]; then
27+
while IFS= read -r data; do echo "$data" >> $1 ; done;
28+
else
29+
echo $2 > $1
30+
fi
31+
32+
p "cat $1"
33+
rougify --theme tulip $1
34+
35+
doSleep 1
36+
}
37+
38+
function clearConsole(){
39+
echo clear
40+
}
41+
42+
function doSleep(){
43+
echo sleep $1
44+
}

gifs/generate_gifs.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ test -f $OUT/failures.txt && rm $OUT/failures.txt
1212

1313
docker build gifs --tag gif-renderer
1414
docker build gifs/svg_render/ --tag svg_rendrer
15+
tty && TTY_OPS="-it"
1516

1617
for name in "$@"
1718
do
1819
echo processing $name
1920
svg_render_mappings="-v $SCRIPT_DIR/../website/static/img:/data -v $OUT/.scala:/out"
2021
svg_render_ops="--in /out/$name.cast --width 70 --height 20 --term iterm2 --padding 20"
21-
echo "start"
22+
echo "start with $TTY_OPS"
2223

23-
# generate termnail session
24-
docker run --rm -it -v $OUT/.scala:/data/out gif-renderer ./run_scenario.sh $name || (
24+
# Run the scenario
25+
docker run --rm $TTY_OPS -v $OUT/.scala:/data/out gif-renderer ./run_scenario.sh $name || (
2526
echo "Scenario failed: $name" &&
2627
echo $name >> $OUT/failures.txt
2728
)
28-
# render svgs
29-
if [ -z "$SKIP_RENDER" ]; then
29+
30+
# do not render gifs without TTY
31+
if [ -n "$TTY_OPS" ]; then
3032
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/$name.svg --profile "/profiles/light"
3133
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/dark/$name.svg --profile "/profiles/dark"
3234
fi

gifs/run_scenario.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ echo "Done with $?"
2323
test -f status.txt && rm status.txt
2424

2525
#do recording
26-
asciinema rec --overwrite --command="$script -n" $SCRIPT_DIR/out/$name.cast
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+
)
2736

2837
test -f status.txt || (
2938
echo "Scenarion $sctip failed." &&

gifs/scenarios/complete-install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ if [[ -z "${ASCIINEMA_REC}" ]]; then
1515
else
1616
. $SCRIPT_DIR/../demo-magic.sh
1717
# # hide the evidence
18-
clear
18+
clearConsole
1919

2020
# Put your stuff here
2121
p scala-cli
2222
scala-cli
2323
p java
2424
java
2525

26-
sleep 2
26+
doSleep 2
2727

2828
pe "curl -sSLf https://virtuslab.github.io/scala-cli-packages/scala-setup.sh | sh"
2929
pe 'source ~/.profile'
3030
pe "echo 'println(\"Hello from scala-cli\")' | scala-cli -"
3131

3232

3333
# Wait a bit to read output of last command
34-
sleep 2
34+
doSleep 2
3535
echo " " && echo "ok" > status.txt
3636
fi

gifs/scenarios/debug.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
########################
6+
# include the magic
7+
########################
8+
9+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
10+
11+
if [[ -z "${ASCIINEMA_REC}" ]]; then
12+
# Code here will be run before the recording session
13+
# Warm up scala-cli
14+
# echo "println(1)" | scala-cli -
15+
# or do other preparation (e.g. create code)
16+
echo OK
17+
else
18+
. $SCRIPT_DIR/../demo-magic.sh
19+
# hide the evidence
20+
clearConsole
21+
22+
# Put your stuff here
23+
# pe "echo 'println(\"<description>\")' | scala-cli -"
24+
25+
# Wait a bit to read output of last command
26+
# doSleep 2
27+
echo " " && echo "ok" > status.txt && echo "ok" > status.txt
28+
fi

gifs/scenarios/defaults.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ if [[ -z "${ASCIINEMA_REC}" ]]; then
1616
else
1717
. $SCRIPT_DIR/../demo-magic.sh
1818
# # hide the evidence
19-
clear
19+
clearConsole
2020

2121
# Put your stuff here
2222
cat <<EOF | updateFile Main.scala
2323
@main def hello() = {println("Hello "+"world")}
2424
EOF
25-
sleep 2
25+
doSleep 2
2626
pe 'scala-cli .'
2727
pe 'scala-cli fmt .'
2828
p "cat Main.scala"
2929
rougify --theme tulip Main.scala
3030
pe 'scala-cli package .'
31-
sleep 4
31+
doSleep 4
3232
echo " " && echo "ok" > status.txt
3333
fi

gifs/scenarios/demo.sh

Lines changed: 7 additions & 7 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-
clear
23+
clearConsoleConsole
2424

2525
cat <<EOF | updateFile demo.scala
2626
@main def demo(args: String *) =
@@ -29,9 +29,9 @@ EOF
2929

3030
pe "scala-cli compile demo.scala" || true
3131

32-
sleep 5
32+
doSleep 5
3333

34-
clear
34+
clearConsoleConsole
3535

3636
cat <<EOF | updateFile demo.scala
3737
def niceArgs(args: String*): String =
@@ -40,11 +40,11 @@ def niceArgs(args: String*): String =
4040
@main def demo(args: String*) = println(niceArgs(args*))
4141
EOF
4242

43-
pe "scala-cli demo.scala -- Ala jake Mike"
43+
pe "scala-cli demo.scala -- Ala jake Mike" || echo "FAILED!"
4444

45-
sleep 5
45+
doSleep 5
4646

47-
clear
47+
clearConsoleConsole
4848

4949
cat <<EOF | updateFile demo.test.scala
5050
// using lib "org.scalameta::munit:0.7.29"
@@ -62,6 +62,6 @@ EOF
6262
pe "scala-cli test demo.scala demo.test.scala" || true
6363

6464
# Wait a bit to read output of last command
65-
sleep 5
65+
doSleep 5
6666
echo " " && echo "ok" > status.txt
6767
fi

gifs/scenarios/education.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if [[ -z "${ASCIINEMA_REC}" ]]; then
1515
else
1616
. $SCRIPT_DIR/../demo-magic.sh
1717
# # hide the evidence
18-
clear
18+
clearConsole
1919

2020
cat <<EOF | updateFile HelloWorld.scala
2121
object HelloWorld {
@@ -29,14 +29,14 @@ EOF
2929
pe "scala-cli HelloWorld.scala"
3030

3131
# Wait a bit to read output of last command
32-
sleep 5
33-
clear
32+
doSleep 5
33+
clearConsole
3434
cat <<EOF | updateFile HelloWorld.sc
3535
println("Hello world from script")
3636
EOF
3737

3838
pe "scala-cli HelloWorld.sc"
3939

40-
sleep 5
40+
doSleep 5
4141
echo " " && echo "ok" > status.txt
4242
fi

0 commit comments

Comments
 (0)