Skip to content

Commit

Permalink
Merge pull request #48 from buildkite-plugins/toote_image_versioning
Browse files Browse the repository at this point in the history
Pin image to actual version (and add option to change it)
  • Loading branch information
pzeballos authored Feb 21, 2023
2 parents b509b8d + a46aa12 commit 269d769
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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`
Expand Down
9 changes: 8 additions & 1 deletion hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
docker run "${args[@]}" buildkite/plugin-linter:"${TAG}"
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ configuration:
properties:
id:
type: string
image-version:
type: string
readme:
type: string
required:
Expand Down
43 changes: 35 additions & 8 deletions tests/command.bats
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 269d769

Please sign in to comment.