Skip to content

Commit ff411ae

Browse files
authored
Merge pull request #310 from romanowski/docs/gifs
Check gifs on CI
2 parents 622d1fc + 265572a commit ff411ae

Some content is hidden

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

69 files changed

+362
-136
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ jobs:
160160
- name: Test documentation
161161
run: .github/scripts/check_docs.sh
162162

163+
- name: Test gifs
164+
run: gifs/generate_gifs.sh $(ls gifs/scenarios/)
165+
163166
checks:
164167
timeout-minutes: 15
165168
runs-on: ubuntu-latest

gifs/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ FROM asciinema/asciinema
22

33
RUN apt-get install -y pv curl
44

5-
RUN curl -fLo scala-cli.deb https://github.com/Virtuslab/scala-cli/releases/download/nightly/scala-cli-x86_64-pc-linux.deb
6-
RUN dpkg -i scala-cli.deb
7-
85
RUN mkdir /data
96
WORKDIR /data
107

@@ -13,6 +10,7 @@ RUN cd /data
1310
RUN echo 'def a = 123' > a.scala
1411
RUN scala-cli compile a.scala || echo "Problems with bloop"
1512

13+
RUN apt-get update
1614
RUN apt-get install -y clang
1715

1816
RUN curl -fsSL https://deb.nodesource.com/setup_12.x | bash -
@@ -21,7 +19,11 @@ RUN apt-get install -y nodejs
2119
RUN apt-get install -y rubygems
2220
RUN gem install rouge
2321

22+
# Update path to point to newer version
23+
RUN curl -fLo scala-cli.deb https://github.com/VirtusLab/scala-cli/releases/download/v0.0.7/scala-cli-x86_64-pc-linux.deb
24+
RUN dpkg -i scala-cli.deb
25+
2426
COPY *.sh /data/
2527
COPY scenarios /data/scenarios
2628

27-
ENTRYPOINT scenarios/$1.sh -n && asciinema rec --overwrite --command="scenarios/$1.sh -n" /out/$1.cast
29+
ENTRYPOINT ./run_scenario.sh "$1"

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/example.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ else
2121

2222
# Wait a bit to read output of last command
2323
sleep 2
24-
echo " "
24+
echo " " && echo "ok" > status.txt
2525
fi

gifs/generate_gifs.sh

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

3+
set -exo pipefail
4+
35
# Generate svg files for arguments based on create scripts with scenarios
46

57
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
68
OUT=$SCRIPT_DIR/.scala
7-
mkdir $OUT
9+
10+
mkdir -p $OUT
11+
rm -f $OUT/failures.txt
12+
13+
tty && TTY_OPS="-it"
14+
15+
columns=70
16+
rows=20
17+
no_record=
18+
no_build=
19+
no_gifs=
20+
no_svgs=
821

922
for name in "$@"
1023
do
11-
echo processing $name
12-
svg_render_mappings="-v $SCRIPT_DIR/../website/static/img:/data -v $OUT/.scala:/out"
13-
svg_render_ops="--in /out/$name.cast --width 70 --height 20 --term iterm2 --padding 20"
14-
echo "start" &&
15-
docker build gifs --tag gif-renderer &&
16-
docker build gifs/svg_render/ --tag svg_rendrer &&
17-
# generate termnail session
18-
docker run --rm -it -v $OUT/.scala:/out gif-renderer generate_gif.sh $name &&
19-
# render svgs
20-
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/$name.svg --profile "/profiles/light" &&
21-
docker run --rm $svg_render_mappings svg_rendrer a $svg_render_ops --out /data/dark/$name.svg --profile "/profiles/dark" &&
24+
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
22100
echo "done"
23-
done
101+
fi
102+
done
103+
104+
failures=
105+
test -f "$OUT/failures.txt" && failures=$(cat "$OUT/failures.txt")
106+
107+
if [ -n "$failures" ]; then
108+
echo "Scenarios failed:" &&
109+
echo "$failures" &&
110+
exit 1
111+
else
112+
echo "All scenarios succeded!"
113+
fi

gifs/run_scenario.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
6+
7+
if [ "$#" != "1" ]; then
8+
echo "Please provide one scenario file!"
9+
exit 1
10+
fi
11+
12+
13+
fileName=$(basename $1)
14+
name=${fileName%%.sh}
15+
script=$SCRIPT_DIR/scenarios/$name.sh
16+
17+
ls $script
18+
19+
#warmup
20+
$script -n
21+
echo "Done with $?"
22+
23+
test -f status.txt && rm status.txt
24+
25+
#do recording
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+
)
35+
36+
test -f status.txt || (
37+
echo "Scenario $script failed." &&
38+
echo "In case logs show that is should succeed check if it creates a status.txt file at the end" &&
39+
exit 1
40+
)

gifs/scenarios/complete-install.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
########################
46
# include the magic
57
########################
@@ -8,27 +10,26 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
810

911
if [[ -z "${ASCIINEMA_REC}" ]]; then
1012
# Warm up scala-cli
11-
apt-get purge -y scala-cli
13+
apt-get purge -y scala-cli || true
1214
# or do other preparation (e.g. create code)
1315
else
1416
. $SCRIPT_DIR/../demo-magic.sh
1517
# # hide the evidence
16-
clear
18+
clearConsole
1719

1820
# Put your stuff here
19-
p scala-cli
20-
scala-cli
21-
p java
22-
java
21+
pe scala-cli || true
22+
23+
pe java || true
2324

24-
sleep 2
25+
doSleep 2
2526

2627
pe "curl -sSLf https://virtuslab.github.io/scala-cli-packages/scala-setup.sh | sh"
2728
pe 'source ~/.profile'
2829
pe "echo 'println(\"Hello from scala-cli\")' | scala-cli -"
2930

3031

3132
# Wait a bit to read output of last command
32-
sleep 2
33-
echo " "
33+
doSleep 2
34+
echo " " && echo "ok" > status.txt
3435
fi

gifs/scenarios/defaults.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
########################
46
# include the magic
57
########################
@@ -14,18 +16,18 @@ if [[ -z "${ASCIINEMA_REC}" ]]; then
1416
else
1517
. $SCRIPT_DIR/../demo-magic.sh
1618
# # hide the evidence
17-
clear
19+
clearConsole
1820

1921
# Put your stuff here
2022
cat <<EOF | updateFile Main.scala
2123
@main def hello() = {println("Hello "+"world")}
2224
EOF
23-
sleep 2
25+
doSleep 2
2426
pe 'scala-cli .'
2527
pe 'scala-cli fmt .'
2628
p "cat Main.scala"
2729
rougify --theme tulip Main.scala
2830
pe 'scala-cli package .'
29-
sleep 4
30-
echo " "
31+
doSleep 4
32+
echo " " && echo "ok" > status.txt
3133
fi

0 commit comments

Comments
 (0)