File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /bin/bash
2-
32set -eu
43
54# If you build HEAD the pipeline.sh step, because it runs first, won't yet
2221
2322 - label: run shellcheck
2423 plugins:
25- ${BUILDKITE_REPO} #${commit} :
24+ shellcheck #${commit} :
2625 files:
2726 - hooks/*
2827 - buildkite/*.sh
Original file line number Diff line number Diff line change @@ -19,17 +19,22 @@ function plugin_read_list() {
1919 fi
2020}
2121
22+ IFS=$' \n\t '
2223files=()
2324
24- for pattern in $( plugin_read_list FILES) ; do
25- while IFS=$' \n ' read -r line; do
26- files+=(" $line " )
27- done < <( ls -1 " $pattern " 2> /dev/null)
25+ # Evaluate all the globs and return the files that exist
26+ for file in $( plugin_read_list FILES) ; do
27+ if [[ -e $file ]] ; then
28+ files+=(" $file " )
29+ fi
2830done
2931
3032if [[ -z ${files:- } ]] ; then
3133 echo " No files found to shellcheck"
3234 exit 1
3335fi
3436
35- docker run --rm -v " $PWD :/mnt" koalaman/shellcheck " ${files[@]} "
37+ echo " +++ Running shellcheck on ${# files[@]} files"
38+ if docker run --rm -v " $PWD :/mnt" koalaman/shellcheck " ${files[@]} " ; then
39+ echo " Files are ok ✅"
40+ fi
Original file line number Diff line number Diff line change 22
33load ' /usr/local/lib/bats/load.bash'
44
5- export DOCKER_STUB_DEBUG=/dev/tty
6- export LS_STUB_DEBUG=/dev/tty
5+ # export DOCKER_STUB_DEBUG=/dev/tty
76
87@test " Shellcheck a single file" {
9- export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0=" llamas .sh"
8+ export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0=" tests/testdata/test .sh"
109
11- stub ls \
12- " -1 llamas.sh : echo llamas.sh"
10+ stub docker \
11+ " run --rm -v $PWD :/mnt koalaman/shellcheck tests/testdata/test.sh : echo testing test.sh"
12+
13+ run " $PWD /hooks/command"
14+
15+ assert_success
16+ assert_output --partial " testing test.sh"
17+
18+ unstub docker
19+ }
20+
21+ @test " Shellcheck multiple files" {
22+ export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0=" tests/testdata/test.sh"
23+ export BUILDKITE_PLUGIN_SHELLCHECK_FILES_1=" tests/testdata/subdir/*"
24+ export BUILDKITE_PLUGIN_SHELLCHECK_FILES_2=" missing"
1325
1426 stub docker \
15- " run --rm -v $PWD :/mnt koalaman/shellcheck llamas.sh : echo testing llamas .sh"
27+ " run --rm -v $PWD :/mnt koalaman/shellcheck tests/testdata/test.sh tests/testdata/subdir/ llamas.sh tests/testdata/subdir/shell\ with\ space.sh' : echo testing test .sh"
1628
1729 run " $PWD /hooks/command"
1830
1931 assert_success
20- assert_output --partial " testing llamas .sh"
32+ assert_output --partial " testing test .sh"
2133
22- unstub ls
2334 unstub docker
2435}
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ echo $UNDEFINED_VAR
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ echo " Ain't nobody likes spaces in filenames"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ echo blah
You can’t perform that action at this time.
0 commit comments