Skip to content

Commit

Permalink
✨ add a GitHub Action for shellcheck'ing on every PR and push to mast…
Browse files Browse the repository at this point in the history
…er branch + shellcheck'ed script
  • Loading branch information
thomasmerz committed Jun 14, 2024
1 parent 69d14a4 commit 0828075
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
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
10 changes: 5 additions & 5 deletions lsix
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ main() {
readarray -t < <(printf "%s\n" "$@" | sort)

# Only show first frame of animated GIFs if filename not specified.
# 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]"
Expand All @@ -203,6 +205,8 @@ main() {
for arg; do
if [ -d "$arg" ]; then
echo Recursing on $arg
# SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
# shellcheck disable=SC2164
(cd "$arg"; $lsix)
else
nodirs+=("$arg")
Expand All @@ -211,10 +215,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
Expand All @@ -232,7 +232,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")
Expand Down

0 comments on commit 0828075

Please sign in to comment.