mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 16:14:44 +00:00
60 lines
1.5 KiB
YAML
60 lines
1.5 KiB
YAML
name: Shell Format & Lint
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
format-lint:
|
|
runs-on: macos-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install shfmt and shellcheck
|
|
run: |
|
|
set -euo pipefail
|
|
brew update
|
|
brew install shfmt shellcheck
|
|
|
|
- name: Collect shell files
|
|
id: files
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
count=0
|
|
: > files-null.list
|
|
while IFS= read -r -d '' f; do
|
|
printf '%s\0' "$f" >> files-null.list
|
|
count=$((count+1))
|
|
done < <(git ls-files -z '*.sh' 'mole' || true)
|
|
|
|
if [[ $count -eq 0 ]]; then
|
|
echo "found=0" >> "$GITHUB_OUTPUT"
|
|
rm -f files-null.list
|
|
else
|
|
echo "found=$count" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- 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
|
|
if [[ -f .shellcheckrc ]]; then
|
|
xargs -0 shellcheck --rcfile ./.shellcheckrc < files-null.list
|
|
else
|
|
xargs -0 shellcheck < files-null.list
|
|
fi
|
|
|
|
- name: Nothing to check
|
|
if: steps.files.outputs.found == '0'
|
|
run: echo "No shell files found; skipping shfmt & shellcheck" |