From 34e26cf14324bf17f5813183356624b7a4f92cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 30 Jan 2023 19:22:59 -0300 Subject: [PATCH 1/5] Added new option for changing where files are found --- hooks/pre-exit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/pre-exit b/hooks/pre-exit index 4a115a7..f585529 100755 --- a/hooks/pre-exit +++ b/hooks/pre-exit @@ -5,6 +5,7 @@ TOKEN_ENV_NAME="${BUILDKITE_PLUGIN_TEST_COLLECTOR_API_TOKEN_ENV_NAME:-BUILDKITE_ FILES_PATTERN="${BUILDKITE_PLUGIN_TEST_COLLECTOR_FILES:-}" FORMAT="${BUILDKITE_PLUGIN_TEST_COLLECTOR_FORMAT:-}" TIMEOUT="${BUILDKITE_PLUGIN_TEST_COLLECTOR_TIMEOUT:-30}" +BASE_PATH="${BUILDKITE_PLUGIN_TEST_COLLECTOR_BASE_PATH:-.}" DEBUG="false" if [[ "${BUILDKITE_PLUGIN_TEST_COLLECTOR_DEBUG:-}" =~ ^(true|on|1|always)$ ]]; then @@ -101,7 +102,7 @@ fi matching_files=() while IFS=$'' read -r matching_file ; do matching_files+=("$matching_file") -done < <("${FIND_CMD[@]}" . -path "./${FILES_PATTERN}") +done < <("${FIND_CMD[@]}" "${BASE_PATH}" -path "${BASE_PATH}/${FILES_PATTERN}") if [[ "${#matching_files[@]}" -eq "0" ]]; then echo "No files found matching '${FILES_PATTERN}'" From 1d500e8899a5c94cf234940a69a968907c9a2896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 30 Jan 2023 19:23:17 -0300 Subject: [PATCH 2/5] Added new option to plugin definition and tests --- plugin.yml | 2 ++ tests/pre-exit-success.bats | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index 571b684..1422f40 100644 --- a/plugin.yml +++ b/plugin.yml @@ -9,6 +9,8 @@ configuration: type: string api-url: type: string + base-path: + type: string branches: type: string debug: diff --git a/tests/pre-exit-success.bats b/tests/pre-exit-success.bats index 4d5d2e5..7271769 100644 --- a/tests/pre-exit-success.bats +++ b/tests/pre-exit-success.bats @@ -166,4 +166,20 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \* assert_output --partial "against https://test-api.example.com/v2" unstub curl -} \ No newline at end of file +} + + +@test "Base path can be changed" { + export BUILDKITE_PLUGIN_TEST_COLLECTOR_BASE_PATH='/test' + + stub find "/test -path /test/\*\*/\*/junit-1.xml : echo '/test/tests/fixtures/junit-1.xml'" + stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* -H \* : echo 'curl success'" + + run "${PWD}/hooks/pre-exit" + + unstub curl + unstub find + + assert_success + assert_output --partial "curl success" +} From 1356ae288c32e0722eaeeaadd11b65bfd3293389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 30 Jan 2023 19:23:29 -0300 Subject: [PATCH 3/5] Added documentation for new option --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f18eb73..f58e282 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ Default value: `BUILDKITE_ANALYTICS_TOKEN` Full URL for the API to upload to. Defaults to `https://analytics-api.buildkite.com/v1/uploads` +#### `base-path` (string) + +Where to search for files to upload. Defaults to the working directory `.` + #### `branches` (string) String containing a regex to only do an upload in branches that match it (using the case-insensitive bash `=~` operator against the `BUILDKITE_BRANCH` environment variable). From e8480181ec862b59d0cc4f43750eb36f2b265b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 30 Jan 2023 19:32:59 -0300 Subject: [PATCH 4/5] Added test for curl failures (closes #37) --- tests/pre-exit-success.bats | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/pre-exit-success.bats b/tests/pre-exit-success.bats index 7271769..72344da 100644 --- a/tests/pre-exit-success.bats +++ b/tests/pre-exit-success.bats @@ -168,7 +168,6 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \* unstub curl } - @test "Base path can be changed" { export BUILDKITE_PLUGIN_TEST_COLLECTOR_BASE_PATH='/test' @@ -183,3 +182,15 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \* assert_success assert_output --partial "curl success" } + +@test "Absorb curl failures" { + stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* -H \* : exit 10" + + run "$PWD/hooks/pre-exit" + + unstub curl + + assert_success + assert_output --partial "Uploading './tests/fixtures/junit-1.xml'..." + assert_output --partial "Error uploading, will continue" +} \ No newline at end of file From 34789339321cb7e920f0a5b9d076669718c40cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 30 Jan 2023 19:50:01 -0300 Subject: [PATCH 5/5] Updated version in the readme in preparation for next release --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f58e282..37797b3 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ steps: - label: "🔨 Test" command: "make test" plugins: - - test-collector#v1.5.0: + - test-collector#v1.6.0: files: "test/junit-*.xml" format: "junit" ``` @@ -101,7 +101,7 @@ steps: - label: "🔨 Test" command: "make test" plugins: - - test-collector#v1.5.0: + - test-collector#v1.6.0: files: "test-data-*.json" format: "json" ``` @@ -122,7 +122,7 @@ steps: - label: "🔍 Test Analytics" command: buildkite-agent artifact download tests-*.xml plugins: - - test-collector#v1.5.0: + - test-collector#v1.6.0: files: "tests-*.xml" format: "junit" ``` @@ -136,7 +136,7 @@ steps: - label: "🔨 Test" command: "make test" plugins: - - test-collector#v1.5.0: + - test-collector#v1.6.0: files: "test-data-*.json" format: "json" branches: "-qa$" @@ -149,7 +149,7 @@ steps: - label: "🔨 Test" command: "make test" plugins: - - test-collector#v1.5.0: + - test-collector#v1.6.0: files: "test-data-*.json" format: "json" exclude-branches: "^legacy$" @@ -162,7 +162,7 @@ steps: - label: "🔨 Test" command: "make test" plugins: - - test-collector#v1.5.0: + - test-collector#v1.6.0: files: "test-data-*.json" format: "json" branches: "^stage-"