From 46c375f4604559e68f85b8576499c5f7c1dae9af Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Mon, 6 Mar 2023 17:28:13 -0800 Subject: [PATCH] buildkite: don't run tests on deleted branches Copybara updates a target branch before merging it to the master and then it deletes it. The problem is that it triggers buildkite twice on the same commit: on the master branch and on the target branch. PiperOrigin-RevId: 514573062 --- .buildkite/hooks/pre-command | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index c79bc3a25..0a9ee356b 100644 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -1,5 +1,11 @@ set -euo pipefail +# Check that the target branch exists. +git fetch origin "${BUILDKITE_BRANCH}" || { + echo "Branch ${BUILDKITE_BRANCH} no longer exists; it was probably deleted by the time we got to it." >&2 + exit 1 +} + # Download any build-specific configuration that has been uploaded. # This allows top-level steps to override all subsequent steps. buildkite-agent artifact download 'tools/bazeldefs/*' . || true