diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e76bf2e4c7..e88b6cbf50d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,8 +37,16 @@ jobs: - name: Calculate the fetch depth run: | if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then - echo "GIT_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.event.pull_request.base.repo.full_name }}" ]; then + echo "IS_FORK_PR=true" >> "${GITHUB_ENV}" + # Fork PRs need full history to find the merge base + echo "GIT_FETCH_DEPTH=0" >> "${GITHUB_ENV}" + else + echo "IS_FORK_PR=false" >> "${GITHUB_ENV}" + echo "GIT_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + fi else + echo "IS_FORK_PR=false" >> "${GITHUB_ENV}" echo "GIT_FETCH_DEPTH=2" >> "${GITHUB_ENV}" fi - name: Check out the revision with minimal required history @@ -75,7 +83,12 @@ jobs: - name: Calculate base ref run: | if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then - git fetch --depth=1 origin "${{ github.event.pull_request.base.sha }}" + if [ "$IS_FORK_PR" == "true" ]; then + # Fork PR: full history already fetched, just ensure the base SHA is available + git fetch origin "${{ github.event.pull_request.base.sha }}" + else + git fetch --depth=1 origin "${{ github.event.pull_request.base.sha }}" + fi BASE_REF="${{ github.event.pull_request.base.sha }}" else BASE_REF="HEAD~1" @@ -282,8 +295,16 @@ jobs: - name: Calculate the fetch depth run: | if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then - echo "GIT_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.event.pull_request.base.repo.full_name }}" ]; then + echo "IS_FORK_PR=true" >> "${GITHUB_ENV}" + # Fork PRs need full history to find the merge base + echo "GIT_FETCH_DEPTH=0" >> "${GITHUB_ENV}" + else + echo "IS_FORK_PR=false" >> "${GITHUB_ENV}" + echo "GIT_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + fi else + echo "IS_FORK_PR=false" >> "${GITHUB_ENV}" echo "GIT_FETCH_DEPTH=2" >> "${GITHUB_ENV}" fi - name: Check out the revision with minimal required history @@ -327,7 +348,12 @@ jobs: tests/component/:: -- -v else if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then - git fetch --depth=1 origin "${{ github.event.pull_request.base.sha }}" + if [ "$IS_FORK_PR" == "true" ]; then + # Fork PR: full history already fetched, just ensure the base SHA is available + git fetch origin "${{ github.event.pull_request.base.sha }}" + else + git fetch --depth=1 origin "${{ github.event.pull_request.base.sha }}" + fi BASE_REF="${{ github.event.pull_request.base.sha }}" else BASE_REF="HEAD~1" diff --git a/changes/9617.misc.md b/changes/9617.misc.md new file mode 100644 index 00000000000..f5a5bcc2b82 --- /dev/null +++ b/changes/9617.misc.md @@ -0,0 +1 @@ +Use full git clone for fork PRs to fix merge-base computation failure in CI.