llvm-project

Форк
0
/
pr-code-format.yml 
96 строк · 3.2 Кб
1
name: "Check code formatting"
2

3
permissions:
4
  contents: read
5

6
on:
7
  pull_request:
8
    branches:
9
      - main
10

11
jobs:
12
  code_formatter:
13
    runs-on: ubuntu-latest
14
    if: github.repository == 'llvm/llvm-project'
15
    steps:
16
      - name: Fetch LLVM sources
17
        uses: actions/checkout@v4
18
        with:
19
          ref: ${{ github.event.pull_request.head.sha }}
20

21
      - name: Checkout through merge base
22
        uses: rmacklin/fetch-through-merge-base@v0
23
        with:
24
          base_ref: ${{ github.event.pull_request.base.ref }}
25
          head_ref: ${{ github.event.pull_request.head.sha }}
26
          deepen_length: 500
27

28
      - name: Get changed files
29
        id: changed-files
30
        uses: tj-actions/changed-files@v39
31
        with:
32
          separator: ","
33
          skip_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
38
        uses: actions/checkout@v4
39
        with:
40
          repository: ${{ github.repository }}
41
          ref: ${{ github.base_ref }}
42
          sparse-checkout: |
43
            llvm/utils/git/requirements_formatting.txt
44
            llvm/utils/git/code-format-helper.py
45
          sparse-checkout-cone-mode: false
46
          path: code-format-tools
47

48
      - name: "Listed files"
49
        env:
50
          CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
51
        run: |
52
          echo "Formatting files:"
53
          echo "$CHANGED_FILES"
54

55
      - name: Install clang-format
56
        uses: aminya/setup-cpp@v1
57
        with:
58
          clangformat: 18.1.7
59

60
      - name: Setup Python env
61
        uses: actions/setup-python@v5
62
        with:
63
          python-version: '3.11'
64
          cache: 'pip'
65
          cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
66

67
      - name: Install python dependencies
68
        run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
69

70
      - name: Run code formatter
71
        env:
72
          GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
73
          START_REV: ${{ github.event.pull_request.base.sha }}
74
          END_REV: ${{ github.event.pull_request.head.sha }}
75
          CHANGED_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.
81
        run: |
82
          echo "[]" > comments &&
83
          python ./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
92
        if: always()
93
        with:
94
          name: workflow-args
95
          path: |
96
            comments
97

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.