Skip to content

Commit d622654

Browse files
[Testing:Developer] Automated ShellCheck linting (Submitty#8269)
Co-authored-by: Viyerelu23333 <[email protected]>
1 parent cf22c6b commit d622654

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

.github/workflows/submitty_ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ jobs:
236236
flags: autograder
237237

238238

239+
shellcheck:
240+
name: ShellCheck
241+
runs-on: ubuntu-20.04
242+
steps:
243+
- uses: actions/checkout@v2
244+
- name: install ShellCheck
245+
run: sudo apt-get install -y shellcheck
246+
- name: Run ShellCheck
247+
run: python3 run_shellcheck.py # Uses the default Python installed with Ubuntu
248+
249+
239250
e2e:
240251
needs:
241252
- js-lint
@@ -245,6 +256,7 @@ jobs:
245256
- python-lint
246257
- python-unit
247258
- css-lint
259+
- shellcheck
248260
runs-on: ubuntu-20.04
249261
services:
250262
postgres:

.shellcheckignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
site/**/*.sh
2+
tests/**/*.sh
3+
.git/**/*.sh
4+
.setup/INSTALL_SUBMITTY_HELPER.sh
5+
.setup/bootstrap.sh
6+
.setup/common/common_env.sh
7+
.setup/testing/print_debug.sh
8+
.setup/testing/before_install.sh
9+
.setup/testing/autograder.sh
10+
.setup/testing/setup_test_suite.sh
11+
.setup/testing/setup_ldap.sh
12+
.setup/testing/setup.sh
13+
.setup/vagrant/db_users.sh
14+
.setup/install_submitty/install_bin.sh
15+
.setup/install_submitty/install_site.sh
16+
.setup/vagrant/setup_vagrant.sh
17+
.setup/vagrant/setup_ldap.sh
18+
.setup/update_system.sh
19+
.setup/bin/recreate_sample_courses.sh
20+
.setup/bin/update_googlefonts.sh
21+
.setup/bin/versions.sh
22+
.setup/bin/MatlabInstall.sh
23+
.setup/bin/update_repos.sh
24+
.setup/install_system.sh
25+
.setup/distro_setup/ubuntu/16.04/setup_distro.sh
26+
.setup/distro_setup/ubuntu/18.04/setup_distro.sh
27+
.setup/distro_setup/ubuntu/20.04/setup_distro.sh
28+
.setup/distro_setup/ubuntu/rpi.sh
29+
.setup/distro_setup/setup_distro.sh
30+
.setup/distro_setup/debian/8/setup_distro.sh
31+
sbin/create_term.sh
32+
sbin/killall_shippers_and_workers.sh
33+
sbin/create_course.sh
34+
sbin/replay_experiment_script.sh
35+
sbin/build_course.sh
36+
bin/build_homework_function.sh

run_shellcheck.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This script serves as a wrapper around ShellCheck to run ShellCheck only
2+
# files listed in the .shellcheckignore script since ShellCheck does not support
3+
# this functionality by default
4+
5+
from pathlib import Path
6+
import subprocess
7+
8+
ignored_files = set()
9+
with open('.shellcheckignore', 'r') as ignore_file:
10+
for line in map(str.strip, ignore_file.readlines()):
11+
if '*' in line:
12+
ignored_files.update(Path('.').rglob(line))
13+
else:
14+
ignored_files.add(Path('.') / line)
15+
16+
all_shell_scripts = set(Path('.').rglob('*.sh'))
17+
18+
shell_scripts_to_check = [str(x) for x in all_shell_scripts.difference(ignored_files)]
19+
20+
return_code = 0
21+
for script in shell_scripts_to_check:
22+
process = subprocess.run(['shellcheck', '-Calways', script], stdout=subprocess.PIPE)
23+
out = process.stdout.decode("utf-8")
24+
if out != '':
25+
print(out)
26+
if process.returncode != 0:
27+
return_code = process.returncode
28+
29+
exit(return_code)

0 commit comments

Comments
 (0)