mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 20:25:04 +00:00
Update shell-format.yml
This commit is contained in:
59
.github/workflows/shell-format.yml
vendored
59
.github/workflows/shell-format.yml
vendored
@@ -3,13 +3,6 @@ name: Shell Format & Lint
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
paths:
|
|
||||||
- '**/*.sh'
|
|
||||||
- mole
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- '**/*.sh'
|
|
||||||
- mole
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
format-lint:
|
format-lint:
|
||||||
@@ -18,34 +11,44 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install shfmt and shellcheck
|
- name: Install shfmt and shellcheck
|
||||||
run: brew install shfmt shellcheck
|
|
||||||
|
|
||||||
- name: Run shfmt in diff mode
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
files=()
|
brew update
|
||||||
while IFS= read -r -d '' file; do
|
brew install shfmt shellcheck
|
||||||
files+=("$file")
|
|
||||||
done < <(find . -type f \( -name '*.sh' -o -name 'mole' \) \
|
- name: Collect shell files
|
||||||
! -path './.git/*' ! -path './tests/tmp-*' -print0)
|
id: files
|
||||||
if (( ${#files[@]} == 0 )); then
|
shell: bash
|
||||||
echo "No shell files found; skipping shfmt"
|
run: |
|
||||||
exit 0
|
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
|
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
|
- name: Run shellcheck
|
||||||
|
if: steps.files.outputs.found != '0'
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
files=()
|
if [[ -f .shellcheckrc ]]; then
|
||||||
while IFS= read -r -d '' file; do
|
xargs -0 shellcheck --rcfile ./.shellcheckrc < files-null.list
|
||||||
files+=("$file")
|
else
|
||||||
done < <(find . -type f \( -name '*.sh' -o -name 'mole' \) \
|
xargs -0 shellcheck < files-null.list
|
||||||
! -path './.git/*' ! -path './tests/tmp-*' -print0)
|
|
||||||
if (( ${#files[@]} == 0 )); then
|
|
||||||
echo "No shell files found; skipping shellcheck"
|
|
||||||
exit 0
|
|
||||||
fi
|
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"
|
||||||
Reference in New Issue
Block a user