| Eric Ball | 60265fe | 2026-05-26 17:14:49 -0700 | [diff] [blame] | 1 | --- |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # SPDX-FileCopyrightText: 2026 The Linux Foundation |
| 4 | |
| 5 | name: ShellCheck Lint |
| 6 | description: "Lint shell scripts with ShellCheck" |
| 7 | |
| 8 | inputs: |
| 9 | path: |
| 10 | description: "Path to search for shell scripts" |
| 11 | required: false |
| 12 | default: "." |
| 13 | severity: |
| 14 | description: "Minimum severity level (error, warning, info, style)" |
| 15 | required: false |
| 16 | default: "style" |
| 17 | exclude: |
| 18 | description: "Comma-separated list of ShellCheck codes to exclude (e.g., SC1090,SC2034)" |
| 19 | required: false |
| 20 | default: "" |
| 21 | |
| 22 | runs: |
| 23 | using: "composite" |
| 24 | steps: |
| 25 | - name: Install ShellCheck |
| 26 | shell: bash |
| 27 | run: | |
| 28 | if ! command -v shellcheck &> /dev/null; then |
| 29 | echo "Installing ShellCheck..." |
| 30 | sudo apt-get update |
| 31 | sudo apt-get install -y shellcheck |
| 32 | fi |
| 33 | echo "ShellCheck version:" |
| 34 | shellcheck --version |
| 35 | |
| 36 | - name: Run ShellCheck |
| 37 | shell: bash |
| 38 | run: | |
| 39 | set +e |
| 40 | fail_shellcheck=0 |
| 41 | files_checked=0 |
| 42 | |
| 43 | echo "=> Linting shell scripts with ShellCheck" |
| 44 | echo " Path: ${{ inputs.path }}" |
| 45 | echo " Severity: ${{ inputs.severity }}" |
| 46 | |
| 47 | # Build exclude argument if provided |
| 48 | exclude_arg="" |
| 49 | if [[ -n "${{ inputs.exclude }}" ]]; then |
| 50 | exclude_arg="--exclude=${{ inputs.exclude }}" |
| 51 | echo " Excluding: ${{ inputs.exclude }}" |
| 52 | fi |
| 53 | |
| 54 | # Find and check all shell scripts |
| 55 | while IFS= read -r -d '' script; do |
| 56 | echo "" |
| 57 | echo "==> CHECKING: ${script}" |
| 58 | files_checked=$((files_checked + 1)) |
| 59 | |
| 60 | if [[ -n "${exclude_arg}" ]]; then |
| 61 | shellcheck --severity="${{ inputs.severity }}" "${exclude_arg}" "${script}" |
| 62 | else |
| 63 | shellcheck --severity="${{ inputs.severity }}" "${script}" |
| 64 | fi |
| 65 | |
| 66 | rc=$? |
| 67 | if [[ $rc -ne 0 ]]; then |
| 68 | echo "==> FAILED: ${script}" |
| 69 | fail_shellcheck=1 |
| 70 | else |
| 71 | echo "==> PASSED: ${script}" |
| 72 | fi |
| 73 | done < <(find "${{ inputs.path }}" \( -name "*.sh" -o -name "*.bash" \) -type f -print0) |
| 74 | |
| 75 | echo "" |
| 76 | echo "=> Summary: ${files_checked} file(s) checked" |
| 77 | |
| 78 | if [[ ${files_checked} -eq 0 ]]; then |
| 79 | echo "=> No shell scripts found" |
| 80 | elif [[ ${fail_shellcheck} -eq 0 ]]; then |
| 81 | echo "=> All checks passed" |
| 82 | else |
| 83 | echo "=> Some checks failed" |
| 84 | exit 1 |
| 85 | fi |