Skip to content

Commit fd0a76b

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

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

Diff for: .github/workflows/shellcheck.yml

+63
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+

Diff for: lsix

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fi
6868
if [[ "$COMSPEC" ]]; then
6969
alias convert="magick convert" # Shun MS Windows' "convert" command.
7070
fi
71-
71+
7272
cleanup() {
7373
echo -n $'\e\\' # Escape sequence to stop SIXEL.
7474
stty echo # Reset terminal to show characters.
@@ -193,7 +193,7 @@ main() {
193193
readarray -t < <(printf "%s\n" "$@" | sort)
194194

195195
# Only show first frame of animated GIFs if filename not specified.
196-
for x in ${!MAPFILE[@]}; do
196+
for x in "${!MAPFILE[@]}"; do
197197
if [[ ${MAPFILE[$x]} =~ (gif|webp)$ ]]; then
198198
MAPFILE[$x]="${MAPFILE[$x]}[0]"
199199
fi
@@ -205,7 +205,7 @@ main() {
205205
for arg; do
206206
if [ -d "$arg" ]; then
207207
echo Recursing on $arg
208-
(cd "$arg"; $lsix)
208+
(cd "$arg" || exit; $lsix)
209209
else
210210
nodirs+=("$arg")
211211
fi
@@ -215,7 +215,7 @@ main() {
215215

216216

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

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

0 commit comments

Comments
 (0)