From db60c405732cfd0989e0ab9845395b73a71fcd10 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 5 Nov 2024 15:50:54 +0100 Subject: [PATCH 1/7] buildkite: skip clone for GitHub check notifications --- .buildkite/build_pr_pipeline.yml | 29 ++++++++++++++--- .buildkite/scripts/build_pr_commit_status.sh | 33 -------------------- 2 files changed, 25 insertions(+), 37 deletions(-) delete mode 100755 .buildkite/scripts/build_pr_commit_status.sh diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index bcca81c0c65e8..7de45a610c291 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -6,7 +6,18 @@ steps: command: ".buildkite/scripts/cancel_running_pr.sh || true" - key: "build-pr-setup" label: "setup" - command: ".buildkite/scripts/build_pr_commit_status.sh pending" + command: | + githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" + data='{"state":"'pending'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'Build started'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' + curl -s -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${githubPublishStatus}" \ + -d "${data}" + plugins: + - 'uber-workflow/run-without-clone': - key: "build-pr" label: ":hammer: Build docs PR" command: ".buildkite/scripts/build_pr.sh" @@ -21,11 +32,21 @@ steps: - key: "teardown" label: "teardown" command: | + status_state=failure if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then - .buildkite/scripts/build_pr_commit_status.sh success - else - .buildkite/scripts/build_pr_commit_status.sh failure + status_state=success fi + githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" + data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'Build finished'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' + curl -s -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${githubPublishStatus}" \ + -d "${data}" depends_on: - step: "build-pr" allow_failure: true + plugins: + - 'uber-workflow/run-without-clone': diff --git a/.buildkite/scripts/build_pr_commit_status.sh b/.buildkite/scripts/build_pr_commit_status.sh deleted file mode 100755 index 3bc5d422dd551..0000000000000 --- a/.buildkite/scripts/build_pr_commit_status.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# This hook should only be invoked for builds triggered by the Buildkite PR bot -if [ -z ${GITHUB_PR_BASE_OWNER+set} ] || [ -z ${GITHUB_PR_BASE_REPO+set} ] || [ -z ${GITHUB_PR_TRIGGERED_SHA+set} ];then - exit 0 -fi - -status_state=$1 -description='' - -case $status_state in - pending) - description='Build started';; - success|failure|error) - description='Build finished';; - *) - echo "Invalid state $status_state" - exit 1;; -esac - -githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" -data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'$description'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' - -echo "Setting commit status: buildkite/${BUILDKITE_PIPELINE_SLUG} - ${status_state}" -curl -s -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "${githubPublishStatus}" \ - -d "${data}" From 6f155c63cbe1445ae7bfff8350286b2cb27b780b Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Nov 2024 09:25:24 +0100 Subject: [PATCH 2/7] fix --- .buildkite/build_pr_pipeline.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index 7de45a610c291..13fdac1d1b97f 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -7,15 +7,13 @@ steps: - key: "build-pr-setup" label: "setup" command: | - githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" - data='{"state":"'pending'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'Build started'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' curl -s -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "${githubPublishStatus}" \ - -d "${data}" + "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ + -d '{"state":"'pending'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'Build started'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' plugins: - 'uber-workflow/run-without-clone': - key: "build-pr" @@ -36,15 +34,13 @@ steps: if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then status_state=success fi - githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" - data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'Build finished'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' curl -s -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "${githubPublishStatus}" \ - -d "${data}" + "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ + -d '{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' depends_on: - step: "build-pr" allow_failure: true From b9ca7fa74722b5a37e87be8e13b698e49fa93b11 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Nov 2024 09:31:04 +0100 Subject: [PATCH 3/7] fix --- .buildkite/build_pr_pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index 13fdac1d1b97f..3cd87c85dd8e4 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -13,7 +13,7 @@ steps: -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ - -d '{"state":"'pending'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'Build started'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' + -d '{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' plugins: - 'uber-workflow/run-without-clone': - key: "build-pr" From 9c29cb4978e6e1f04efa5eb374803b446686a655 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Nov 2024 11:01:31 +0100 Subject: [PATCH 4/7] use dollar to support bash commands or env variables at runtime --- .buildkite/build_pr_pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index 3cd87c85dd8e4..31a9f113cad1d 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -31,7 +31,7 @@ steps: label: "teardown" command: | status_state=failure - if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then + if [ $$(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then status_state=success fi curl -s -L \ @@ -40,7 +40,7 @@ steps: -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ - -d '{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' + -d '{"state":"'$$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' depends_on: - step: "build-pr" allow_failure: true From e43526e3687d1963ea012a7c3ff7cb98599ec636 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Nov 2024 16:28:24 +0100 Subject: [PATCH 5/7] try something else --- .buildkite/build_pr_pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index 31a9f113cad1d..1af3ef50d85a6 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -34,6 +34,7 @@ steps: if [ $$(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then status_state=success fi + export status_state curl -s -L \ -X POST \ -H "Accept: application/vnd.github+json" \ From 4a7b43b1a8587979337811938d97607bcb64071f Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Nov 2024 19:01:29 +0100 Subject: [PATCH 6/7] test --- .buildkite/build_pr_pipeline.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index 1af3ef50d85a6..2ddf2b80241ac 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -10,12 +10,34 @@ steps: curl -s -L \ -X POST \ -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ + -H "Authorization: Bearer $${VAULT_GITHUB_TOKEN}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ -d '{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' plugins: - 'uber-workflow/run-without-clone': + + - key: "test" + label: "test" + command: | + status_state=failure + if [ $$(buildkite-agent step get "outcome" --step "build-pr-setup") == "passed" ]; then + status_state=success + fi + export status_state + curl -s -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $${VAULT_GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ + -d '{"state":"'$$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' + depends_on: + - step: "build-pr-setup" + allow_failure: true + plugins: + - 'uber-workflow/run-without-clone': + - key: "build-pr" label: ":hammer: Build docs PR" command: ".buildkite/scripts/build_pr.sh" @@ -38,7 +60,7 @@ steps: curl -s -L \ -X POST \ -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${VAULT_GITHUB_TOKEN}" \ + -H "Authorization: Bearer $${VAULT_GITHUB_TOKEN}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ -d '{"state":"'$$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' From 6ff59a2df47075014a095dbcee2cbc64ba1c316e Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 7 Nov 2024 19:07:54 +0100 Subject: [PATCH 7/7] remove test --- .buildkite/build_pr_pipeline.yml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/.buildkite/build_pr_pipeline.yml b/.buildkite/build_pr_pipeline.yml index 2ddf2b80241ac..3df10f379e55e 100644 --- a/.buildkite/build_pr_pipeline.yml +++ b/.buildkite/build_pr_pipeline.yml @@ -16,28 +16,6 @@ steps: -d '{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' plugins: - 'uber-workflow/run-without-clone': - - - key: "test" - label: "test" - command: | - status_state=failure - if [ $$(buildkite-agent step get "outcome" --step "build-pr-setup") == "passed" ]; then - status_state=success - fi - export status_state - curl -s -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $${VAULT_GITHUB_TOKEN}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}" \ - -d '{"state":"'$$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}' - depends_on: - - step: "build-pr-setup" - allow_failure: true - plugins: - - 'uber-workflow/run-without-clone': - - key: "build-pr" label: ":hammer: Build docs PR" command: ".buildkite/scripts/build_pr.sh"