You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a PR workflow that detects which files have changed between a feature branch and its base branch, then generates a rollout artifact containing those changes.
Expected Behavior
When detecting changes for a PR, we want to capture all files that differ between the feature branch's current state and the base branch.
If the same feature branch is reused for multiple PRs (merged once, then continued with new commits), subsequent PRs should include all cumulative changes from that feature branch across all its work—not just the delta since the last merge.
Problem Scenario
gitGraph
commit id: "Base commit"
branch "Feature A"
commit id: "A1"
commit id: "A2"
checkout main
branch "Feature B"
commit id: "B1"
commit id: "B2"
checkout main
merge "Feature A"
commit id: "Base after merge A"
checkout "Feature B"
merge main
commit id: "B3"
checkout main
commit id: "Latest base"
Loading
The change detection fails in this flow:
Feature Branch A and Feature Branch B both start from the same base.
Feature Branch A is merged into the base.
The base is then merged down into Feature Branch B (to bring in updates from other work).
Feature Branch B now physically contains both its own changes and Feature Branch A's changes (via the merge-down).
When we run the PR workflow for Feature Branch B at this point, the change detection incorrectly includes files from Feature Branch A.
This happens even though Feature Branch B's actual work only modified its own set of files. The changes from Feature Branch A should not appear in Feature Branch B's rollout.
Why This Is a Problem
From Feature Branch B's perspective, it should only concern itself with changes it directly introduced, not with changes that arrived from other branches through a merge-down of the base.
If we cannot distinguish between "my branch's own changes" and "changes that came in through a merge-down from another branch," the rollout will contain unintended files.
The code I use
- name: Calculate fork point for accurate change detection
id: fork_point
run: |
echo "::group::🔍 Calculating change detection base"
BASE_REF=${{ github.event.pull_request.base.ref }}
HEAD_REF=${{ github.event.pull_request.head.sha }}
echo "Base branch: $BASE_REF"
echo "PR HEAD: $HEAD_REF"
# For rollout generation, we want ALL cumulative changes made on the feature branch
# since the base branch originally diverged from master.
# This captures all changes regardless of intermediate merges between base and feature.
# Find where the base branch diverged from master
BASE_FORK_POINT=$(git merge-base origin/${BASE_REF} origin/master)
echo "Base branch fork point from master: $BASE_FORK_POINT"
git log --oneline -1 $BASE_FORK_POINT
echo "::notice::Using base branch fork point $BASE_FORK_POINT for cumulative change detection"
# Show total commits in this PR since base fork point
COMMIT_COUNT=$(git rev-list --count ${BASE_FORK_POINT}..${HEAD_REF})
echo "::notice::This PR includes $COMMIT_COUNT total commits since base branch diverged from master"
# Export for use in changed-files action
echo "sha=$BASE_FORK_POINT" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Get changed files since original fork point
id: changed-files
uses: tj-actions/changed-files@v46
with:
base_sha: ${{ steps.fork_point.outputs.sha }}
sha: ${{ github.event.pull_request.head.sha }}
separator: ":::"
files: |
!.github/**
!diff_files.txt
!removed_files.txt
!event.json
!.gitignore
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
We have a PR workflow that detects which files have changed between a feature branch and its base branch, then generates a rollout artifact containing those changes.
Expected Behavior
When detecting changes for a PR, we want to capture all files that differ between the feature branch's current state and the base branch.
If the same feature branch is reused for multiple PRs (merged once, then continued with new commits), subsequent PRs should include all cumulative changes from that feature branch across all its work—not just the delta since the last merge.
Problem Scenario
gitGraph commit id: "Base commit" branch "Feature A" commit id: "A1" commit id: "A2" checkout main branch "Feature B" commit id: "B1" commit id: "B2" checkout main merge "Feature A" commit id: "Base after merge A" checkout "Feature B" merge main commit id: "B3" checkout main commit id: "Latest base"The change detection fails in this flow:
When we run the PR workflow for Feature Branch B at this point, the change detection incorrectly includes files from Feature Branch A.
This happens even though Feature Branch B's actual work only modified its own set of files. The changes from Feature Branch A should not appear in Feature Branch B's rollout.
Why This Is a Problem
From Feature Branch B's perspective, it should only concern itself with changes it directly introduced, not with changes that arrived from other branches through a merge-down of the base.
If we cannot distinguish between "my branch's own changes" and "changes that came in through a merge-down from another branch," the rollout will contain unintended files.
The code I use
Beta Was this translation helpful? Give feedback.
All reactions