Skip to content

Commit

Permalink
refactor ci scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
moukoublen committed Oct 19, 2024
1 parent 8e4ac16 commit 6880362
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 54 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
- name: run shellcheck anf shfmt
shell: bash
run: |
set -e
./.helpers/sh-checks
./.helpers/git-check-dirty
./.helpers/shellcheck
- name: shfmt
shell: bash
run: |
status=0
./.helpers/shfmt || status=1
./.helpers/git-check-dirty || status=1
exit "${status}"
27 changes: 16 additions & 11 deletions .helpers/foreach-script
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@

# -perm +111

VERBOSE=${VERBOSE:="0"}

mapfile -d '' -t files < <(
find ./ \
-type f \
-and \( -not -path './.git/*' \) \
-and \( -not -path './vendor/*' \) \
-and \( -name '*.bash' -or -name '*.sh' -or -executable \) \
-print0
)

status=0
find ./ \
-type f \
-and \( -not -path './.git/*' \) \
-and \( -not -path './vendor/*' \) \
-and \( -name '*.bash' -or -name '*.sh' -or -executable \) \
-print0 | while IFS= read -r -d '' file; do

for file in "${files[@]}"; do
if file "${file}" | grep -qE 'shell script|POSIX shell script|Bourne-Again shell script|bash script|a sh script'; then
echo "${*} ${file}"
if ! "${@}" "${file}"; then
status=1
fi
[[ ${VERBOSE} == "1" ]] || echo "${*} ${file}"
"${@}" "${file}" || status=1
fi
done

exit $status
exit ${status}
23 changes: 0 additions & 23 deletions .helpers/sh-checks

This file was deleted.

30 changes: 13 additions & 17 deletions .helpers/shellcheck
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ if ! command -v shellcheck &>/dev/null; then
exit 1
fi

mapfile -t FILES < <(find . \
\( -not -name 'root.bash' \) \
-a \( -not -path './.git/*' \) \
-a \( -not -path './config/gnome/lib/palettes/*' \) \
-a \( -name '*.bash' -o \( -type f -a -executable \) \) \
-print)

set -x

shellcheck \
--shell=bash \
--exclude=SC1090 \
./.helpers/foreach-script shellcheck \
--norc \
--external-sources \
--severity=warning \
--format=tty \
--source-path=./config/gnome/lib \
--norc \
root.bash \
"${FILES[@]}"
--enable=require-variable-braces,add-default-case \
--exclude=SC2012 \
--exclude=SC2002 \
--exclude=SC2059 \
--exclude=SC2181

# SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames. https://www.shellcheck.net/wiki/SC2012
# SC2059 (info): Don't use variables in the printf format string. https://www.shellcheck.net/wiki/SC2059
# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. https://www.shellcheck.net/wiki/SC2002
# SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. https://www.shellcheck.net/wiki/SC2181

13 changes: 13 additions & 0 deletions .helpers/shfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

if ! command -v shfmt &>/dev/null; then
echo 'shfmt not found' >&2
exit 1
fi

./.helpers/foreach-script shfmt \
--simplify \
--language-dialect auto \
--case-indent \
--indent 2 \
--write
1 change: 1 addition & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path-read-link() {
;;
*)
readlink -n "${1}"
;;
esac
}

Expand Down

0 comments on commit 6880362

Please sign in to comment.