File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -eu
4+
5+ # needs to be specific to not include zsh and some people do odd /usr/bin/env bash things
6+ SHEBANG_REGEX=' ^#!\(/bin/\|/usr/bin/env \)\(sh\|bash\|dash\|ksh\)'
7+
8+ if ! git grep " $SHEBANG_REGEX " ; then
9+ echo " No shell scripts found, no need"
10+ exit 0
11+ fi
12+
13+ if [ -e .github/workflows/shellcheck.yml ]; then
14+ echo " .github/workflows/shellcheck.yml already exists -- we must be good"
15+ exit 0
16+ fi
17+ source $( readlink -f $0 | xargs dirname) /common.sh
18+
19+ git checkout -b enh-shellcheck
20+
21+ # do workflow first since straightforward
22+ cat > .github/workflows/shellcheck.yml << EOF
23+ ---
24+ name: Shellcheck
25+
26+ on:
27+ push:
28+ branches: [$branch ]
29+ pull_request:
30+ branches: [$branch ]
31+
32+ jobs:
33+ shellcheck:
34+ name: Check shell scripts
35+ runs-on: ubuntu-latest
36+
37+ steps:
38+ - name: Checkout
39+ uses: actions/checkout@v3
40+ - name: Install dependencies
41+ run: |
42+ sudo apt update && sudo apt install -y shellcheck
43+
44+ - name: shellcheck
45+ run: |
46+ git grep -l '$SHEBANG_REGEX ' | xargs shellcheck
47+ EOF
48+ git add .github/workflows/shellcheck.yml
49+ git commit -m " Add github action to shellcheck $branch on push and PRs"
50+
51+
52+ git grep -l " $SHEBANG_REGEX " | xargs shellcheck
You can’t perform that action at this time.
0 commit comments