frog_emojis/.github/workflows/main.yml

94 lines
2.9 KiB
YAML
Raw Normal View History

name: Test SVGs
2022-02-04 13:49:56 +00:00
2022-02-05 08:57:43 +00:00
# Triggers the workflow on push / pull request events, and on manual trigger
on: [push, pull_request, workflow_dispatch]
2022-02-04 13:49:56 +00:00
jobs:
2022-02-04 14:15:12 +00:00
Test-SVGs:
2022-02-04 13:49:56 +00:00
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
2022-02-04 14:09:27 +00:00
- name: Check SVG validity
2022-02-04 13:49:56 +00:00
run: |
# Enables globstar to recursively go through folders
shopt -s globstar
errArr=()
2022-02-06 13:05:12 +00:00
for f in ./svg/**/*.svg
2022-02-04 13:49:56 +00:00
do
2022-02-04 14:09:27 +00:00
echo "Checking '$f'"
2022-02-04 14:15:12 +00:00
# Checking if file contains space in path
if [[ $f == *\ * ]] ; then
errArr+=("$f contains a space!")
fi
2022-02-06 13:05:12 +00:00
# Save first few lines of file into variable to make parsing faster
headfile=$(head -n 50 "$f")
2022-02-04 13:49:56 +00:00
# Gets everything in between the viewBox quotes
2022-02-06 13:05:12 +00:00
vbStr=${headfile}
2022-02-04 13:49:56 +00:00
vbStr=${vbStr##*viewBox=\"}
vbStr=${vbStr%%\"*}
# sets x, y, width, height params
vbArr=($vbStr)
vbX=${vbArr[0]}
vbY=${vbArr[1]}
vbW=${vbArr[2]}
vbH=${vbArr[3]}
2022-02-04 13:49:56 +00:00
# Check that viewbox' x and y are 0
if [[ $vbX != 0 || $vbY != 0 ]] ; then
errArr+=("$f has viewBox' x: $vbX and y: $vbY")
2022-02-04 13:49:56 +00:00
fi
# Check that viewbox' width and height are equal
if [[ $vbW != $vbH ]] ; then
2022-02-04 15:56:08 +00:00
errArr+=("$f has viewbox -width: $vbW and -height: $vbH")
fi
# Check if normal width/height parameters exist and
# if yes, compare them with viewBox height/width
2022-02-06 13:05:12 +00:00
svgTags=${headfile}
svgTags=${svgTags##*\<svg}
svgTags=${svgTags%%\>*}
# Width comparison
if [[ $svgTags == *width* ]] ; then
w=${svgTags##*width=\"}
w=${w%%\"*}
if [[ $w != $vbW ]] ; then
2022-02-04 15:56:08 +00:00
errArr+=("$f has width: $w but viewbox-width: $vbW")
fi
fi
# Height comparison
if [[ $svgTags == *height* ]] ; then
h=${svgTags##*height=\"}
h=${h%%\"*}
if [[ $h != $vbH ]] ; then
2022-02-04 15:56:08 +00:00
errArr+=("$f has height: $h but viewbox-height: $vbH")
fi
2022-02-04 13:49:56 +00:00
fi
# Check that svg is not 1 line
2022-02-06 13:05:12 +00:00
if [[ $(wc -l < "$f") == 0 ]] ; then
2022-02-04 13:49:56 +00:00
errArr+=("$f is only one line!")
fi
done
2022-02-04 14:09:27 +00:00
# Results
2022-02-04 14:32:10 +00:00
# If the error Array is not empty, print everything from it and error out
# Otherwise exit normally
2022-02-04 13:56:52 +00:00
if [[ ${#errArr[@]} != 0 ]] ; then
2022-02-04 14:32:10 +00:00
echo "--------------------"
2022-02-04 13:49:56 +00:00
for errMess in "${errArr[@]}"
do
echo $errMess
done
exit 1
fi
2022-02-04 13:59:43 +00:00
echo "No Errors!"