-
Notifications
You must be signed in to change notification settings - Fork 840
162 lines (146 loc) · 5.75 KB
/
clang-format-checker.yml
File metadata and controls
162 lines (146 loc) · 5.75 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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 DirectXShaderCompiler sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout through merge base
uses: rmacklin/fetch-through-merge-base@bfe4d03a86f9afa52bc1a70e9814fc92a07f7b75 # v0.3.0
with:
base_ref: ${{ github.event.pull_request.base.ref }}
head_ref: ${{ github.event.pull_request.head.sha }}
deepen_length: 500
- name: Get changed files
id: changed-files
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
with:
separator: ","
skip_initial_fetch: true
# We need to pull the script from the main branch, so that we ensure
# we get the latest version of this script.
- name: Fetch code formatting utils
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: microsoft/DirectXShaderCompiler
ref: ${{ github.base_ref }}
sparse-checkout: |
utils/git/requirements_formatting.txt
utils/git/code-format-helper.py
utils/git/code-format-save-diff.py
sparse-checkout-cone-mode: false
path: code-format-tools
- 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: 'code-format-tools/utils/git/requirements_formatting.txt'
- name: Install python dependencies
run: pip install -r code-format-tools/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 code-format-tools/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}`)
}
# We need to pull the script from the main branch, so that we ensure
# we get the latest version of this script.
- name: Fetch code formatting utils
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: microsoft/DirectXShaderCompiler
ref: ${{ github.base_ref }}
sparse-checkout: |
utils/git/requirements_formatting.txt
utils/git/code-format-helper.py
utils/git/code-format-save-diff.py
sparse-checkout-cone-mode: false
path: code-format-tools
- name: Setup Python env
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'code-format-tools/utils/git/requirements_formatting.txt'
- name: Install python dependencies
run: pip install -r code-format-tools/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 code-format-tools/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 }}