Skip to content

Commit b2eb425

Browse files
Switched refs, added checkout of target for security
1 parent eec1483 commit b2eb425

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,27 @@ jobs:
1717
with:
1818
separator: ","
1919

20-
- name: Calculate number of commits to fetch (PR)
20+
- name: Calculate number of commits to fetch
2121
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
2222

23-
- name: Fetch LLVM sources
23+
- name: Fetch PR sources
2424
uses: actions/checkout@v4
2525
with:
26+
ref: ${{ github.event.pull_request.head.ref }}
2627
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
2741

2842
- name: "Listed files"
2943
run: |
@@ -40,21 +54,21 @@ jobs:
4054
with:
4155
python-version: '3.11'
4256
cache: 'pip'
43-
cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt'
57+
cache-dependency-path: 'llvm-sources/llvm/utils/git/requirements_formatting.txt'
4458

4559
- 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
4761

4862
- name: Run code formatter
4963
env:
5064
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 }}
5366
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
67+
working-directory: ./pr-sources
5468
run: |
55-
python llvm/utils/git/code-format-helper.py \
69+
python ../llvm-sources/llvm/utils/git/code-format-helper.py \
5670
--token ${{ secrets.GITHUB_TOKEN }} \
5771
--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 \
6074
--changed-files "$CHANGED_FILES"

0 commit comments

Comments
 (0)