Skip to content

Commit 6d906ad

Browse files
authored
Merge pull request #239 from erict-square/erict/allow-running-outside-of-docker
Allow running the annotate script outside of Docker
2 parents a7a0cb5 + c60c126 commit 6d906ad

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ The docker image to use for running the analysis code. Must be a valid image ref
108108

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

111+
### `run-in-docker` (optional, boolean)
112+
113+
Default: `true`
114+
115+
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.
116+
111117
## Developing
112118

113119
To run testing, shellchecks and plugin linting use use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli).

hooks/command

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,22 @@ fi
4242
echo "--- :junit: Processing the junits"
4343

4444
set +e
45-
docker \
46-
--log-level "error" \
47-
run \
48-
--rm \
49-
--volume "$artifacts_dir:/junits" \
50-
--volume "$PLUGIN_DIR/ruby:/src" \
51-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
52-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
53-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
54-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED:-}" \
55-
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
56-
> "$annotation_path"
45+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER:-true}" =~ "true" ]]; then
46+
docker \
47+
--log-level "error" \
48+
run \
49+
--rm \
50+
--volume "$artifacts_dir:/junits" \
51+
--volume "$PLUGIN_DIR/ruby:/src" \
52+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
53+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
54+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
55+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED:-}" \
56+
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
57+
> "$annotation_path"
58+
else
59+
ruby "${PLUGIN_DIR}/ruby/bin/annotate" "${artifacts_dir}" > "$annotation_path"
60+
fi
5761

5862
exit_code=$?
5963
set -e

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ configuration:
3030
type: integer
3131
ruby-image:
3232
type: string
33+
run-in-docker:
34+
type: boolean
3335
required:
3436
- artifacts
3537
additionalProperties: false

tests/command.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,33 @@ DOCKER_STUB_DEFAULT_OPTIONS='--log-level error run --rm --volume \* --volume \*
527527
unstub buildkite-agent
528528
unstub docker
529529
rm "${annotation_input}"
530+
}
531+
532+
@test "does not run in docker when run-in-docker is false" {
533+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
534+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
535+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER=false
536+
537+
stub mktemp \
538+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
539+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
540+
541+
stub buildkite-agent \
542+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
543+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
544+
545+
stub ruby \
546+
"/plugin/hooks/../ruby/bin/annotate /plugin/${artifacts_tmp} : echo '<details>Failure</details>' && exit 64"
547+
548+
run "$PWD/hooks/command"
549+
550+
assert_success
551+
552+
assert_output --partial "Annotation added with context junit and style error"
553+
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'
554+
555+
unstub mktemp
556+
unstub buildkite-agent
557+
unstub ruby
558+
rm "${annotation_input}"
530559
}

0 commit comments

Comments
 (0)