diff --git a/README.md b/README.md index d2c78ac..9bcf747 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ For a full list of features see the [Buildkite Plugin Linter cli tool documentat steps: - label: ":sparkles: Lint" plugins: - - plugin-linter#v3.0.0: + - plugin-linter#v3.1.0: id: my-org/my-plugin ``` @@ -24,6 +24,10 @@ If you want to run it locally on a command line, see the [Buildkite Plugin Linte The id of the plugin (e.g. `my-org/my-plugin`) +### `image-version` + +The docker tag of the `buildkite/plugin-linter` image to use. Default is `2.0.1` + ### `readme` (optional) The filename of the plugin’s readme. Default is `README.md` diff --git a/hooks/command b/hooks/command index dec2566..42a44d7 100755 --- a/hooks/command +++ b/hooks/command @@ -2,6 +2,11 @@ set -euo pipefail +if [ -z "${BUILDKITE_PLUGIN_PLUGIN_LINTER_ID:-}" ]; then + echo ':boom: Missing id parameter in plugin configuration' + exit 1 +fi + echo "--- :docker: Fetching the latest buildkite/plugin-linter" docker pull buildkite/plugin-linter @@ -15,8 +20,10 @@ args=( "--env" "PLUGIN_ID=$BUILDKITE_PLUGIN_PLUGIN_LINTER_ID" ) +TAG=${BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION:-v2.0.1} + if [[ -n "${BUILDKITE_PLUGIN_PLUGIN_LINTER_README:-}" ]] ; then args+=("--env" "PLUGIN_README=$BUILDKITE_PLUGIN_PLUGIN_LINTER_README") fi -docker run "${args[@]}" buildkite/plugin-linter \ No newline at end of file +docker run "${args[@]}" buildkite/plugin-linter:"${TAG}" diff --git a/plugin.yml b/plugin.yml index 22b845d..b8a813a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -7,6 +7,8 @@ configuration: properties: id: type: string + image-version: + type: string readme: type: string required: diff --git a/tests/command.bats b/tests/command.bats index 196efcc..2691381 100644 --- a/tests/command.bats +++ b/tests/command.bats @@ -1,18 +1,31 @@ #!/usr/bin/env bats -load '/usr/local/lib/bats/load.bash' - # Uncomment the following to get more detail on failures of stubs # export DOCKER_STUB_DEBUG=/dev/tty -@test "Runs the linter via Docker" { +setup() { + load "${BATS_PLUGIN_PATH}/load.bash" + export BUILDKITE_PLUGIN_PLUGIN_LINTER_ID=my-plugin + # defining specific version to make all the tests not dependent on default + export BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION='latest' +} + +@test "Missing id parameter is a failure" { + unset BUILDKITE_PLUGIN_PLUGIN_LINTER_ID + + run "$PWD"/hooks/command + assert_failure + assert_output --partial 'Missing id parameter in plugin configuration' +} + +@test "Runs the linter via Docker" { stub docker \ "pull buildkite/plugin-linter : echo pulled image" \ - "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter : echo linted" + "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter:latest : echo linted" - run $PWD/hooks/command + run "$PWD"/hooks/command assert_success assert_output --partial "pulled image" @@ -21,14 +34,28 @@ load '/usr/local/lib/bats/load.bash' } @test "Supports the readme option" { - export BUILDKITE_PLUGIN_PLUGIN_LINTER_ID=my-plugin export BUILDKITE_PLUGIN_PLUGIN_LINTER_README=some-readme.yml stub docker \ "pull buildkite/plugin-linter : echo pulled image" \ - "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin --env PLUGIN_README=some-readme.yml buildkite/plugin-linter : echo linted" + "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin --env PLUGIN_README=some-readme.yml buildkite/plugin-linter:latest : echo linted" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "pulled image" + assert_output --partial "linted" + unstub docker +} + +@test "Support not specifying a tag" { + unset BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION + + stub docker \ + "pull buildkite/plugin-linter : echo pulled image" \ + "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter:v2.0.1 : echo linted" - run $PWD/hooks/command + run "$PWD"/hooks/command assert_success assert_output --partial "pulled image"