fix(ci): preserve target branch history for import profiler baseline generation - #18105
Conversation
…generation
Avoid shallow-fetching origin/${TARGET_BRANCH} when TEST_TYPE is import_profile
so git merge-base can successfully find baseline commits for baseline profiling comparison.
There was a problem hiding this comment.
Code Review
This pull request updates the CI scripts to handle shallow clones and fetch target branches more reliably. The review feedback correctly points out that the unshallow fetch logic in 'ci/run_single_test.sh' should also support forks by attempting to fetch from the 'upstream' remote before falling back to 'origin'.
…er baseline Attempt fetching from upstream before falling back to origin to properly support fork repositories.
| if [[ "${TEST_TYPE}" == "import_profile" ]]; then | ||
| git fetch upstream "${TARGET_BRANCH}" 2>/dev/null || git fetch origin "${TARGET_BRANCH}" || true | ||
| else | ||
| git fetch upstream "${TARGET_BRANCH}" --depth=200 2>/dev/null || git fetch origin "${TARGET_BRANCH}" --depth=200 || true | ||
| fi |
There was a problem hiding this comment.
| if [[ "${TEST_TYPE}" == "import_profile" ]]; then | |
| git fetch upstream "${TARGET_BRANCH}" 2>/dev/null || git fetch origin "${TARGET_BRANCH}" || true | |
| else | |
| git fetch upstream "${TARGET_BRANCH}" --depth=200 2>/dev/null || git fetch origin "${TARGET_BRANCH}" --depth=200 || true | |
| fi | |
| if [[ "${TEST_TYPE}" == "import_profile" ]]; then | |
| git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" || true | |
| else | |
| git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" --depth=200 || true | |
| fi |
Since we do not need to support external forks upstream, we can target origin directly. Gemini also suggested this edit
| # Fetch history for the target branch without --depth=1 in case it was shallowly fetched | ||
| if [ -f "$(git rev-parse --git-dir)/shallow" ]; then | ||
| git fetch upstream "${TARGET_BRANCH}" --unshallow 2>/dev/null || \ | ||
| git fetch origin "${TARGET_BRANCH}" --unshallow 2>/dev/null || \ | ||
| git fetch upstream "${TARGET_BRANCH}" 2>/dev/null || \ | ||
| git fetch origin "${TARGET_BRANCH}" 2>/dev/null || true | ||
| fi |
There was a problem hiding this comment.
Similar feedback as my other comment
| # Fetch history for the target branch without --depth=1 in case it was shallowly fetched | |
| if [ -f "$(git rev-parse --git-dir)/shallow" ]; then | |
| git fetch upstream "${TARGET_BRANCH}" --unshallow 2>/dev/null || \ | |
| git fetch origin "${TARGET_BRANCH}" --unshallow 2>/dev/null || \ | |
| git fetch upstream "${TARGET_BRANCH}" 2>/dev/null || \ | |
| git fetch origin "${TARGET_BRANCH}" 2>/dev/null || true | |
| fi | |
| # Fetch history for the target branch without --depth=1 in case it was shallowly fetched | |
| if [ -f "$(git rev-parse --git-dir)/shallow" ]; then | |
| git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" --unshallow 2>/dev/null || \ | |
| git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" 2>/dev/null || true | |
| fi |
There was a problem hiding this comment.
Simplified the unshallow fetch to target origin directly with the explicit refspec.
There was a problem hiding this comment.
Since we don't need to support upstream, we can use
# Try origin first, then fallback to HEAD if everything else fails
BASELINE_COMMIT=$(git merge-base HEAD "origin/${TARGET_BRANCH}" 2>/dev/null || \
git rev-parse HEAD)
There was a problem hiding this comment.
Done! Updated to check origin/${TARGET_BRANCH} directly and fallback to git rev-parse HEAD.
…ne fetching
Address PR review feedback:
- Explicitly pass ${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH} to git fetch to update remote tracking branch refs.
- Target origin directly and fall back to HEAD if merge-base fails.
Avoid shallow-fetching
origin/${TARGET_BRANCH}whenTEST_TYPEis import_profile so git merge-base can successfully find baseline commits for baseline profiling comparison.