Skip to content

[CI] detect package changes on first push of long-running branches#19045

Merged
mrodm merged 4 commits into
elastic:mainfrom
mrodm:fix_first_push_long_running_branches
May 21, 2026
Merged

[CI] detect package changes on first push of long-running branches#19045
mrodm merged 4 commits into
elastic:mainfrom
mrodm:fix_first_push_long_running_branches

Conversation

@mrodm
Copy link
Copy Markdown
Collaborator

@mrodm mrodm commented May 18, 2026

Summary

On the first push of a new backport-* or feature/* branch with no prior
successful build, get_from_changeset() was unconditionally returning an empty
diff range, causing package tests to be silently skipped even when the pushed
commit contained real packages/ changes. Fixed by computing the merge-base
with origin/main and checking whether commits exclusive to the branch touch
packages/ before deciding whether to run package tests.

Proposed commit message

On the first push of a new `backport-*` or `feature/*` branch with no previous
successful build, `get_from_changeset()` set `from="${BUILDKITE_COMMIT}"`, making
`from==to` and producing an empty diff. This caused package tests to be silently
skipped even when the pushed commit contained real package changes (e.g. when
the backport pipeline had no CI infra changes to commit and pushed the branch
directly at `BASE_COMMIT`, the package version bump commit).

Fix by computing` git merge-base "${BUILDKITE_COMMIT}" "origin/main"` to find the
divergence point from main, then checking whether commits exclusive to the branch
contain packages/ changes:
- If yes: use the merge-base as `from` so the affected packages are tested.
- If no (CI infra-only first commit): keep `from="${BUILDKITE_COMMIT}"`, producing
  an empty diff and skipping package testing as intended.

Also refactor `get_from_changeset()` to use early returns, removing three levels
of nested if/else and a dead get_previous_commit call unreachable for `main` and
long-running branches.

Update `docs/ci_pipelines.md` to document the first-push behaviour for `backport-*`,
`feature/*`, and `main` branches.

WHAT

get_from_changeset() in .buildkite/scripts/common.sh previously set
from="${BUILDKITE_COMMIT}" for all backport-* and feature/* branches
when no previous successful build existed (first push). Since
get_to_changeset() also resolves to BUILDKITE_COMMIT for these branches,
this produced an empty diff range and caused package tests to be silently
skipped — even when the pushed commit contained real package changes.

This happened in a specific scenario: when the backport pipeline created the
branch at BASE_COMMIT but had no CI infrastructure changes to commit, the
branch was pushed pointing directly at BASE_COMMIT (the package version
bump), which does contain packages/ changes.

The fix computes git merge-base "${BUILDKITE_COMMIT}" "origin/main" to find
the divergence point from main, then checks whether commits exclusive to the
branch contain packages/ changes:

  • If yes → use the merge-base as from, so the affected packages are tested.
  • If no (CI infra-only first commit) → keep from="${BUILDKITE_COMMIT}", producing an empty diff and skipping package testing as intended.

The function is also refactored to use early returns, eliminating three levels
of nested if/else and removing a dead get_previous_commit call that was
unreachable for main and long-running branches.

docs/ci_pipelines.md is updated to document the first-push behaviour for
backport-*, feature/*, and main branches.

WHY

On the first push of a new backport-* branch, package regressions could
merge without package validation because CI annotated "No packages to be
tested" and skipped integration tests entirely. The same gap existed for
feature/* branches.

Author's Checklist

  • grep -q replaced with grep -E ... > /dev/null consistent with the SIGPIPE warning documented throughout common.sh.

Related issues


This PR was generated with the assistance of Claude (claude-sonnet-4-6).

mrodm and others added 3 commits May 18, 2026 11:46
On the first push of a new backport or feature branch with no previous
successful build, get_from_changeset() was unconditionally setting
from=BUILDKITE_COMMIT, making from==to and producing an empty diff.
This caused package tests to be silently skipped even when the pushed
commit contained package changes (e.g. when the backport script had
nothing to commit for CI infra and pushed the branch directly at
BASE_COMMIT).

Fix by computing the merge-base with origin/main and checking whether
the commits exclusive to the branch touch packages/. If they do, use
the merge-base as the changeset start; otherwise keep the empty-diff
behaviour for CI infra-only first commits.

Co-authored-by: Claude <noreply@anthropic.com>
Replace nested if/else accumulation pattern with early returns per
branch case. Also removes the dead get_previous_commit call that was
unreachable for main and long-running branches.

Co-authored-by: Claude <noreply@anthropic.com>
…nches

Add a "First push" sub-section under the branch context description to
explain the merge-base approach used when no previous successful build
exists for backport-* and feature/* branches. Also update the feature
branches section to describe the content-aware check (package changes
are tested; CI infra-only pushes skip package testing).

Co-authored-by: Claude <noreply@anthropic.com>
@mrodm mrodm self-assigned this May 18, 2026
Comment on lines +662 to +664
merge_base=$(git merge-base "${BUILDKITE_COMMIT}" "origin/main")
if git diff --name-only "${merge_base}" "${BUILDKITE_COMMIT}" | grep -E '^packages/' > /dev/null; then
echo "${merge_base}"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will help to test packages in feature branches in the first commit if there is any.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

✅ Vale Linting Results

No issues found on modified lines!


The Vale linter checks documentation changes against the Elastic Docs style guide.

To use Vale locally or report issues, refer to Elastic style guide for Vale.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

🔍 Preview links for changed docs

@mrodm mrodm marked this pull request as ready for review May 18, 2026 11:18
@mrodm mrodm requested a review from a team as a code owner May 18, 2026 11:18
@andrewkroh andrewkroh added the documentation Improvements or additions to documentation. Applied to PRs that modify *.md files. label May 18, 2026
@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@mrodm mrodm merged commit d31bdfa into elastic:main May 21, 2026
8 of 9 checks passed
@mrodm mrodm deleted the fix_first_push_long_running_branches branch May 21, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation. Applied to PRs that modify *.md files.

Projects

None yet

4 participants