diff --git a/.buildkite/hooks/post-checkout b/.buildkite/hooks/post-checkout deleted file mode 100755 index 15126bcfadf..00000000000 --- a/.buildkite/hooks/post-checkout +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash -## -## This script prepares the git context so it works with GitHub Pull Requests. -## -## Originally implemented in https://github.com/elastic/elastic-agent/blob/main/.buildkite/hooks/post-checkout -## - -set -euo pipefail - -checkout_merge() { - local target_branch=$1 - local pr_commit=$2 - local merge_branch=$3 - - if [[ -z "${target_branch}" ]]; then - echo "No pull request target branch" - exit 1 - fi - - git fetch -v origin "${target_branch}" - git checkout FETCH_HEAD - echo "Current branch: $(git rev-parse --abbrev-ref HEAD)" - - # create temporal branch to merge the PR with the target branch - git checkout -b ${merge_branch} - echo "New branch created: $(git rev-parse --abbrev-ref HEAD)" - - # set author identity so it can be run git merge - git config user.name "github-merged-pr-post-checkout" - git config user.email "auto-merge@buildkite" - - git merge --no-edit "${BUILDKITE_COMMIT}" || { - local merge_result=$? - echo "Merge failed: ${merge_result}" - git merge --abort - exit ${merge_result} - } -} - -pull_request="${BUILDKITE_PULL_REQUEST:-false}" - -if [[ "${pull_request}" == "false" ]]; then - echo "Not a pull request, skipping" - exit 0 -fi - -TARGET_BRANCH="${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-main}" -PR_COMMIT="${BUILDKITE_COMMIT}" -PR_ID=${BUILDKITE_PULL_REQUEST} -MERGE_BRANCH="pr_merge_${PR_ID}" - -checkout_merge "${TARGET_BRANCH}" "${PR_COMMIT}" "${MERGE_BRANCH}" - -echo "--- Commit information" -git log --format=%B -n 1 - -# Ensure buildkite groups are rendered -echo "" diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index 4a3265a7096..4cea2b24af3 100755 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -10,6 +10,12 @@ set -eo pipefail +# Upload should not do much with the pre-command. +if [[ "$BUILDKITE_COMMAND" =~ .*"upload".* ]]; then + echo "Skipped pre-command when running the Upload pipeline" + exit 0 +fi + # shellcheck disable=SC1091 source .buildkite/scripts/utils.sh diff --git a/.buildkite/package.yml b/.buildkite/package.yml index 8acce8119e1..3bb01af1b48 100644 --- a/.buildkite/package.yml +++ b/.buildkite/package.yml @@ -1,8 +1,8 @@ notify: - slack: "#apm-server" - if: build.state == "failed" + if: build.state == "failed" && build.branch =~ /^(main|\d+\.\d+|\d+\.x)$$/ - slack: "#observablt-bots" - if: "build.state != 'passed'" + if: build.state == "failed" && build.branch =~ /^(main|\d+\.\d+|\d+\.x)$$/ env: IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2404" diff --git a/.buildkite/scripts/utils.sh b/.buildkite/scripts/utils.sh index 762495f2ae8..8cb279d26c1 100644 --- a/.buildkite/scripts/utils.sh +++ b/.buildkite/scripts/utils.sh @@ -32,7 +32,8 @@ retry() { # # An opinionated approach to detect if unsupported Unified Release branches -# can be used, this is handy for testing feature branches in dry-run mode +# can be used, this is handy for testing feature branches in dry-run mode. +# In addition support for PRs is added by using the base branch of the PR. # It produces the below environment variables: # - VERSION # - DRA_COMMAND @@ -58,6 +59,9 @@ dra_process_other_branches() { buildkite-agent annotate "It was not possible to know the original base branch for ${BUILDKITE_BRANCH}. This won't fail - this is a feature branch." --style 'info' --context 'ctx-info-feature-branch' fi fi + elif [[ -n "$BUILDKITE_PULL_REQUEST_BASE_BRANCH" ]]; then + DRA_BRANCH="$BUILDKITE_PULL_REQUEST_BASE_BRANCH" + DRA_COMMAND=list fi export DRA_BRANCH DRA_COMMAND VERSION }