Skip to content

Commit 1108caa

Browse files
committed
Added shellcheckit helper
Demo run effect - nipy/nipype#3550
1 parent 4410bee commit 1108caa

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

shellcheckit

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

0 commit comments

Comments
 (0)