Skip to content

Commit

Permalink
Merge pull request #239 from erict-square/erict/allow-running-outside…
Browse files Browse the repository at this point in the history
…-of-docker

Allow running the annotate script outside of Docker
  • Loading branch information
mcncl authored Dec 10, 2024
2 parents a7a0cb5 + c60c126 commit 6d906ad
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ The docker image to use for running the analysis code. Must be a valid image ref

Default: `ruby:3.1-alpine@sha256:a39e26d0598837f08c75a42c8b0886d9ed5cc862c4b535662922ee1d05272fca`

### `run-in-docker` (optional, boolean)

Default: `true`

Controls whether the JUnit processing should run inside a Docker container. When set to `false`, the processing will run directly on the host using the system's Ruby installation.

## Developing

To run testing, shellchecks and plugin linting use use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli).
Expand Down
28 changes: 16 additions & 12 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ fi
echo "--- :junit: Processing the junits"

set +e
docker \
--log-level "error" \
run \
--rm \
--volume "$artifacts_dir:/junits" \
--volume "$PLUGIN_DIR/ruby:/src" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED:-}" \
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
> "$annotation_path"
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER:-true}" =~ "true" ]]; then
docker \
--log-level "error" \
run \
--rm \
--volume "$artifacts_dir:/junits" \
--volume "$PLUGIN_DIR/ruby:/src" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED:-}" \
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
> "$annotation_path"
else
ruby "${PLUGIN_DIR}/ruby/bin/annotate" "${artifacts_dir}" > "$annotation_path"
fi

exit_code=$?
set -e
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ configuration:
type: integer
ruby-image:
type: string
run-in-docker:
type: boolean
required:
- artifacts
additionalProperties: false
29 changes: 29 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,33 @@ DOCKER_STUB_DEFAULT_OPTIONS='--log-level error run --rm --volume \* --volume \*
unstub buildkite-agent
unstub docker
rm "${annotation_input}"
}

@test "does not run in docker when run-in-docker is false" {
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER=false

stub mktemp \
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"

stub buildkite-agent \
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"

stub ruby \
"/plugin/hooks/../ruby/bin/annotate /plugin/${artifacts_tmp} : echo '<details>Failure</details>' && exit 64"

run "$PWD/hooks/command"

assert_success

assert_output --partial "Annotation added with context junit and style error"
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'

unstub mktemp
unstub buildkite-agent
unstub ruby
rm "${annotation_input}"
}

0 comments on commit 6d906ad

Please sign in to comment.