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 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 - 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"