From e7525c4d8a1cfafb880c85e7d48c9389165f6715 Mon Sep 17 00:00:00 2001 From: Thomas Merz Date: Fri, 7 Jun 2024 11:47:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20a=20GitHub=20Action=20for=20s?= =?UTF-8?q?hellcheck'ing=20on=20every=20PR=20and=20push=20to=20master=20br?= =?UTF-8?q?anch=20+=20shellcheck'ed=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/shellcheck.yml | 63 ++++++++++++++++++++++++++++++++ lsix | 11 +++--- 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/shellcheck.yml diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..0981b94 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,63 @@ +name: Shellcheck Lint + +on: + push: + paths: + # Run workflow on every push + # only if a file within the specified paths has been changed: + - 'lsix' + + pull_request: + paths: + # Run workflow on every push + # only if a file within the specified paths has been changed: + - 'lsix' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + name: Shellcheck Lint + + # This job runs on Linux + runs-on: ubuntu-latest + + steps: + # Required to access files of this repository + - uses: actions/checkout@v4 + + # Download Shellcheck and add it to the workflow path + - name: Download Shellcheck + run: | + wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv + chmod +x shellcheck-stable/shellcheck + # Verify that Shellcheck can be executed + - name: Check Shellcheck Version + run: | + shellcheck-stable/shellcheck --version + + # Run Shellcheck on repository + # --- + # https://github.com/koalaman/shellcheck + # --- + # Excluded checks: + # https://www.shellcheck.net/wiki/SC1091 -- Not following: /etc/rc.status was... + # https://www.shellcheck.net/wiki/SC1090 -- Can't follow non-constant source. .. + # --- + - name: Run Shellcheck + run: | + set +e + find ./*/ -type f | while read -r sh; do + if [ "$(file --brief --mime-type "$sh")" == 'text/x-shellscript' ]; then + echo "shellcheck'ing $sh" + if ! shellcheck-stable/shellcheck --color=always --severity=warning --exclude=SC1091,SC1090 "$sh"; then + touch some_scripts_have_failed_shellcheck + fi + fi + done + if [ -f ./some_scripts_have_failed_shellcheck ]; then + echo "Shellcheck failed for one or more shellscript(s)" + exit 1 + fi + diff --git a/lsix b/lsix index 779bfb2..b236a47 100755 --- a/lsix +++ b/lsix @@ -191,6 +191,9 @@ main() { readarray -t < <(printf "%s\n" "$@" | sort) # Only show first frame of animated GIFs if filename not specified. + # INFO: Next two lines are only needed for shellcheck to avoid this error-messages that we can't fix right now: + # SC2068 (error): Double quote array expansions to avoid re-splitting elements. + # shellcheck disable=SC2068 for x in ${!MAPFILE[@]}; do if [[ ${MAPFILE[$x]} =~ (gif|webp)$ ]]; then MAPFILE[$x]="${MAPFILE[$x]}[0]" @@ -203,7 +206,7 @@ main() { for arg; do if [ -d "$arg" ]; then echo Recursing on $arg - (cd "$arg"; $lsix) + (cd "$arg" && $lsix) else nodirs+=("$arg") fi @@ -211,10 +214,6 @@ main() { set -- "${nodirs[@]}" fi - - # Resize on load: Save memory by appending this suffix to every filename. - resize="[${tilewidth}x${tileheight}]" - imoptions="-tile ${numtiles}x1" # Each montage is 1 row x $numtiles columns imoptions+=" -geometry ${tilewidth}x${tileheight}>+${tilexspace}+${tileyspace}" # Size of each tile and spacing imoptions+=" -background $background -fill $foreground" # Use terminal's colors @@ -232,7 +231,7 @@ main() { # While we still have images to process... onerow=() goal=$(($# - numtiles)) # How many tiles left after this row - while [ $# -gt 0 -a $# -gt $goal ]; do + while [[ $# -gt 0 && $# -gt $goal ]]; do len=${#onerow[@]} onerow[len++]="-label" onerow[len++]=$(processlabel "$1")