7
7
code_formatter :
8
8
runs-on : ubuntu-latest
9
9
steps :
10
- - name : Fetch LLVM sources
11
- uses : actions/checkout@v4
12
- with :
13
- fetch-depth : 2 # Fetches only the last 2 commits
14
-
10
+ # Get changed files before checking out the repository to force the action
11
+ # to analyze the diff from the Github API rather than looking at the
12
+ # shallow clone and erroring out, which is significantly more prone to
13
+ # failure.
15
14
- name : Get changed files
16
15
id : changed-files
17
16
uses : tj-actions/changed-files@v39
18
17
with :
19
18
separator : " ,"
20
- fetch_depth : 2000 # Fetches only the last 2000 commits
19
+
20
+ - name : Calculate number of commits to fetch
21
+ run : echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
22
+
23
+ - name : Fetch PR sources
24
+ uses : actions/checkout@v4
25
+ with :
26
+ ref : ${{ github.event.pull_request.head.sha }}
27
+ fetch-depth : ${{ env.PR_FETCH_DEPTH }}
28
+ path : pr-sources
29
+
30
+ # We need to make sure that we aren't executing/using any code from the
31
+ # PR for security reasons as we're using pull_request_target. Checkout
32
+ # the target branch with the necessary files.
33
+ - name : Fetch LLVM Sources
34
+ uses : actions/checkout@v4
35
+ with :
36
+ sparse-checkout : |
37
+ llvm/utils/git/requirements_formatting.txt
38
+ llvm/utils/git/code-format-helper.py
39
+ sparse-checkout-cone-mode : false
40
+ path : llvm-sources
21
41
22
42
- name : " Listed files"
23
43
run : |
@@ -34,21 +54,21 @@ jobs:
34
54
with :
35
55
python-version : ' 3.11'
36
56
cache : ' pip'
37
- cache-dependency-path : ' llvm/utils/git/requirements_formatting.txt'
57
+ cache-dependency-path : ' llvm-sources/llvm /utils/git/requirements_formatting.txt'
38
58
39
59
- name : Install python dependencies
40
- run : pip install -r llvm/utils/git/requirements_formatting.txt
60
+ run : pip install -r llvm-sources/llvm /utils/git/requirements_formatting.txt
41
61
42
62
- name : Run code formatter
43
63
env :
44
64
GITHUB_PR_NUMBER : ${{ github.event.pull_request.number }}
45
- START_REV : ${{ github.event.pull_request.base.sha }}
46
- END_REV : ${{ github.event.pull_request.head.sha }}
65
+ PR_DEPTH : ${{ github.event.pull_request.commits }}
47
66
CHANGED_FILES : ${{ steps.changed-files.outputs.all_changed_files }}
67
+ working-directory : ./pr-sources
48
68
run : |
49
- python llvm/utils/git/code-format-helper.py \
69
+ python ../llvm-sources/ llvm/utils/git/code-format-helper.py \
50
70
--token ${{ secrets.GITHUB_TOKEN }} \
51
71
--issue-number $GITHUB_PR_NUMBER \
52
- --start-rev $START_REV \
53
- --end-rev $END_REV \
72
+ --start-rev HEAD~$PR_DEPTH \
73
+ --end-rev HEAD \
54
74
--changed-files "$CHANGED_FILES"
0 commit comments