From 94f3f777f25085e6f6613ad65ce69fbc0205eba1 Mon Sep 17 00:00:00 2001 From: "Ma. Paula Zeballos" Date: Thu, 9 Jun 2022 21:38:59 -0300 Subject: [PATCH 1/5] fix find files for older systems --- hooks/pre-exit | 5 ++++- tests/pre-exit-success.bats | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hooks/pre-exit b/hooks/pre-exit index 3003aa5..bb8c003 100755 --- a/hooks/pre-exit +++ b/hooks/pre-exit @@ -83,7 +83,10 @@ if [[ -z "${FORMAT}" ]]; then exit 1 fi -readarray -d '' matching_files < <(find . -path "./${FILES_PATTERN}" -print0 | sort -z) +matching_files=() +while IFS=$'' read -r matching_file ; do + matching_files+=("$matching_file") +done < <(find . -path "./${FILES_PATTERN}") if [[ "${#matching_files[@]}" -eq "0" ]]; then echo "No files found matching '${FILES_PATTERN}'" diff --git a/tests/pre-exit-success.bats b/tests/pre-exit-success.bats index 5999373..80052ba 100644 --- a/tests/pre-exit-success.bats +++ b/tests/pre-exit-success.bats @@ -41,8 +41,8 @@ setup() { stub git "rev-parse --short HEAD : echo 'some-commit-id'" stub curl \ - "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-1.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 1'" \ - "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-2.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 2'" + "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-2.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 2'" \ + "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-1.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 1'" run "$PWD/hooks/pre-exit" From a8d86558d19513fbbeddacbcc9d1f7cbb63c07bb Mon Sep 17 00:00:00 2001 From: "Ma. Paula Zeballos" Date: Thu, 9 Jun 2022 22:03:33 -0300 Subject: [PATCH 2/5] update plugin.yml with accepted config. options --- README.md | 4 ++-- plugin.yml | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 61d40da..b58b1b5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Test Collector Buildkite Plugin (WIP) +# Test Collector Buildkite Plugin A Buildkite plugin for uploading [JSON](https://buildkite.com/docs/test-analytics/importing-json) or [JUnit](https://buildkite.com/docs/test-analytics/importing-junit-xml) files to [Buildkite Test Analytics](https://buildkite.com/test-analytics) ✨ -## 👉 Usage +## Example ### Upload a JUnit file diff --git a/plugin.yml b/plugin.yml index 4fdcdbc..81ec022 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,23 +1,24 @@ -name: Test Collector Buildkite Plugin -description: ... +name: Test Collector +description: Uploads you JSON or JUnit files to Buildkite Test Analytics author: https://github.com/buildkite requirements: - docker + - curl configuration: properties: files: type: string - artifacts: - type: string format: enum: - json - junit api-token-env-name: type: string - oneOf: - - required: - - files - - required: - - artifacts + debug: + type: boolean + timeout: + type: integer + required: + - files + - format additionalProperties: false From fd1b6d6d0e73c3d1bb4e12ee08ce39e62acf1b76 Mon Sep 17 00:00:00 2001 From: "Ma. Paula Zeballos" Date: Thu, 9 Jun 2022 22:19:18 -0300 Subject: [PATCH 3/5] fix indentation on plugin.yml --- plugin.yml | 2 +- tests/pre-exit-success.bats | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin.yml b/plugin.yml index 81ec022..342c892 100644 --- a/plugin.yml +++ b/plugin.yml @@ -14,7 +14,7 @@ configuration: - junit api-token-env-name: type: string - debug: + debug: type: boolean timeout: type: integer diff --git a/tests/pre-exit-success.bats b/tests/pre-exit-success.bats index 80052ba..a9f27e6 100644 --- a/tests/pre-exit-success.bats +++ b/tests/pre-exit-success.bats @@ -50,10 +50,10 @@ setup() { unstub git assert_success - assert_output --partial "Uploading './tests/fixtures/junit-1.xml'..." assert_output --partial "Uploading './tests/fixtures/junit-2.xml'..." - assert_output --partial "curl success 1" + assert_output --partial "Uploading './tests/fixtures/junit-1.xml'..." assert_output --partial "curl success 2" + assert_output --partial "curl success 1" } @test "Debug true prints the curl info w/o token" { From ee89a73e8521d74d18b49c106868118deb7efb9a Mon Sep 17 00:00:00 2001 From: Pol Date: Thu, 9 Jun 2022 22:25:41 -0300 Subject: [PATCH 4/5] turn on debugging Enable curl debugging. Tests pass locally but not on BK :-/ --- tests/pre-exit-success.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pre-exit-success.bats b/tests/pre-exit-success.bats index a9f27e6..fdec14a 100644 --- a/tests/pre-exit-success.bats +++ b/tests/pre-exit-success.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats # To debug stubs, uncomment these lines: -# export CURL_STUB_DEBUG=/dev/tty +export CURL_STUB_DEBUG=/dev/tty # export GIT_STUB_DEBUG=/dev/tty setup() { From 8f08aa58f6893a94df77bcb1632c4e2b10075c1f Mon Sep 17 00:00:00 2001 From: Pol Date: Thu, 9 Jun 2022 22:33:50 -0300 Subject: [PATCH 5/5] Fix tests The order of the results from `find` is correct. Ideally, we should have a stub for the find to avoid the order difference in running the tests on different machines --- tests/pre-exit-success.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pre-exit-success.bats b/tests/pre-exit-success.bats index fdec14a..5999373 100644 --- a/tests/pre-exit-success.bats +++ b/tests/pre-exit-success.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats # To debug stubs, uncomment these lines: -export CURL_STUB_DEBUG=/dev/tty +# export CURL_STUB_DEBUG=/dev/tty # export GIT_STUB_DEBUG=/dev/tty setup() { @@ -41,8 +41,8 @@ setup() { stub git "rev-parse --short HEAD : echo 'some-commit-id'" stub curl \ - "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-2.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 2'" \ - "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-1.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 1'" + "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-1.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 1'" \ + "-X POST --silent --show-error --max-time 30 --form format=junit --form data=\"@./tests/fixtures/junit-2.xml\" --form run_env[CI]=buildkite --form run_env[key]=an-id --form run_env[url]=https://url.com/ --form run_env[branch]=a-branch --form run_env[commit_sha]=a-commit --form run_env[number]=123 --form run_env[job_id]=321 --form run_env[message]=\"A message\" --form run_env[collector]=test-collector-buildkite-plugin --form run_env[version]=some-commit-id https://analytics-api.buildkite.com/v1/uploads -H 'Authorization: Token token=\"a-secret-analytics-token\"' : echo 'curl success 2'" run "$PWD/hooks/pre-exit" @@ -50,10 +50,10 @@ setup() { unstub git assert_success - assert_output --partial "Uploading './tests/fixtures/junit-2.xml'..." assert_output --partial "Uploading './tests/fixtures/junit-1.xml'..." - assert_output --partial "curl success 2" + assert_output --partial "Uploading './tests/fixtures/junit-2.xml'..." assert_output --partial "curl success 1" + assert_output --partial "curl success 2" } @test "Debug true prints the curl info w/o token" {