|
| 1 | +--- |
| 2 | +name: shellcheck |
| 3 | +on: [push, pull_request] |
| 4 | +jobs: |
| 5 | + shellcheck: |
| 6 | + runs-on: ubuntu-latest |
| 7 | + env: |
| 8 | + SHELLCHECKOPTS: -a -x -s sh -P SCRIPTDIR -o require-variable-braces -o deprecate-which -o avoid-nullary-conditions |
| 9 | + # -o check-set-e-suppressed -o check-extra-masked-returns |
| 10 | + steps: |
| 11 | + - name: Install shellcheck |
| 12 | + shell: sh |
| 13 | + run: | |
| 14 | + case ${{ runner.os }} |
| 15 | + in |
| 16 | + (macOS) osvariant=darwin ;; |
| 17 | + (Linux) osvariant=linux ;; |
| 18 | + (Windows) |
| 19 | + echo 'Windows runners are not supported.' >&2 |
| 20 | + exit 1 |
| 21 | + ;; |
| 22 | + (*) |
| 23 | + printf 'unknown runner.os: %s\n' '${{ runner.os }}' >&2 |
| 24 | + exit 1 |
| 25 | + ;; |
| 26 | + esac |
| 27 | + case ${{ runner.arch }} |
| 28 | + in |
| 29 | + (X86) |
| 30 | + echo 'x86 runners not supported.' >&2 |
| 31 | + exit 1 |
| 32 | + ;; |
| 33 | + (X64) arch=x86_64 ;; |
| 34 | + (ARM) arch=armv6hf ;; |
| 35 | + (ARM64) arch=aarch64 ;; |
| 36 | + (*) |
| 37 | + printf 'unknown runner.arch: %s\n' '${{ runner.arch }}' >&2 |
| 38 | + exit 1 |
| 39 | + ;; |
| 40 | + esac |
| 41 | +
|
| 42 | + scversion=stable # stable, latest (nightly), or tag (v0.8.0) |
| 43 | +
|
| 44 | + baseurl=https://github.com/koalaman/shellcheck/releases/download |
| 45 | + filename=shellcheck-${scversion}.${osvariant}.${arch}.tar.xz |
| 46 | +
|
| 47 | + mkdir -p /usr/local/bin |
| 48 | + curl -s -L "${baseurl}/${scversion}/${filename}" \ |
| 49 | + | tar -x -J -O "shellcheck-${scversion}/shellcheck" \ |
| 50 | + >/usr/local/bin/shellcheck |
| 51 | + chmod +x /usr/local/bin/shellcheck |
| 52 | + - name: Display shellcheck version |
| 53 | + shell: sh |
| 54 | + run: | |
| 55 | + command -v shellcheck |
| 56 | + shellcheck --version |
| 57 | + - name: Check out repository code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + fetch-depth: 0 |
| 61 | + - name: Run shellcheck |
| 62 | + shell: sh |
| 63 | + run: | |
| 64 | + # shellcheck |
| 65 | +
|
| 66 | + if test -d ./explorer |
| 67 | + then |
| 68 | + # check explorers |
| 69 | + find ./explorer -type f \ |
| 70 | + -exec awk 'FNR==1{exit !/^#!\/bin\/sh/}' {} \; \ |
| 71 | + -exec shellcheck ${SHELLCHECKOPTS-} {} + \ |
| 72 | + || steprc=1 |
| 73 | + fi |
| 74 | +
|
| 75 | + # Check types |
| 76 | + for type in ./type/*/. |
| 77 | + do |
| 78 | + rc=0 |
| 79 | + type=${type%/.} |
| 80 | +
|
| 81 | + for c in \ |
| 82 | + "${type}"/manifest \ |
| 83 | + "${type}"/gencode-local \ |
| 84 | + "${type}"/gencode-remote |
| 85 | + do |
| 86 | + test -e "${c}" || continue |
| 87 | +
|
| 88 | + shellcheck ${SHELLCHECKOPTS-} "${c}" || rc=1 |
| 89 | + done |
| 90 | +
|
| 91 | + if test -d "${type}/explorer" |
| 92 | + then |
| 93 | + find "${type}/explorer" -type f \ |
| 94 | + -exec awk 'FNR==1{exit !/^#!\/bin\/sh/}' {} \; \ |
| 95 | + -exec shellcheck ${SHELLCHECKOPTS-} {} + \ |
| 96 | + || rc=1 |
| 97 | + fi |
| 98 | +
|
| 99 | + if test -d "${type}/files" |
| 100 | + then |
| 101 | + find "${type}/files" -type f \ |
| 102 | + \( -name '*.sh' -o -exec awk 'FNR==1{exit !/^#!\/bin\/sh/}' {} \; \) \ |
| 103 | + -exec shellcheck ${SHELLCHECKOPTS-} {} + \ |
| 104 | + || rc=1 |
| 105 | + fi |
| 106 | +
|
| 107 | + if test $((rc)) -ne 0 |
| 108 | + then |
| 109 | + steprc=1 |
| 110 | + fi |
| 111 | + done |
| 112 | +
|
| 113 | + exit $((steprc)) |
0 commit comments