|
| 1 | +name: Shellcheck Lint |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + # Run workflow on every push |
| 7 | + # only if a file within the specified paths has been changed: |
| 8 | + - 'lsix' |
| 9 | + |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + # Run workflow on every push |
| 13 | + # only if a file within the specified paths has been changed: |
| 14 | + - 'lsix' |
| 15 | + |
| 16 | + # Allows you to run this workflow manually from the Actions tab |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: Shellcheck Lint |
| 22 | + |
| 23 | + # This job runs on Linux |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + # Required to access files of this repository |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + |
| 30 | + # Download Shellcheck and add it to the workflow path |
| 31 | + - name: Download Shellcheck |
| 32 | + run: | |
| 33 | + wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv |
| 34 | + chmod +x shellcheck-stable/shellcheck |
| 35 | + # Verify that Shellcheck can be executed |
| 36 | + - name: Check Shellcheck Version |
| 37 | + run: | |
| 38 | + shellcheck-stable/shellcheck --version |
| 39 | +
|
| 40 | + # Run Shellcheck on repository |
| 41 | + # --- |
| 42 | + # https://github.com/koalaman/shellcheck |
| 43 | + # --- |
| 44 | + # Excluded checks: |
| 45 | + # https://www.shellcheck.net/wiki/SC1091 -- Not following: /etc/rc.status was... |
| 46 | + # https://www.shellcheck.net/wiki/SC1090 -- Can't follow non-constant source. .. |
| 47 | + # --- |
| 48 | + - name: Run Shellcheck |
| 49 | + run: | |
| 50 | + set +e |
| 51 | + find ./*/ -type f | while read -r sh; do |
| 52 | + if [ "$(file --brief --mime-type "$sh")" == 'text/x-shellscript' ]; then |
| 53 | + echo "shellcheck'ing $sh" |
| 54 | + if ! shellcheck-stable/shellcheck --color=always --severity=warning --exclude=SC1091,SC1090 "$sh"; then |
| 55 | + touch some_scripts_have_failed_shellcheck |
| 56 | + fi |
| 57 | + fi |
| 58 | + done |
| 59 | + if [ -f ./some_scripts_have_failed_shellcheck ]; then |
| 60 | + echo "Shellcheck failed for one or more shellscript(s)" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
0 commit comments