Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add a GitHub Action for shellcheck'ing on every PR and push to master branch + shellcheck'ed script #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -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

11 changes: 5 additions & 6 deletions lsix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oog. That's ugly. lsix is supposed to be a simple script that people can easily hack upon without all the extra cognitive load of these sort of distractions.

How about just adding the GitHub Action so it can run as an advisory linter but leave all these shellcheck comments out of the code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are neccessary for shellcheck so it won't complain about a specific error or warning in the next line. So for bash-hackers it should not confuse or distract them - but a failing shellcheck GitHub Action might confuse 🤔
I tried to fix this as mentioned/hinted on https://github.com/koalaman/shellcheck/wiki/SC2068 - but then lsix failed doing the right thing 😞 So I left shellcheck intentionally ignore this because it works/does the right thing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment that should help other users understand why these shellcheck-lines are neccessary. And I fixed (cd "$arg"; $lsix) to (cd "$arg" && $lsix) - Do you @hackerb9 agree to that?

for x in ${!MAPFILE[@]}; do
if [[ ${MAPFILE[$x]} =~ (gif|webp)$ ]]; then
MAPFILE[$x]="${MAPFILE[$x]}[0]"
Expand All @@ -203,18 +206,14 @@ main() {
for arg; do
if [ -d "$arg" ]; then
echo Recursing on $arg
(cd "$arg"; $lsix)
(cd "$arg" && $lsix)
else
nodirs+=("$arg")
fi
done
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
Expand All @@ -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
thomasmerz marked this conversation as resolved.
Show resolved Hide resolved
len=${#onerow[@]}
onerow[len++]="-label"
onerow[len++]=$(processlabel "$1")
Expand Down