Skip to content

Commit 7a6eef9

Browse files
committed
Build docs on unmerged branch so warning lines match & avoid deep clone
1 parent 568cae7 commit 7a6eef9

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

.github/workflows/reusable-docs.yml

+23-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,30 @@ jobs:
1616
name: 'Docs'
1717
runs-on: ubuntu-latest
1818
timeout-minutes: 60
19+
env:
20+
branch_base: 'origin/${{ github.event.pull_request.base.ref }}'
21+
branch_pr: 'origin/${{ github.event.pull_request.head.ref }}'
22+
refspec_base: '+${{ github.event.pull_request.base.sha }}:remotes/origin/${{ github.event.pull_request.base.ref }}'
23+
refspec_pr: '+${{ github.event.pull_request.head.sha }}:remotes/origin/${{ github.event.pull_request.head.ref }}'
1924
steps:
20-
- uses: actions/checkout@v3
25+
- name: 'Check out latest PR branch commit'
26+
uses: actions/checkout@v3
2127
with:
22-
fetch-depth: 0
28+
ref: ${{ github.event.pull_request.head.sha }}
29+
# Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721
30+
- name: 'Fetch commits to get branch diff'
31+
run: |
32+
# Fetch enough history to find a common ancestor commit (aka merge-base):
33+
git fetch origin ${{ env.refspec_pr }} --depth=$(( ${{ github.event.pull_request.commits }} + 1 )) \
34+
--no-tags --prune --no-recurse-submodules
35+
36+
# This should get the oldest commit in the local fetched history (which may not be the commit the PR branched from):
37+
COMMON_ANCESTOR=$( git rev-list --first-parent --max-parents=0 --max-count=1 ${{ env.branch_pr }} )
38+
DATE=$( git log --date=iso8601 --format=%cd "${COMMON_ANCESTOR}" )
39+
40+
# Get all commits since that commit date from the base branch (eg: master or main):
41+
git fetch origin ${{ env.refspec_base }} --shallow-since="${DATE}" \
42+
--no-tags --prune --no-recurse-submodules
2343
- name: 'Set up Python'
2444
uses: actions/setup-python@v4
2545
with:
@@ -40,7 +60,7 @@ jobs:
4060
if: github.event_name == 'pull_request'
4161
run: |
4262
python Doc/tools/check-warnings.py \
43-
--annotate-diff 'origin/${{ github.base_ref }}' '${{ github.sha }}' \
63+
--annotate-diff '${{ env.branch_base }}' '${{ env.branch_pr }}' \
4464
--fail-if-regression \
4565
--fail-if-improved
4666

0 commit comments

Comments
 (0)