Skip to content

Commit e7525c4

Browse files
committed
✨ add a GitHub Action for shellcheck'ing on every PR and push to master branch + shellcheck'ed script
1 parent 69d14a4 commit e7525c4

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

.github/workflows/shellcheck.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Shellcheck Lint
2+
3+
on:
4+
push:
5+
paths:
6+
# Run workflow on every push
7+
# only if a file within the specified paths has been changed:
8+
- 'lsix'
9+
10+
pull_request:
11+
paths:
12+
# Run workflow on every push
13+
# only if a file within the specified paths has been changed:
14+
- 'lsix'
15+
16+
# Allows you to run this workflow manually from the Actions tab
17+
workflow_dispatch:
18+
19+
jobs:
20+
build:
21+
name: Shellcheck Lint
22+
23+
# This job runs on Linux
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
# Required to access files of this repository
28+
- uses: actions/checkout@v4
29+
30+
# Download Shellcheck and add it to the workflow path
31+
- name: Download Shellcheck
32+
run: |
33+
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv
34+
chmod +x shellcheck-stable/shellcheck
35+
# Verify that Shellcheck can be executed
36+
- name: Check Shellcheck Version
37+
run: |
38+
shellcheck-stable/shellcheck --version
39+
40+
# Run Shellcheck on repository
41+
# ---
42+
# https://github.com/koalaman/shellcheck
43+
# ---
44+
# Excluded checks:
45+
# https://www.shellcheck.net/wiki/SC1091 -- Not following: /etc/rc.status was...
46+
# https://www.shellcheck.net/wiki/SC1090 -- Can't follow non-constant source. ..
47+
# ---
48+
- name: Run Shellcheck
49+
run: |
50+
set +e
51+
find ./*/ -type f | while read -r sh; do
52+
if [ "$(file --brief --mime-type "$sh")" == 'text/x-shellscript' ]; then
53+
echo "shellcheck'ing $sh"
54+
if ! shellcheck-stable/shellcheck --color=always --severity=warning --exclude=SC1091,SC1090 "$sh"; then
55+
touch some_scripts_have_failed_shellcheck
56+
fi
57+
fi
58+
done
59+
if [ -f ./some_scripts_have_failed_shellcheck ]; then
60+
echo "Shellcheck failed for one or more shellscript(s)"
61+
exit 1
62+
fi
63+

lsix

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ main() {
191191
readarray -t < <(printf "%s\n" "$@" | sort)
192192

193193
# Only show first frame of animated GIFs if filename not specified.
194+
# INFO: Next two lines are only needed for shellcheck to avoid this error-messages that we can't fix right now:
195+
# SC2068 (error): Double quote array expansions to avoid re-splitting elements.
196+
# shellcheck disable=SC2068
194197
for x in ${!MAPFILE[@]}; do
195198
if [[ ${MAPFILE[$x]} =~ (gif|webp)$ ]]; then
196199
MAPFILE[$x]="${MAPFILE[$x]}[0]"
@@ -203,18 +206,14 @@ main() {
203206
for arg; do
204207
if [ -d "$arg" ]; then
205208
echo Recursing on $arg
206-
(cd "$arg"; $lsix)
209+
(cd "$arg" && $lsix)
207210
else
208211
nodirs+=("$arg")
209212
fi
210213
done
211214
set -- "${nodirs[@]}"
212215
fi
213216

214-
215-
# Resize on load: Save memory by appending this suffix to every filename.
216-
resize="[${tilewidth}x${tileheight}]"
217-
218217
imoptions="-tile ${numtiles}x1" # Each montage is 1 row x $numtiles columns
219218
imoptions+=" -geometry ${tilewidth}x${tileheight}>+${tilexspace}+${tileyspace}" # Size of each tile and spacing
220219
imoptions+=" -background $background -fill $foreground" # Use terminal's colors
@@ -232,7 +231,7 @@ main() {
232231
# While we still have images to process...
233232
onerow=()
234233
goal=$(($# - numtiles)) # How many tiles left after this row
235-
while [ $# -gt 0 -a $# -gt $goal ]; do
234+
while [[ $# -gt 0 && $# -gt $goal ]]; do
236235
len=${#onerow[@]}
237236
onerow[len++]="-label"
238237
onerow[len++]=$(processlabel "$1")

0 commit comments

Comments
 (0)