Skip to content

Commit 415387e

Browse files
Merge pull request #57 from davidblum/enable-configurable-image
enable image configuration
2 parents db163c2 + b5e4ed9 commit 415387e

6 files changed

Lines changed: 87 additions & 1 deletion

File tree

.buildkite/pipeline.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ steps:
1515
- plugin-linter#v3.3.0:
1616
id: shellcheck
1717

18+
- label: selftest - fork
19+
plugins:
20+
- ${BUILDKITE_PULL_REQUEST_REPO}#${BUILDKITE_COMMIT}:
21+
files:
22+
- hooks/*
23+
- buildkite/*.sh
24+
if: build.pull_request.repository.fork == true
25+
1826
- label: selftest
1927
plugins:
2028
- shellcheck#${BUILDKITE_COMMIT}:
2129
files:
2230
- hooks/*
2331
- buildkite/*.sh
32+
if: build.pull_request.repository.fork == false

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ Version of docker image to use.
4949

5050
Default: `latest`
5151

52+
### `image` (string)
53+
54+
Which shell check image to use.
55+
56+
Default: `koalaman/shellcheck`
57+
58+
## Developing
59+
60+
To run the tests:
61+
62+
```bash
63+
docker-compose run --rm tests bats tests
64+
```
65+
5266
## License
5367

5468
MIT (see [LICENSE](LICENSE))

compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
tests:
3+
image: buildkite/plugin-tester:v4.1.1
4+
volumes:
5+
- ".:/plugin"

hooks/command

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ while IFS=$'\n' read -r option; do
102102
done < <(plugin_read_list OPTIONS)
103103

104104
BUILDKITE_PLUGIN_SHELLCHECK_VERSION="${BUILDKITE_PLUGIN_SHELLCHECK_VERSION:-stable}"
105+
BUILDKITE_PLUGIN_SHELLCHECK_IMAGE="${BUILDKITE_PLUGIN_SHELLCHECK_IMAGE:-koalaman/shellcheck}"
105106

106107
echo "+++ Running shellcheck on ${#files[@]} files"
107-
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" "koalaman/shellcheck:$BUILDKITE_PLUGIN_SHELLCHECK_VERSION" "${options[@]+${options[@]}}" "${files[@]}"; then
108+
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" "$BUILDKITE_PLUGIN_SHELLCHECK_IMAGE:$BUILDKITE_PLUGIN_SHELLCHECK_VERSION" "${options[@]+${options[@]}}" "${files[@]}"; then
108109
echo "Files are ok ✅"
109110
else
110111
exit 1

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ configuration:
2020
minItems: 1
2121
version:
2222
type: [string]
23+
image:
24+
type: [string]
2325
required:
2426
- files

tests/run.bats

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,58 @@ load "${BATS_PLUGIN_PATH}/load.bash"
189189

190190
unstub docker
191191
}
192+
193+
@test "Shellcheck uses default image when not specified" {
194+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
195+
unset BUILDKITE_PLUGIN_SHELLCHECK_IMAGE
196+
unset BUILDKITE_PLUGIN_SHELLCHECK_VERSION
197+
198+
stub docker \
199+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/test.sh : echo running shellcheck on test.sh"
200+
201+
run "$PWD/hooks/command"
202+
203+
assert_success
204+
assert_output --partial "Running shellcheck on 1 files"
205+
assert_output --partial "running shellcheck on test.sh"
206+
assert_output --partial "Files are ok"
207+
208+
unstub docker
209+
}
210+
211+
@test "Shellcheck uses default image when specified" {
212+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
213+
export BUILDKITE_PLUGIN_SHELLCHECK_IMAGE="foo/shellcheck"
214+
export BUILDKITE_PLUGIN_SHELLCHECK_VERSION="bar"
215+
216+
stub docker \
217+
"run --rm -v $PWD:/mnt --workdir /mnt foo/shellcheck:bar --color=always tests/testdata/test.sh : echo running shellcheck on test.sh"
218+
219+
run "$PWD/hooks/command"
220+
221+
assert_success
222+
assert_output --partial "Running shellcheck on 1 files"
223+
assert_output --partial "running shellcheck on test.sh"
224+
assert_output --partial "Files are ok"
225+
226+
unstub docker
227+
}
228+
229+
230+
@test "Shellcheck uses default image when empty string set" {
231+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
232+
export BUILDKITE_PLUGIN_SHELLCHECK_IMAGE=""
233+
export BUILDKITE_PLUGIN_SHELLCHECK_VERSION="stable"
234+
235+
stub docker \
236+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/test.sh : echo running shellcheck on test.sh"
237+
238+
run "$PWD/hooks/command"
239+
240+
assert_success
241+
assert_output --partial "Running shellcheck on 1 files"
242+
assert_output --partial "running shellcheck on test.sh"
243+
assert_output --partial "Files are ok"
244+
245+
unstub docker
246+
}

0 commit comments

Comments
 (0)