Skip to content

Commit

Permalink
Merge pull request #57 from davidblum/enable-configurable-image
Browse files Browse the repository at this point in the history
enable image configuration
  • Loading branch information
jeremybumsted authored Oct 2, 2024
2 parents db163c2 + b5e4ed9 commit 415387e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ steps:
- plugin-linter#v3.3.0:
id: shellcheck

- label: selftest - fork
plugins:
- ${BUILDKITE_PULL_REQUEST_REPO}#${BUILDKITE_COMMIT}:
files:
- hooks/*
- buildkite/*.sh
if: build.pull_request.repository.fork == true

- label: selftest
plugins:
- shellcheck#${BUILDKITE_COMMIT}:
files:
- hooks/*
- buildkite/*.sh
if: build.pull_request.repository.fork == false
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ Version of docker image to use.

Default: `latest`

### `image` (string)

Which shell check image to use.

Default: `koalaman/shellcheck`

## Developing

To run the tests:

```bash
docker-compose run --rm tests bats tests
```

## License

MIT (see [LICENSE](LICENSE))
5 changes: 5 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
tests:
image: buildkite/plugin-tester:v4.1.1
volumes:
- ".:/plugin"
3 changes: 2 additions & 1 deletion hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ while IFS=$'\n' read -r option; do
done < <(plugin_read_list OPTIONS)

BUILDKITE_PLUGIN_SHELLCHECK_VERSION="${BUILDKITE_PLUGIN_SHELLCHECK_VERSION:-stable}"
BUILDKITE_PLUGIN_SHELLCHECK_IMAGE="${BUILDKITE_PLUGIN_SHELLCHECK_IMAGE:-koalaman/shellcheck}"

echo "+++ Running shellcheck on ${#files[@]} files"
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" "koalaman/shellcheck:$BUILDKITE_PLUGIN_SHELLCHECK_VERSION" "${options[@]+${options[@]}}" "${files[@]}"; then
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" "$BUILDKITE_PLUGIN_SHELLCHECK_IMAGE:$BUILDKITE_PLUGIN_SHELLCHECK_VERSION" "${options[@]+${options[@]}}" "${files[@]}"; then
echo "Files are ok ✅"
else
exit 1
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ configuration:
minItems: 1
version:
type: [string]
image:
type: [string]
required:
- files
55 changes: 55 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,58 @@ load "${BATS_PLUGIN_PATH}/load.bash"

unstub docker
}

@test "Shellcheck uses default image when not specified" {
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
unset BUILDKITE_PLUGIN_SHELLCHECK_IMAGE
unset BUILDKITE_PLUGIN_SHELLCHECK_VERSION

stub docker \
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/test.sh : echo running shellcheck on test.sh"

run "$PWD/hooks/command"

assert_success
assert_output --partial "Running shellcheck on 1 files"
assert_output --partial "running shellcheck on test.sh"
assert_output --partial "Files are ok"

unstub docker
}

@test "Shellcheck uses default image when specified" {
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
export BUILDKITE_PLUGIN_SHELLCHECK_IMAGE="foo/shellcheck"
export BUILDKITE_PLUGIN_SHELLCHECK_VERSION="bar"

stub docker \
"run --rm -v $PWD:/mnt --workdir /mnt foo/shellcheck:bar --color=always tests/testdata/test.sh : echo running shellcheck on test.sh"

run "$PWD/hooks/command"

assert_success
assert_output --partial "Running shellcheck on 1 files"
assert_output --partial "running shellcheck on test.sh"
assert_output --partial "Files are ok"

unstub docker
}


@test "Shellcheck uses default image when empty string set" {
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
export BUILDKITE_PLUGIN_SHELLCHECK_IMAGE=""
export BUILDKITE_PLUGIN_SHELLCHECK_VERSION="stable"

stub docker \
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck:stable --color=always tests/testdata/test.sh : echo running shellcheck on test.sh"

run "$PWD/hooks/command"

assert_success
assert_output --partial "Running shellcheck on 1 files"
assert_output --partial "running shellcheck on test.sh"
assert_output --partial "Files are ok"

unstub docker
}

0 comments on commit 415387e

Please sign in to comment.