-
Notifications
You must be signed in to change notification settings - Fork 6
252 lines (216 loc) · 8.42 KB
/
check-clang-format.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
name: Check ClangFormat Configuration
env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-clang-format.yml"
- "other/clang-format-configuration/scripts/convert-clang-format-configuration.js"
- "other/clang-format-configuration/testdata/**"
- "other/clang-format-configuration/.clang-format"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-clang-format.yml"
- "other/clang-format-configuration/scripts/convert-clang-format-configuration.js"
- "other/clang-format-configuration/testdata/**"
- "other/clang-format-configuration/.clang-format"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
schedule:
# Run periodically to catch breakage caused by external changes.
- cron: "0 17 * * WED"
workflow_dispatch:
inputs:
clang-format-version:
description: ClangFormat version (leave empty for standard version)
type: string
default: ""
required: false
repository_dispatch:
jobs:
validate:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x
- name: Validate ClangFormat configuration files
run: task --silent clang-format:validate
check-config:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x
- name: Set environment variables
run: |
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then
echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV"
else
echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV"
fi
echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV"
echo "YQ_INSTALL_PATH=${{ runner.temp }}/yq" >> "$GITHUB_ENV"
echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV"
- name: Download ClangFormat
id: download-clang-format
uses: MrOctopus/[email protected]
with:
repository: arduino/clang-static-binaries
tag: ${{ env.CLANG_FORMAT_VERSION }}
asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2
target: ${{ env.CLANG_FORMAT_INSTALL_PATH }}
- name: Install ClangFormat
run: |
cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}"
tar --extract --file="${{ steps.download-clang-format.outputs.name }}"
# Add installation to PATH:
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH"
- name: Download yq
id: download-yq
uses: MrOctopus/[email protected]
with:
repository: mikefarah/yq
asset: yq_linux_amd64.tar.gz
target: ${{ env.YQ_INSTALL_PATH }}
- name: Install yq
run: |
cd "${{ env.YQ_INSTALL_PATH }}"
tar --extract --file="${{ steps.download-yq.outputs.name }}"
# Add installation to PATH:
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.YQ_INSTALL_PATH }}/yq" >> "$GITHUB_PATH"
- name: Check ClangFormat configuration file
id: check
run: |
task \
--silent \
clang-format:check-config \
CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}"
- name: Save effective configuration file to a workflow artifact
if: >
always() &&
steps.check.outcome == 'failure'
uses: actions/upload-artifact@v3
with:
path: ${{ env.WORKING_FOLDER }}/expected/.clang-format
if-no-files-found: error
name: config-output
check-output:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x
- name: Set environment variables
run: |
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then
echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV"
else
echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV"
fi
echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV"
echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV"
- name: Download ClangFormat
id: download
uses: MrOctopus/[email protected]
with:
repository: arduino/clang-static-binaries
tag: ${{ env.CLANG_FORMAT_VERSION }}
asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2
target: ${{ env.CLANG_FORMAT_INSTALL_PATH }}
- name: Install ClangFormat
run: |
cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}"
tar --extract --file="${{ steps.download.outputs.name }}"
# Add installation to PATH:
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH"
- name: Check ClangFormat output
id: check
run: |
task \
clang-format:check-output \
CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}" \
WORKING_FOLDER="${{ env.WORKING_FOLDER }}"
- name: Save formatted test data to a workflow artifact
if: >
always() &&
steps.check.outcome == 'failure'
uses: actions/upload-artifact@v3
with:
path: ${{ env.WORKING_FOLDER }}/output
if-no-files-found: error
name: testdata-output
check-testdata:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x
- name: Check ClangFormat test data
run: task --silent clang-format:check-testdata
convert:
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Set environment variables
run: |
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
echo "CONVERSION_OUTPUT_PATH=${{ runner.temp }}/clang-format-js-object.txt" >> "$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x
- name: Convert the ClangFormat configuration
run: |
task \
--silent \
clang-format:convert \
OUTPUT_PATH="${{ env.CONVERSION_OUTPUT_PATH }}"
- name: Save conversion to a workflow artifact
uses: actions/upload-artifact@v3
with:
path: ${{ env.CONVERSION_OUTPUT_PATH }}
if-no-files-found: error
name: javascript-configuration-object