1 name: "Check code formatting"
2 on: pull_request_target
9 if: github.repository == 'llvm/llvm-project'
11 - name: Fetch LLVM sources
12 uses: actions/checkout@v4
14 ref: ${{ github.event.pull_request.head.sha }}
16 - name: Checkout through merge base
17 uses: rmacklin/fetch-through-merge-base@v0
19 base_ref: ${{ github.event.pull_request.base.ref }}
20 head_ref: ${{ github.event.pull_request.head.sha }}
23 - name: Get changed files
25 uses: tj-actions/changed-files@v39
28 skip_initial_fetch: true
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 code formatting utils
34 uses: actions/checkout@v4
37 llvm/utils/git/requirements_formatting.txt
38 llvm/utils/git/code-format-helper.py
39 sparse-checkout-cone-mode: false
40 path: code-format-tools
42 - name: "Listed files"
44 CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
46 echo "Formatting files:"
49 - name: Install clang-format
50 uses: aminya/setup-cpp@v1
54 - name: Setup Python env
55 uses: actions/setup-python@v4
57 python-version: '3.11'
59 cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
61 - name: Install python dependencies
62 run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
64 - name: Run code formatter
66 GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
67 START_REV: ${{ github.event.pull_request.base.sha }}
68 END_REV: ${{ github.event.pull_request.head.sha }}
69 CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
71 python ./code-format-tools/llvm/utils/git/code-format-helper.py \
72 --token ${{ secrets.GITHUB_TOKEN }} \
73 --issue-number $GITHUB_PR_NUMBER \
74 --start-rev $START_REV \
76 --changed-files "$CHANGED_FILES"