Skip to content

Commit

Permalink
Merge pull request #39 from buildkite-plugins/toote_base_path
Browse files Browse the repository at this point in the history
Base path
  • Loading branch information
pzeballos authored Feb 20, 2023
2 parents fd4f463 + 3478933 commit f753eb1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -83,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"
```
Expand All @@ -97,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"
```
Expand All @@ -118,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"
```
Expand All @@ -132,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$"
Expand All @@ -145,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$"
Expand All @@ -158,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-"
Expand Down
3 changes: 2 additions & 1 deletion hooks/pre-exit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}'"
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ configuration:
type: string
api-url:
type: string
base-path:
type: string
branches:
type: string
debug:
Expand Down
27 changes: 27 additions & 0 deletions tests/pre-exit-success.bats
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,31 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
assert_output --partial "against https://test-api.example.com/v2"

unstub curl
}

@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"
}

@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"
}

0 comments on commit f753eb1

Please sign in to comment.