1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 14:26:46 +00:00

Update shell-format.yml

This commit is contained in:
Tw93
2025-10-12 17:55:53 +08:00
committed by GitHub
parent d54ca50486
commit b61a3659d3

View File

@@ -3,13 +3,6 @@ name: Shell Format & Lint
on:
push:
branches: [main]
paths:
- '**/*.sh'
- mole
pull_request:
paths:
- '**/*.sh'
- mole
jobs:
format-lint:
@@ -18,34 +11,44 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install shfmt and shellcheck
run: brew install shfmt shellcheck
- name: Run shfmt in diff mode
run: |
set -euo pipefail
files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <(find . -type f \( -name '*.sh' -o -name 'mole' \) \
! -path './.git/*' ! -path './tests/tmp-*' -print0)
if (( ${#files[@]} == 0 )); then
echo "No shell files found; skipping shfmt"
exit 0
brew update
brew install shfmt shellcheck
- name: Collect shell files
id: files
shell: bash
run: |
set -euo pipefail
mapfile -d '' FILES < <(git ls-files -z '*.sh' 'mole' || true)
if (( ${#FILES[@]} == 0 )); then
echo "found=0" >> "$GITHUB_OUTPUT"
else
printf '%s\0' "${FILES[@]}" > files-null.list
echo "found=${#FILES[@]}" >> "$GITHUB_OUTPUT"
fi
"${search_cmd[@]}" -exec shfmt -i 4 -ci -sr -d {} +
- name: Run shfmt (diff mode, indent=4, simplify)
if: steps.files.outputs.found != '0'
run: |
set -euo pipefail
xargs -0 shfmt -i 4 -ci -sr -d < files-null.list
- name: Run shellcheck
if: steps.files.outputs.found != '0'
run: |
set -euo pipefail
files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <(find . -type f \( -name '*.sh' -o -name 'mole' \) \
! -path './.git/*' ! -path './tests/tmp-*' -print0)
if (( ${#files[@]} == 0 )); then
echo "No shell files found; skipping shellcheck"
exit 0
if [[ -f .shellcheckrc ]]; then
xargs -0 shellcheck --rcfile ./.shellcheckrc < files-null.list
else
xargs -0 shellcheck < files-null.list
fi
"${search_cmd[@]}" -exec shellcheck --rcfile .shellcheckrc {} +
- name: Nothing to check
if: steps.files.outputs.found == '0'
run: echo "No shell files found; skipping shfmt & shellcheck"