@@ -17,13 +17,27 @@ jobs:
17
17
with :
18
18
separator : " ,"
19
19
20
- - name : Calculate number of commits to fetch (PR)
20
+ - name : Calculate number of commits to fetch
21
21
run : echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
22
22
23
- - name : Fetch LLVM sources
23
+ - name : Fetch PR sources
24
24
uses : actions/checkout@v4
25
25
with :
26
+ ref : ${{ github.event.pull_request.head.ref }}
26
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
27
41
28
42
- name : " Listed files"
29
43
run : |
@@ -40,21 +54,21 @@ jobs:
40
54
with :
41
55
python-version : ' 3.11'
42
56
cache : ' pip'
43
- cache-dependency-path : ' llvm/utils/git/requirements_formatting.txt'
57
+ cache-dependency-path : ' llvm-sources/llvm /utils/git/requirements_formatting.txt'
44
58
45
59
- name : Install python dependencies
46
- run : pip install -r llvm/utils/git/requirements_formatting.txt
60
+ run : pip install -r llvm-sources/llvm /utils/git/requirements_formatting.txt
47
61
48
62
- name : Run code formatter
49
63
env :
50
64
GITHUB_PR_NUMBER : ${{ github.event.pull_request.number }}
51
- START_REV : ${{ github.event.pull_request.base.sha }}
52
- END_REV : ${{ github.event.pull_request.head.sha }}
65
+ PR_DEPTH : ${{ github.event.pull_request.commits }}
53
66
CHANGED_FILES : ${{ steps.changed-files.outputs.all_changed_files }}
67
+ working-directory : ./pr-sources
54
68
run : |
55
- python llvm/utils/git/code-format-helper.py \
69
+ python ../llvm-sources/ llvm/utils/git/code-format-helper.py \
56
70
--token ${{ secrets.GITHUB_TOKEN }} \
57
71
--issue-number $GITHUB_PR_NUMBER \
58
- --start-rev $START_REV \
59
- --end-rev $END_REV \
72
+ --start-rev HEAD~$PR_DEPTH \
73
+ --end-rev HEAD \
60
74
--changed-files "$CHANGED_FILES"
0 commit comments