Skip to content

Commit

Permalink
Merge pull request #66 from jtszalay/annotation-fix
Browse files Browse the repository at this point in the history
Add job label to message and amend annotation.
  • Loading branch information
pzeballos committed Feb 5, 2024
2 parents 21268b2 + 956b720 commit b5323d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions hooks/pre-exit
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b5323d9

Please sign in to comment.