-
Notifications
You must be signed in to change notification settings - Fork 707
132 lines (119 loc) · 4.23 KB
/
clang-format-checker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: "Check code formatting"
on:
pull_request_target:
types: [opened,synchronize]
issue_comment:
types: edited
jobs:
code_formatter:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Fetch LLVM sources
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
separator: ","
fetch_depth: 100 # Fetches only the last 10 commits
- name: "Listed files"
env:
LISTED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Formatting files:"
echo "$LISTED_FILES"
- name: Install clang-format
uses: aminya/setup-cpp@v1
with:
clangformat: 17.0.1
- name: Setup Python env
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'utils/git/requirements_formatting.txt'
- name: Install python dependencies
run: pip install -r utils/git/requirements_formatting.txt
- name: Run code formatter
id: formatter
env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
START_REV: ${{ github.event.pull_request.base.sha }}
END_REV: ${{ github.event.pull_request.head.sha }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
python utils/git/code-format-helper.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--start-rev $START_REV \
--end-rev $END_REV \
--changed-files "$CHANGED_FILES"
apply_diff:
if: ${{ github.event_name == 'issue_comment' && endsWith(github.event.comment.body, '- [x] Check this box to apply formatting changes to this branch.') }}
runs-on: ubuntu-latest
env:
TMP_DIFF_FILE: /tmp/diff.patch
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/github-script@v3
id: get-pr
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
try {
const result = await github.pulls.get(request)
return result.data
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: Fetch LLVM sources
uses: actions/checkout@v4
with:
fetch-depth: 2
path: build/main_src
- name: Setup Python env
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'build/main_src/utils/git/requirements_formatting.txt'
- name: Install python dependencies
run: pip install -r build/main_src/utils/git/requirements_formatting.txt
- name: Apply code diff
env:
GITHUB_PR_NUMBER: ${{ github.event.issue.number }}
COMMENT_ID: ${{ github.event.comment.id }}
run: |
python build/main_src/utils/git/code-format-save-diff.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--tmp-diff-file $TMP_DIFF_FILE \
--comment-id $COMMENT_ID
- name: Fetch LLVM sources for head
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }}
repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }}
- name: apply diff
run: |
git apply $TMP_DIFF_FILE
git add .
- name: Commit & Push changes
uses: actions-js/push@master
with:
branch: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }}
repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }}
github_token: ${{ secrets.GITHUB_TOKEN }}