Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job label to message and amend annotation. #66

Merged
merged 3 commits into from Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions hooks/pre-exit
Expand Up @@ -58,7 +58,7 @@ annotation-link() {
REPORT_COUNT=$((REPORT_COUNT + 1))
done

echo -e "Check the test report(s) here: \n\n${REPORTS}" | buildkite-agent annotate --style info --context "test-collector"
echo -e "Check the ${BUILDKITE_LABEL} test report(s) here: \n\n${REPORTS}" | buildkite-agent annotate --style info --context "test-collector" --append
else
echo "There are no report URLs to annotate."
fi
Expand Down Expand Up @@ -162,7 +162,7 @@ find_and_upload() {
else
declare -a uploads_in_progress=()
echo "Uploading '${#matching_files[@]}' files matching '${FILES_PATTERN}'"

# needs to be part of else for bash4.3 compatibility
for file in "${matching_files[@]}"; do
iterations_waited=0
Expand Down Expand Up @@ -195,7 +195,7 @@ find_and_upload() {
else
response_file="$(mktemp -t 'response.XXXXXX')"
fi

if ! upload "$TOKEN_VALUE" "$FORMAT" "${file}" "${response_file}"; then
echo "Error uploading, will continue"
fi
Expand Down
23 changes: 12 additions & 11 deletions tests/pre-exit-report-link.bats
Expand Up @@ -18,6 +18,7 @@ setup() {
export BUILDKITE_BRANCH="a-branch"
export BUILDKITE_COMMIT="a-commit"
export BUILDKITE_BUILD_NUMBER="123"
export BUILDKITE_LABEL="A test step"
export BUILDKITE_JOB_ID="321"
export BUILDKITE_MESSAGE="A message"
export BUILDKITE_PLUGIN_TEST_COLLECTOR_ANNOTATION_LINK="true"
Expand All @@ -28,8 +29,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*

@test "Annotates report link with jq" {
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"

run "$PWD/hooks/pre-exit"

assert_success
Expand All @@ -44,9 +45,9 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*

@test "Annotates report link without jq" {
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"
stub which "jq : exit 1"

run "$PWD/hooks/pre-exit"

assert_success
Expand All @@ -67,8 +68,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
"-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success 1'" \
"-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success 2'" \
"-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success 3'"
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"


run "$PWD/hooks/pre-exit"

Expand Down Expand Up @@ -96,8 +97,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
"-r '.run_url' \* : echo https://buildkite.com/organizations/example/analytics/suites/collector-test/runs/1" \
"-r '.run_url' \* : echo https://buildkite.com/organizations/example/analytics/suites/collector-test/runs/2" \
"-r '.run_url' \* : echo https://buildkite.com/organizations/example/analytics/suites/collector-test/runs/1"
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success' with stdin:; cat"
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success' with stdin:; cat"


run "$PWD/hooks/pre-exit"

Expand All @@ -119,8 +120,8 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
@test "Annotates report link absorbs empty file error" {
export CURL_RESP_FILE="response.json"
stub curl "-X POST --silent --show-error --max-time 30 --form format=junit ${COMMON_CURL_OPTIONS} \* \* \* -H \* : echo 'curl success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" : echo 'annotation success'"
stub buildkite-agent "annotate --style info --context \"test-collector\" --append : echo 'annotation success'"

run "$PWD/hooks/pre-exit"

assert_success
Expand All @@ -134,7 +135,7 @@ COMMON_CURL_OPTIONS='--form \* --form \* --form \* --form \* --form \* --form \*
@test "No annotation when url property on json response is missing" {
export CURL_RESP_FILE="./tests/fixtures/response_no_url.json"
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"

assert_success
Expand Down