Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/reusable-check-html-ids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,33 @@ jobs:
- name: 'Find merge base'
id: merge-base
run: |
# Fetching can fail with "fatal: shallow file has changed since we
# read it", especially for old pull requests, which have a lot of
# history to fetch. Retry it several times (see gh-151365).
retry_fetch() {
for attempt in $(seq 5); do
if [ "${attempt}" -gt 1 ]; then
echo "::warning::git fetch failed, retrying (attempt ${attempt})"
sleep 3
fi
if git fetch "$@"; then
return 0
fi
done
return 1
}

BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
git fetch --depth=$((${{ github.event.pull_request.commits }} + 10)) --no-tags origin "$BASE" "$HEAD"
retry_fetch --depth=$((${{ github.event.pull_request.commits }} + 10)) --no-tags origin "$BASE" "$HEAD"

if ! MERGE_BASE=$(git merge-base "$BASE" "$HEAD" 2>/dev/null); then
git fetch --deepen=1 --no-tags origin "$BASE" "$HEAD"
retry_fetch --deepen=1 --no-tags origin "$BASE" "$HEAD"

OLDEST=$(git rev-list --reflog --max-parents=0 --reverse "${BASE}^" "${HEAD}^" | head -1)
TIMESTAMP=$(git show --format=%at --no-patch "$OLDEST")

git fetch --shallow-since="$TIMESTAMP" --no-tags origin "$BASE" "$HEAD"
retry_fetch --shallow-since="$TIMESTAMP" --no-tags origin "$BASE" "$HEAD"

MERGE_BASE=$(git merge-base "$BASE" "$HEAD")
fi
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/reusable-context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,32 @@ jobs:
run: |
set -eux

# Fetching can fail with "fatal: shallow file has changed since we
# read it", especially for old pull requests, which have a lot of
# history to fetch. Retry it several times (see gh-151365).
retry_fetch() {
for attempt in $(seq 5); do
if [ "${attempt}" -gt 1 ]; then
echo "::warning::git fetch failed, retrying (attempt ${attempt})"
sleep 3
fi
if git fetch "$@"; then
return 0
fi
done
return 1
}

# Fetch enough history to find a common ancestor commit (aka merge-base):
git fetch origin "${refspec_pr}" --depth=$(( commits + 1 )) \
retry_fetch origin "${refspec_pr}" --depth=$(( commits + 1 )) \
--no-tags --prune --no-recurse-submodules

# This should get the oldest commit in the local fetched history (which may not be the commit the PR branched from):
COMMON_ANCESTOR=$( git rev-list --first-parent --max-parents=0 --max-count=1 "${branch_pr}" )
DATE=$( git log --date=iso8601 --format=%cd "${COMMON_ANCESTOR}" )

# Get all commits since that commit date from the base branch (eg: main):
git fetch origin "${refspec_base}" --shallow-since="${DATE}" \
retry_fetch origin "${refspec_base}" --shallow-since="${DATE}" \
--no-tags --prune --no-recurse-submodules
env:
branch_pr: 'origin/${{ github.event.pull_request.head.ref }}'
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/reusable-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,32 @@ jobs:
- name: 'Fetch commits to get branch diff'
if: github.event_name == 'pull_request'
run: |
# Fetching can fail with "fatal: shallow file has changed since we
# read it", especially for old pull requests, which have a lot of
# history to fetch. Retry it several times (see gh-151365).
retry_fetch() {
for attempt in $(seq 5); do
if [ "${attempt}" -gt 1 ]; then
echo "::warning::git fetch failed, retrying (attempt ${attempt})"
sleep 3
fi
if git fetch "$@"; then
return 0
fi
done
return 1
}

# Fetch enough history to find a common ancestor commit (aka merge-base):
git fetch origin "${refspec_pr}" --depth=$(( commits + 1 )) \
retry_fetch origin "${refspec_pr}" --depth=$(( commits + 1 )) \
--no-tags --prune --no-recurse-submodules

# This should get the oldest commit in the local fetched history (which may not be the commit the PR branched from):
COMMON_ANCESTOR=$( git rev-list --first-parent --max-parents=0 --max-count=1 "${branch_pr}" )
DATE=$( git log --date=iso8601 --format=%cd "${COMMON_ANCESTOR}" )

# Get all commits since that commit date from the base branch (eg: master or main):
git fetch origin "${refspec_base}" --shallow-since="${DATE}" \
retry_fetch origin "${refspec_base}" --shallow-since="${DATE}" \
--no-tags --prune --no-recurse-submodules
- name: 'Set up Python'
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
Expand Down
Loading