From a8e1af2678fda4e1a86cc6c21a9cb68842f88aff Mon Sep 17 00:00:00 2001 From: David Blum Date: Mon, 30 Sep 2024 11:44:11 -0600 Subject: [PATCH 1/5] enable image configuration --- README.md | 6 ++++++ hooks/command | 3 ++- plugin.yml | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28359f1..a686b1c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,12 @@ Version of docker image to use. Default: `latest` +## `image` (string) + +Which shell check image to use. + +Default: `koalaman/shellcheck` + ## License MIT (see [LICENSE](LICENSE)) diff --git a/hooks/command b/hooks/command index 17c8b0d..bedf226 100755 --- a/hooks/command +++ b/hooks/command @@ -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 diff --git a/plugin.yml b/plugin.yml index 32968bc..e1cd05c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -20,5 +20,7 @@ configuration: minItems: 1 version: type: [string] + image: + type: [string] required: - files From 353b115e45a8b5477a7a3c68a3384a8764c0db3d Mon Sep 17 00:00:00 2001 From: David Blum Date: Mon, 30 Sep 2024 12:04:50 -0600 Subject: [PATCH 2/5] correct heading indentation for image config in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a686b1c..5f020fd 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Version of docker image to use. Default: `latest` -## `image` (string) +### `image` (string) Which shell check image to use. From fe1d4b567ae0663f925b3cf86326fe4cdd4ea8f2 Mon Sep 17 00:00:00 2001 From: Ben McNicholl Date: Tue, 1 Oct 2024 15:33:48 +1000 Subject: [PATCH 3/5] Add tests for new config --- README.md | 8 ++++++++ compose.yml | 5 +++++ tests/run.bats | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 compose.yml diff --git a/README.md b/README.md index 5f020fd..ff09430 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,14 @@ 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)) diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..d35d129 --- /dev/null +++ b/compose.yml @@ -0,0 +1,5 @@ +services: + tests: + image: buildkite/plugin-tester:v4.1.1 + volumes: + - ".:/plugin" diff --git a/tests/run.bats b/tests/run.bats index 6e9c699..615e93e 100644 --- a/tests/run.bats +++ b/tests/run.bats @@ -189,3 +189,39 @@ 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 +} From 72865f0655b9bfa29827d6d861bbd9a41051fe22 Mon Sep 17 00:00:00 2001 From: Jeremy Bumsted Date: Wed, 2 Oct 2024 12:54:01 -0600 Subject: [PATCH 4/5] add some more tests for custom image config --- tests/run.bats | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/run.bats b/tests/run.bats index 615e93e..b20390b 100644 --- a/tests/run.bats +++ b/tests/run.bats @@ -225,3 +225,22 @@ load "${BATS_PLUGIN_PATH}/load.bash" 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 +} From b5e4ed9feb3c3b8983b6c943a07a921c297b37d5 Mon Sep 17 00:00:00 2001 From: Jeremy Bumsted Date: Wed, 2 Oct 2024 12:55:19 -0600 Subject: [PATCH 5/5] modify pipeline to run selftest on fork PRs --- .buildkite/pipeline.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 670d0bf..cca0023 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -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