Skip to content

chore(ci_visibility): use merge-base for github actions PR base commit sha#17657

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
mainfrom
gnufede/SDTEST-2356-base-branch-sha-gha
Apr 22, 2026
Merged

chore(ci_visibility): use merge-base for github actions PR base commit sha#17657
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
mainfrom
gnufede/SDTEST-2356-base-branch-sha-gha

Conversation

@gnufede

@gnufede gnufede commented Apr 21, 2026

Copy link
Copy Markdown
Member

Description

On GitHub Actions, pull_request.base.sha in the event payload points to the HEAD of the base branch, not to the common ancestor (merge base) commit. This PR fixes two related issues:

  1. Tag rename: pull_request.base.sha is now stored as git.pull_request.base_branch_head_sha (was incorrectly absent; the value is semantically the base branch head, not the base commit SHA).
  2. Merge base computation: git.pull_request.base_branch_sha (the true diff base) is now computed via git merge-base <base.sha> <head.sha> when it hasn't already been provided by the CI system (e.g. GitLab provides it directly via CI_MERGE_REQUEST_DIFF_BASE_SHA).

Reference implementation (Go): DataDog/dd-trace-go#3816

Changes

  • ddtrace/ext/ci/github_actions.py: read pull_request.base.sha from event file → set as git.PULL_REQUEST_BASE_BRANCH_HEAD_SHA
  • ddtrace/testing/internal/git.py: add Git.get_merge_base() method and get_pr_base_commit_sha() module-level helper
  • ddtrace/testing/internal/env_tags.py: after assembling tags, compute PULL_REQUEST_BASE_BRANCH_SHA via merge-base when not already set

Test plan

  • test_github_actions_base_branch_head_sha_extracted_from_event — verifies pull_request.base.shabase_branch_head_sha
  • test_github_actions_base_branch_sha_computed_as_merge_base — verifies merge-base is called with correct SHAs
  • test_github_actions_base_branch_sha_not_overwritten_when_already_set — verifies pre-existing value (e.g. from DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA) is respected

🤖 Generated with Claude Code

On GitHub Actions, pull_request.base.sha points to the HEAD of the base
branch rather than the common ancestor commit. Store it as
git.pull_request.base_branch_head_sha and compute the true base commit
SHA via `git merge-base` for use as git.pull_request.base_branch_sha.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@gnufede
gnufede requested a review from a team as a code owner April 21, 2026 14:34
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

ddtrace/ext/ci/github_actions.py                                        @DataDog/ci-app-libraries
ddtrace/testing/internal/env_tags.py                                    @DataDog/ci-app-libraries
ddtrace/testing/internal/git.py                                         @DataDog/ci-app-libraries
tests/testing/internal/test_env_tags.py                                 @DataDog/ci-app-libraries

@gnufede gnufede changed the title fix(ci_visibility): use merge-base for GitHub Actions PR base commit SHA fix(ci_visibility): use merge-base for github actions PR base commit sha Apr 21, 2026
@gnufede gnufede changed the title fix(ci_visibility): use merge-base for github actions PR base commit sha chore(ci_visibility): use merge-base for github actions PR base commit sha Apr 21, 2026
@gnufede gnufede added changelog/no-changelog A changelog entry is not required for this PR. CI App labels Apr 21, 2026
@gnufede

gnufede commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

E2E Test Report: SUCCESS ✅

Tested by: Shepherd Agent (autonomous QA for Datadog Test Optimization)

Test Environment

  • Method: Local testing with flask playground (Python/pytest) — including simulated GitHub Actions environment
  • Revision: a75ff3b8b05c3b2ce29009362dbc0ba8e90c6816 (branch: gnufede/SDTEST-2356-base-branch-sha-gha)

Results

Check Status
No regressions (496 passed, 3 pre-existing failures)
ci.provider.name detected as github under GHA env
git merge-base called with correct SHAs from event payload
git.pull_request.base_branch_head_sha set from pull_request.base.sha in event file
git.pull_request.base_branch_sha computed via merge-base
git.pull_request.base_branch set to main
git.branch set to feature-branch (from GITHUB_HEAD_REF)

Test Methodology

Test 1 — Regression check (local, no GHA env)

Ran the flask playground normally to confirm no regressions: 499 tests, 25 suites, same 3 pre-existing failures as baseline.

Test 2 — Simulated GitHub Actions environment

Re-ran with the following injected env vars to simulate a pull_request event:

GITHUB_ACTIONS=true
GITHUB_EVENT_NAME=pull_request
GITHUB_EVENT_PATH=/tmp/gha_event.json   # contains pull_request.base.sha + head.sha
GITHUB_SHA=c34d6e81...  (HEAD of flask repo)
GITHUB_HEAD_REF=feature-branch
GITHUB_BASE_REF=main

