1 name: "Check code formatting"
14 runs-on: ubuntu-latest
17 group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
18 cancel-in-progress: true
19 if: github.repository == 'llvm/llvm-project'
21 - name: Fetch LLVM sources
22 uses: actions/checkout@v4
24 ref: ${{ github.event.pull_request.head.sha }}
26 - name: Checkout through merge base
27 uses: rmacklin/fetch-through-merge-base@v0
29 base_ref: ${{ github.event.pull_request.base.ref }}
30 head_ref: ${{ github.event.pull_request.head.sha }}
33 - name: Get changed files
35 uses: tj-actions/changed-files@v39
38 skip_initial_fetch: true
40 # We need to pull the script from the main branch, so that we ensure
41 # we get the latest version of this script.
42 - name: Fetch code formatting utils
43 uses: actions/checkout@v4
45 repository: ${{ github.repository }}
46 ref: ${{ github.base_ref }}
48 llvm/utils/git/requirements_formatting.txt
49 llvm/utils/git/code-format-helper.py
50 sparse-checkout-cone-mode: false
51 path: code-format-tools
53 - name: "Listed files"
55 CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
57 echo "Formatting files:"
60 - name: Install clang-format
61 uses: aminya/setup-cpp@v1
65 - name: Setup Python env
66 uses: actions/setup-python@v5
68 python-version: '3.11'
70 cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
72 - name: Install python dependencies
73 run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
75 - name: Run code formatter
77 GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
78 START_REV: ${{ github.event.pull_request.base.sha }}
79 END_REV: ${{ github.event.pull_request.head.sha }}
80 CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
81 # TODO(boomanaiden154): Once clang v18 is released, we should be able
82 # to take advantage of the new --diff_from_common_commit option
83 # explicitly in code-format-helper.py and not have to diff starting at
85 # Create an empty comments file so the pr-write job doesn't fail.
87 echo "[]" > comments &&
88 python ./code-format-tools/llvm/utils/git/code-format-helper.py \
89 --write-comment-to-file \
90 --token ${{ secrets.GITHUB_TOKEN }} \
91 --issue-number $GITHUB_PR_NUMBER \
92 --start-rev $(git merge-base $START_REV $END_REV) \
94 --changed-files "$CHANGED_FILES"
96 - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0