From daad85cf1e587edd8dbac201659897927584581f Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:49:52 +0100 Subject: [PATCH] Actions: Check for SVG-Width+Height and compare against viewbox --- .github/workflows/main.yml | 46 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 81994bc..92be76b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Test Square SVGs +name: Test SVGs # Triggers the workflow on push / pull request events but only for the svg folder on: @@ -42,19 +42,43 @@ jobs: # sets x, y, width, height params vbArr=($vbStr) - x=${vbArr[0]} - y=${vbArr[1]} - w=${vbArr[2]} - h=${vbArr[3]} + vbX=${vbArr[0]} + vbY=${vbArr[1]} + vbW=${vbArr[2]} + vbH=${vbArr[3]} - # Check that x and y are 0 - if [[ $x != 0 || $y != 0 ]] ; then - errArr+=("$f has x: $x and y: $y") + # Check that viewbox' x and y are 0 + if [[ $vbX != 0 || $vbY != 0 ]] ; then + errArr+=("$f has viewBox' x: $vbX and y: $vbY") fi - # Check that width and height are equal - if [[ $w != $h ]] ; then - errArr+=("$f has width: $w and height: $h") + # Check that viewbox' width and height are equal + if [[ $vbW != $vbH ]] ; then + 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 + svgTags=$(cat $f) + svgTags=${svgTags##*\*} + + # Width comparison + if [[ $svgTags == *width* ]] ; then + w=${svgTags##*width=\"} + w=${h%%\"*} + if [[ $w != $vbW ]] ; then + 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 + errArr+=("$f has height: $h but viewbox height: $vbH") + fi fi # Check that svg is not 1 line