llvm-project
96 строк · 3.2 Кб
1name: "Check code formatting"
2
3permissions:
4contents: read
5
6on:
7pull_request:
8branches:
9- main
10
11jobs:
12code_formatter:
13runs-on: ubuntu-latest
14if: github.repository == 'llvm/llvm-project'
15steps:
16- name: Fetch LLVM sources
17uses: actions/checkout@v4
18with:
19ref: ${{ github.event.pull_request.head.sha }}
20
21- name: Checkout through merge base
22uses: rmacklin/fetch-through-merge-base@v0
23with:
24base_ref: ${{ github.event.pull_request.base.ref }}
25head_ref: ${{ github.event.pull_request.head.sha }}
26deepen_length: 500
27
28- name: Get changed files
29id: changed-files
30uses: tj-actions/changed-files@v39
31with:
32separator: ","
33skip_initial_fetch: true
34
35# We need to pull the script from the main branch, so that we ensure
36# we get the latest version of this script.
37- name: Fetch code formatting utils
38uses: actions/checkout@v4
39with:
40repository: ${{ github.repository }}
41ref: ${{ github.base_ref }}
42sparse-checkout: |
43llvm/utils/git/requirements_formatting.txt
44llvm/utils/git/code-format-helper.py
45sparse-checkout-cone-mode: false
46path: code-format-tools
47
48- name: "Listed files"
49env:
50CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
51run: |
52echo "Formatting files:"
53echo "$CHANGED_FILES"
54
55- name: Install clang-format
56uses: aminya/setup-cpp@v1
57with:
58clangformat: 18.1.7
59
60- name: Setup Python env
61uses: actions/setup-python@v5
62with:
63python-version: '3.11'
64cache: 'pip'
65cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
66
67- name: Install python dependencies
68run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
69
70- name: Run code formatter
71env:
72GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
73START_REV: ${{ github.event.pull_request.base.sha }}
74END_REV: ${{ github.event.pull_request.head.sha }}
75CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
76# TODO(boomanaiden154): Once clang v18 is released, we should be able
77# to take advantage of the new --diff_from_common_commit option
78# explicitly in code-format-helper.py and not have to diff starting at
79# the merge base.
80# Create an empty comments file so the pr-write job doesn't fail.
81run: |
82echo "[]" > comments &&
83python ./code-format-tools/llvm/utils/git/code-format-helper.py \
84--write-comment-to-file \
85--token ${{ secrets.GITHUB_TOKEN }} \
86--issue-number $GITHUB_PR_NUMBER \
87--start-rev $(git merge-base $START_REV $END_REV) \
88--end-rev $END_REV \
89--changed-files "$CHANGED_FILES"
90
91- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
92if: always()
93with:
94name: workflow-args
95path: |
96comments
97