mirror of
https://github.com/tw93/Mole.git
synced 2026-02-14 17:02:26 +00:00
Update shell-format.yml
This commit is contained in:
54
.github/workflows/shell-format.yml
vendored
54
.github/workflows/shell-format.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Shell Format & Lint
|
name: Shell Format & Lint (Minimal)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -7,54 +7,60 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
format-lint:
|
format-lint:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install shfmt and shellcheck
|
- name: Install shfmt & shellcheck
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
brew update
|
brew update
|
||||||
brew install shfmt shellcheck
|
brew install shfmt shellcheck
|
||||||
|
shfmt -version || true
|
||||||
|
shellcheck --version || true
|
||||||
|
|
||||||
- name: Collect shell files
|
- name: List target files
|
||||||
id: files
|
id: list
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
count=0
|
FILES=$(git ls-files '*.sh' 'mole' || true)
|
||||||
: > files-null.list
|
echo "FILES<<EOF" >> "$GITHUB_OUTPUT"
|
||||||
while IFS= read -r -d '' f; do
|
echo "$FILES" >> "$GITHUB_OUTPUT"
|
||||||
printf '%s\0' "$f" >> files-null.list
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
count=$((count+1))
|
if [[ -z "$FILES" ]]; then
|
||||||
done < <(git ls-files -z '*.sh' 'mole' || true)
|
|
||||||
|
|
||||||
if [[ $count -eq 0 ]]; then
|
|
||||||
echo "found=0" >> "$GITHUB_OUTPUT"
|
echo "found=0" >> "$GITHUB_OUTPUT"
|
||||||
rm -f files-null.list
|
echo "No shell files found."
|
||||||
else
|
else
|
||||||
echo "found=$count" >> "$GITHUB_OUTPUT"
|
echo "found=1" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Files:"
|
||||||
|
echo "$FILES"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run shfmt (diff mode, indent=4, simplify)
|
- name: Run shfmt (diff only)
|
||||||
if: steps.files.outputs.found != '0'
|
if: steps.list.outputs.found == '1'
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
xargs -0 shfmt -i 4 -ci -sr -d < files-null.list
|
shfmt -i 4 -ci -sr -d ${FILES}
|
||||||
|
env:
|
||||||
|
FILES: ${{ steps.list.outputs.FILES }}
|
||||||
|
|
||||||
- name: Run shellcheck
|
- name: Run shellcheck
|
||||||
if: steps.files.outputs.found != '0'
|
if: steps.list.outputs.found == '1'
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
if [[ -f .shellcheckrc ]]; then
|
if [[ -f .shellcheckrc ]]; then
|
||||||
xargs -0 shellcheck --rcfile ./.shellcheckrc < files-null.list
|
shellcheck --rcfile .shellcheckrc ${FILES}
|
||||||
else
|
else
|
||||||
xargs -0 shellcheck < files-null.list
|
shellcheck ${FILES}
|
||||||
fi
|
fi
|
||||||
|
env:
|
||||||
|
FILES: ${{ steps.list.outputs.FILES }}
|
||||||
|
|
||||||
- name: Nothing to check
|
- name: Nothing to check
|
||||||
if: steps.files.outputs.found == '0'
|
if: steps.list.outputs.found == '0'
|
||||||
run: echo "No shell files found; skipping shfmt & shellcheck"
|
run: echo "Skip: no shell files."
|
||||||
Reference in New Issue
Block a user