2022-02-04 15:49:52 +00:00
|
|
|
name: Test SVGs
|
2022-02-04 13:49:56 +00:00
|
|
|
|
|
|
|
# Triggers the workflow on push / pull request events but only for the svg folder
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
paths: svg/
|
|
|
|
pull_request:
|
|
|
|
paths: svg/
|
|
|
|
|
|
|
|
# Allows you to run this workflow manually from the Actions tab
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
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=()
|
|
|
|
for f in ./**/*.svg
|
|
|
|
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-04 13:49:56 +00:00
|
|
|
# Gets everything in between the viewBox quotes
|
|
|
|
vbStr=$(cat $f)
|
|
|
|
vbStr=${vbStr##*viewBox=\"}
|
|
|
|
vbStr=${vbStr%%\"*}
|
|
|
|
|
|
|
|
# sets x, y, width, height params
|
|
|
|
vbArr=($vbStr)
|
2022-02-04 15:49:52 +00:00
|
|
|
vbX=${vbArr[0]}
|
|
|
|
vbY=${vbArr[1]}
|
|
|
|
vbW=${vbArr[2]}
|
|
|
|
vbH=${vbArr[3]}
|
2022-02-04 13:49:56 +00:00
|
|
|
|
2022-02-04 15:49:52 +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
|
|
|
|
|
2022-02-04 15:49:52 +00:00
|
|
|
# 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")
|
2022-02-04 15:49:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if normal width/height parameters exist and
|
|
|
|
# if yes, compare them with viewBox height/width
|
|
|
|
svgTags=$(cat $f)
|
|
|
|
svgTags=${svgTags##*\<svg}
|
|
|
|
svgTags=${svgTags%%\>*}
|
|
|
|
|
|
|
|
# Width comparison
|
|
|
|
if [[ $svgTags == *width* ]] ; then
|
|
|
|
w=${svgTags##*width=\"}
|
2022-02-04 16:03:38 +00:00
|
|
|
w=${w%%\"*}
|
2022-02-04 15:49:52 +00:00
|
|
|
if [[ $w != $vbW ]] ; then
|
2022-02-04 15:56:08 +00:00
|
|
|
errArr+=("$f has width: $w but viewbox-width: $vbW")
|
2022-02-04 15:49:52 +00:00
|
|
|
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")
|
2022-02-04 15:49:52 +00:00
|
|
|
fi
|
2022-02-04 13:49:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that svg is not 1 line
|
|
|
|
if [[ $(wc -l < $f) == 0 ]] ; then
|
|
|
|
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!"
|