From 530e191f3bc445fb4222f7c264e7e68cb8218f73 Mon Sep 17 00:00:00 2001 From: James Szalay Date: Tue, 16 Jan 2024 11:20:21 -0500 Subject: [PATCH 1/3] Add job label to message and ammend annotation. --- hooks/pre-exit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/pre-exit b/hooks/pre-exit index 286ae0a..0bdd241 100755 --- a/hooks/pre-exit +++ b/hooks/pre-exit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail TOKEN_ENV_NAME="${BUILDKITE_PLUGIN_TEST_COLLECTOR_API_TOKEN_ENV_NAME:-BUILDKITE_ANALYTICS_TOKEN}" @@ -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 From cba59cca7700e55f0474aa091a5c7fddf892187b Mon Sep 17 00:00:00 2001 From: James Szalay Date: Sat, 3 Feb 2024 21:44:09 -0500 Subject: [PATCH 2/3] Fix tests for change --- tests/pre-exit-report-link.bats | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/pre-exit-report-link.bats b/tests/pre-exit-report-link.bats index 3a74516..3228e1f 100644 --- a/tests/pre-exit-report-link.bats +++ b/tests/pre-exit-report-link.bats @@ -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" @@ -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 @@ -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 @@ -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" @@ -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" @@ -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 @@ -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 From 956b720a39806b0689251931bdddbadd5b3547b9 Mon Sep 17 00:00:00 2001 From: James Szalay Date: Mon, 5 Feb 2024 09:34:42 -0500 Subject: [PATCH 3/3] shebang revert --- hooks/pre-exit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hooks/pre-exit b/hooks/pre-exit index 0bdd241..7d73799 100755 --- a/hooks/pre-exit +++ b/hooks/pre-exit @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash set -euo pipefail TOKEN_ENV_NAME="${BUILDKITE_PLUGIN_TEST_COLLECTOR_API_TOKEN_ENV_NAME:-BUILDKITE_ANALYTICS_TOKEN}" @@ -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 @@ -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