Skip to content

Commit 76e2c5d

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 76e2c5d

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ main() {
191191
readarray -t < <(printf "%s\n" "$@" | sort)
192192

193193
# Only show first frame of animated GIFs if filename not specified.
194-
for x in ${!MAPFILE[@]}; do
194+
for x in "${!MAPFILE[@]}"; do
195195
if [[ ${MAPFILE[$x]} =~ (gif|webp)$ ]]; then
196196
MAPFILE[$x]="${MAPFILE[$x]}[0]"
197197
fi
@@ -203,7 +203,7 @@ main() {
203203
for arg; do
204204
if [ -d "$arg" ]; then
205205
echo Recursing on $arg
206-
(cd "$arg"; $lsix)
206+
(cd "$arg" || exit; $lsix)
207207
else
208208
nodirs+=("$arg")
209209
fi
@@ -213,7 +213,7 @@ main() {
213213

214214

215215
# Resize on load: Save memory by appending this suffix to every filename.
216-
resize="[${tilewidth}x${tileheight}]"
216+
#resize="[${tilewidth}x${tileheight}]" ### DONE: SC2034 (warning): resize appears unused. Verify use (or export if used externally).
217217

218218
imoptions="-tile ${numtiles}x1" # Each montage is 1 row x $numtiles columns
219219
imoptions+=" -geometry ${tilewidth}x${tileheight}>+${tilexspace}+${tileyspace}" # Size of each tile and spacing
@@ -232,7 +232,7 @@ main() {
232232
# While we still have images to process...
233233
onerow=()
234234
goal=$(($# - numtiles)) # How many tiles left after this row
235-
while [ $# -gt 0 -a $# -gt $goal ]; do
235+
while [ $# -gt 0 ] && [ $# -gt $goal ]; do
236236
len=${#onerow[@]}
237237
onerow[len++]="-label"
238238
onerow[len++]=$(processlabel "$1")

0 commit comments

Comments
 (0)