From fa35500f9b4b374a2a6f7f1835ac7bd67695de8a Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 14 Mar 2022 14:33:49 -0300 Subject: [PATCH 1/2] Add dummy GITHUB_REPOSITORY value to local test results upload I missed this in 6a55aee. --- Scripts/local_dev_upload_test_results.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Scripts/local_dev_upload_test_results.sh b/Scripts/local_dev_upload_test_results.sh index 74a27e5a7..8e77405bf 100755 --- a/Scripts/local_dev_upload_test_results.sh +++ b/Scripts/local_dev_upload_test_results.sh @@ -14,5 +14,6 @@ export GITHUB_RUN_ATTEMPT="1" export GITHUB_BASE_REF="main" export GITHUB_HEAD_REF="my-branch" export GITHUB_JOB="fake-job" +export GITHUB_REPOSITORY="ably/ably-cocoa" ./Scripts/upload_test_results.sh --upload-server-base-url "http://localhost:3000" From cb078a28ab9a32ea794aff335fa36d5731c2ea77 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 14 Mar 2022 14:34:42 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Don=E2=80=99t=20require=20GITHUB=5F[BASE|HE?= =?UTF-8?q?AD]=5FREF=20to=20be=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are only set by GitHub when the CI pipeline is triggered by a pull request. They aren’t set when running a regular CI pipeline on `main`. --- Scripts/upload_test_results.sh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Scripts/upload_test_results.sh b/Scripts/upload_test_results.sh index 10a9b4342..30a287cdb 100755 --- a/Scripts/upload_test_results.sh +++ b/Scripts/upload_test_results.sh @@ -73,18 +73,6 @@ then exit 1 fi -if [[ -z $GITHUB_BASE_REF ]] -then - echo "The GITHUB_BASE_REF environment variable must be set." 2>&1 - exit 1 -fi - -if [[ -z $GITHUB_HEAD_REF ]] -then - echo "The GITHUB_HEAD_REF environment variable must be set." 2>&1 - exit 1 -fi - if [[ -z $GITHUB_JOB ]] then echo "The GITHUB_JOB environment variable must be set." 2>&1 @@ -136,6 +124,23 @@ echo "Test report found: ${test_reports}" 2>&1 temp_request_body_file=$(mktemp) +# https://unix.stackexchange.com/questions/446847/conditionally-pass-params-to-a-script +optional_params=() + +if [[ ! -z $GITHUB_BASE_REF ]] +then + optional_params+=(--arg github_base_ref "${GITHUB_BASE_REF}") +else + optional_params+=(--argjson github_base_ref null) +fi + +if [[ ! -z $GITHUB_HEAD_REF ]] +then + optional_params+=(--arg github_head_ref "${GITHUB_HEAD_REF}") +else + optional_params+=(--argjson github_head_ref null) +fi + jq -n \ --rawfile junit_report_xml "${test_reports}" \ --arg github_repository "${GITHUB_REPOSITORY}" \ @@ -146,10 +151,9 @@ jq -n \ --arg github_run_number "${GITHUB_RUN_NUMBER}" \ --arg github_run_attempt "${GITHUB_RUN_ATTEMPT}" \ --arg github_run_id "${GITHUB_RUN_ID}" \ - --arg github_base_ref "${GITHUB_BASE_REF}" \ - --arg github_head_ref "${GITHUB_HEAD_REF}" \ --arg github_job "${GITHUB_JOB}" \ --arg iteration "${iteration}" \ + "${optional_params[@]}" \ '{ junit_report_xml: $junit_report_xml | @base64, github_repository: $github_repository, github_sha: $github_sha, github_ref_name: $github_ref_name, github_retention_days: $github_retention_days, github_action: $github_action, github_run_number: $github_run_number, github_run_attempt: $github_run_attempt, github_run_id: $github_run_id, github_base_ref: $github_base_ref, github_head_ref: $github_head_ref, github_job: $github_job, iteration: $iteration }' \ > "${temp_request_body_file}"