Verified in the raw citestcycle payload:

  • git merge-base a411a2434b09d9cbaa4074232b2c247d591bb655 c34d6e81fd8e405e6d4178bf24b364918811ef17 was invoked
  • Both tags appeared correctly in the metadata["*"] section sent to the backend:
"git.pull_request.base_branch_head_sha": "a411a2434b09d9cbaa4074232b2c247d591bb655",
"git.pull_request.base_branch_sha":      "a411a2434b09d9cbaa4074232b2c247d591bb655",
"git.pull_request.base_branch":          "main",
"git.branch":                            "feature-branch"

Note: in this linear-history test repo the merge-base equals the base branch head — the important thing is that git merge-base was called and its result was used, as confirmed in the debug logs.


This E2E test was performed by Shepherd — autonomous QA agent for Datadog Test Optimization

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 851b72c into main Apr 22, 2026
423 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the gnufede/SDTEST-2356-base-branch-sha-gha branch April 22, 2026 09:29
brettlangdon pushed a commit that referenced this pull request Apr 23, 2026
…t sha (#17657)

## Description

On GitHub Actions, `pull_request.base.sha` in the event payload points to the **HEAD of the base branch**, not to the common ancestor (merge base) commit. This PR fixes two related issues:

1. **Tag rename**: `pull_request.base.sha` is now stored as `git.pull_request.base_branch_head_sha` (was incorrectly absent; the value is semantically the base branch head, not the base commit SHA).
2. **Merge base computation**: `git.pull_request.base_branch_sha` (the true diff base) is now computed via `git merge-base <base.sha> <head.sha>` when it hasn't already been provided by the CI system (e.g. GitLab provides it directly via `CI_MERGE_REQUEST_DIFF_BASE_SHA`).

Reference implementation (Go): DataDog/dd-trace-go#3816

## Changes

- `ddtrace/ext/ci/github_actions.py`: read `pull_request.base.sha` from event file → set as `git.PULL_REQUEST_BASE_BRANCH_HEAD_SHA`
- `ddtrace/testing/internal/git.py`: add `Git.get_merge_base()` method and `get_pr_base_commit_sha()` module-level helper
- `ddtrace/testing/internal/env_tags.py`: after assembling tags, compute `PULL_REQUEST_BASE_BRANCH_SHA` via merge-base when not already set

## Test plan

- [x] `test_github_actions_base_branch_head_sha_extracted_from_event` — verifies `pull_request.base.sha` → `base_branch_head_sha`
- [x] `test_github_actions_base_branch_sha_computed_as_merge_base` — verifies merge-base is called with correct SHAs
- [x] `test_github_actions_base_branch_sha_not_overwritten_when_already_set` — verifies pre-existing value (e.g. from `DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA`) is respected

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: federico.mon <[email protected]>
emmettbutler pushed a commit that referenced this pull request May 6, 2026
…t sha (#17657)

## Description

On GitHub Actions, `pull_request.base.sha` in the event payload points to the **HEAD of the base branch**, not to the common ancestor (merge base) commit. This PR fixes two related issues:

1. **Tag rename**: `pull_request.base.sha` is now stored as `git.pull_request.base_branch_head_sha` (was incorrectly absent; the value is semantically the base branch head, not the base commit SHA).
2. **Merge base computation**: `git.pull_request.base_branch_sha` (the true diff base) is now computed via `git merge-base <base.sha> <head.sha>` when it hasn't already been provided by the CI system (e.g. GitLab provides it directly via `CI_MERGE_REQUEST_DIFF_BASE_SHA`).

Reference implementation (Go): DataDog/dd-trace-go#3816

## Changes

- `ddtrace/ext/ci/github_actions.py`: read `pull_request.base.sha` from event file → set as `git.PULL_REQUEST_BASE_BRANCH_HEAD_SHA`
- `ddtrace/testing/internal/git.py`: add `Git.get_merge_base()` method and `get_pr_base_commit_sha()` module-level helper
- `ddtrace/testing/internal/env_tags.py`: after assembling tags, compute `PULL_REQUEST_BASE_BRANCH_SHA` via merge-base when not already set

## Test plan

- [x] `test_github_actions_base_branch_head_sha_extracted_from_event` — verifies `pull_request.base.sha` → `base_branch_head_sha`
- [x] `test_github_actions_base_branch_sha_computed_as_merge_base` — verifies merge-base is called with correct SHAs
- [x] `test_github_actions_base_branch_sha_not_overwritten_when_already_set` — verifies pre-existing value (e.g. from `DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA`) is respected

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: federico.mon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR. CI App

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants