[🍒][ci] Fix the base branch we use to determine changes (#79503) (#79506)

We should diff against the base branch, not always against `main`. This
allows the BuildKite pre-commit CI to work properly when we target other
branches, such as `release/18.x`.

(cherry picked from commit 3b762891826192ded07286852d326f9c9060f52e)
This commit is contained in:
Louis Dionne 2024-01-25 16:57:41 -05:00 committed by GitHub
parent 6abd792a67
commit 3173faaff1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,19 +22,20 @@ set -o pipefail
# Environment variables script works with: # Environment variables script works with:
# Fetch origin/main to have an up to date merge base for main...HEAD diff. # Set by buildkite
git fetch origin main:main : ${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=}
: ${BUILDKITE_COMMIT:=}
: ${BUILDKITE_BRANCH:=}
# Fetch origin to have an up to date merge base for the diff.
git fetch origin
# List of files affected by this commit # List of files affected by this commit
: ${MODIFIED_FILES:=$(git diff --name-only main...HEAD)} : ${MODIFIED_FILES:=$(git diff --name-only origin/${BUILDKITE_PULL_REQUEST_BASE_BRANCH}...HEAD)}
# Filter rules for generic windows tests # Filter rules for generic windows tests
: ${WINDOWS_AGENTS:='{"queue": "windows"}'} : ${WINDOWS_AGENTS:='{"queue": "windows"}'}
# Filter rules for generic linux tests # Filter rules for generic linux tests
: ${LINUX_AGENTS:='{"queue": "linux"}'} : ${LINUX_AGENTS:='{"queue": "linux"}'}
# Service agents, for interacting with Phabricator. # Service agents, for interacting with Phabricator.
: ${SERVICE_AGENTS:='{"queue": "service"}'} : ${SERVICE_AGENTS:='{"queue": "service"}'}
# Set by buildkite
: ${BUILDKITE_COMMIT:=}
: ${BUILDKITE_BRANCH:=}
reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')"
if [[ "${reviewID}" != "" ]]; then if [[ "${reviewID}" != "" ]]; then