-
Notifications
You must be signed in to change notification settings - Fork 52
339 lines (282 loc) · 10 KB
/
build_and_lint_pr.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
name: Build and Analyze
on:
pull_request: # Kick off this on every PR
workflow_call: # We may want to run this workflow from other places, like nightly builds
inputs:
nightly:
required: false
type: boolean
default: false
secrets:
GIST_SECRET:
required: true
jobs:
Build-Platforms:
runs-on: ubuntu-latest
strategy:
matrix:
# This job matrix will generate a separate job for all platforms listed.
# Add platforms in alphabetical order.
platform: [
at-cb,
at-mc,
gt-cc,
wc-mb,
yv3-dl,
yv3-vf,
yv35-bb,
yv35-cl,
yv35-gl,
yv35-hd,
yv35-rf,
yv35-ji,
yv4-sd,
yv4-ff,
yv4-wf,
]
# Need to set this to false otherwise it will cancel all platform builds if one fails.
fail-fast: false
steps:
- uses: actions/checkout@v2
with:
path: ${{ github.event.repository.name }}
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends \
ninja-build \
gperf \
ccache \
dfu-util \
device-tree-compiler \
gcc-multilib \
g++-multilib \
libsdl2-dev \
- name: Setup Python
uses: actions/setup-python@v2
# Exactly what it says on the tin.
- name: Install requirements
run: |
pip install --user -U west
pip install pyelftools
- name: Init West Project
run: |
west init --local ${{ github.event.repository.name }}
# Sets up python and loads packages from the cache.
- name: Try Cache
id: python
uses: actions/cache@v2
with:
path: |
./modules
./zephyr
key: west-yml-${{ hashFiles('OpenBIC/west.yml') }}
- name: Cache SDK Toolchain
id: cache-sdk
uses: actions/cache@v2
with:
path: /home/runner/zephyr-sdk-0.12.4
key: zephyr-sdk-0.12.4
- name: Get SDK Toolchain
if: steps.cache-sdk.outputs.cache-hit != 'true'
id: download-sdk
run: |
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.12.4/zephyr-sdk-0.12.4-x86_64-linux-setup.run
chmod +x zephyr-sdk-0.12.4-x86_64-linux-setup.run
./zephyr-sdk-0.12.4-x86_64-linux-setup.run --quiet -- -d /home/runner/zephyr-sdk-0.12.4
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=/home/runner/zephyr-sdk-0.12.4
- name: Update West Project
run: |
cd OpenBIC
west update
- name: Apply Kernel Patches
run: |
${{ github.event.repository.name }}/scripts/build/apply_patches.py --source="${{ github.event.repository.name }}/fix_patch/" --destination="zephyr"
- name: Build Platform
id: build
continue-on-error: true
run: |
cd ${{ github.event.repository.name }}
touch meta-facebook/${{ matrix.platform }}/CMakeLists.txt
west build -p auto -b ast1030_evb meta-facebook/${{ matrix.platform }}/
- name: Get Build Status
env:
OUTCOME: ${{ steps.build.outcome }}
run: |
ret="$OUTCOME"
echo "$ret"
if [ "$ret" = "success" ]; then
echo "badge_message=PASS" >> $GITHUB_ENV
echo "badge_color=green" >> $GITHUB_ENV
echo "build_return_code=0" >> $GITHUB_ENV
else
echo "badge_message=FAIL" >> $GITHUB_ENV
echo "badge_color=red" >> $GITHUB_ENV
echo "build_return_code=1" >> $GITHUB_ENV
fi
- name: Update Build Badges
if: ${{ inputs.nightly == true }}
uses: schneegans/dynamic-badges-action@v1.4.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 62fb115c4fa43a02acad226534e10932
filename: ${{ matrix.platform }}.json
label: Build
message: ${{ env.badge_message }}
color: ${{ env.badge_color }}
- name: Check Build Failure
if: ${{ env.build_return_code != '0' }}
run : |
exit 1
run-cppcheck:
runs-on: ubuntu-latest
if: ${{ inputs.nightly == false }}
steps:
- name: Get PR File List
shell: bash
run: |
URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${{ github.event.pull_request.number }}/files"
curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $URL | jq -r '.[] | .filename' > git_diff.log
cat git_diff.log
- name: Check for C/CPP Sources
shell: bash
run : |
CPP_FILE_LIST="/tmp/cppcheck_file_list.log"
# Only keep the source files to check or CPPCheck gets confused.
sed '/\(\.c$\|\.cpp$\|\.c$\|\.cc$\|\.cu$\|\.cxx$\|\.h$\|\.hh$\|\.hpp$\|\.hxx$\|\.tcc$\)/!d' git_diff.log > $CPP_FILE_LIST
if [ -s $CPP_FILE_LIST ]; then
echo "C/C++ source files kept:"
cat $CPP_FILE_LIST
fi
if [ -s $CPP_FILE_LIST ]; then
echo "contains_c_source=true" >> $GITHUB_ENV
else
echo "contains_c_source=false" >> $GITHUB_ENV
fi
- uses: actions/checkout@v2
name: Checkout Repo
if: env.contains_c_source == 'true'
- uses: actions/setup-python@v2
name: Setup Python
if: env.contains_c_source == 'true'
- name: Install CPPCheck
if: env.contains_c_source == 'true'
run: sudo apt-get install -y cppcheck
- name: Run CPPCheck on Modified Source Files
if: env.contains_c_source == 'true'
continue-on-error: true
shell: bash
run: |
# These files specify the config for cppcheck and a list of errors to suppress
CPPCHECK_CONFIG=scripts/linters/cppcheck/cppcheck.cfg
CPPCHECK_SUPPRESSED=scripts/linters/cppcheck/cppcheck-suppressions.txt
echo "Files to check:"
cat /tmp/cppcheck_file_list.log
options=( "-j2"
"--force"
"--inconclusive"
"--enable=performance,style,portability,information"
"--library=scripts/linters/cppcheck/cppcheck.cfg"
"--suppressions-list=scripts/linters/cppcheck/cppcheck-suppressions.txt"
"--file-list=/tmp/cppcheck_file_list.log"
"--template={file}:{line}:{column}:{message}"
"--output-file=/tmp/cppcheck.log"
"--report-progress")
cppcheck "${options[@]}"
if [ -s /tmp/cppcheck.log ]; then
echo "Errors Found:"
cat /tmp/cppcheck.log
fi
- uses: actions/upload-artifact@master
name: Upload CPPCheck error log
if: env.contains_c_source == 'true'
with:
name: cppcheck-output
path: /tmp/cppcheck.log
- name: Check for cppcheck output
if: env.contains_c_source == 'true'
run : |
if [ -s /tmp/cppcheck.log ]; then
exit 1
fi
run-clang-format:
runs-on: ubuntu-latest
if: ${{ inputs.nightly == false }}
steps:
- uses: actions/checkout@v2
name: Checkout Repo
- name: Get PR File List
shell: bash
run: |
URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${{ github.event.pull_request.number }}/files"
curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $URL | jq -r '.[] | .filename' > /tmp/change_set.log
cat /tmp/change_set.log
- name: Check for C/CPP Sources
shell: bash
run : |
CLANG_FORMAT_FILE_LIST="/tmp/clang_format_file_list.log"
# Only keep the source files to check or clang-format starts checking everything.
sed '/\(\.c$\|\.cpp$\|\.c$\|\.cc$\|\.cu$\|\.cxx$\|\.h$\|\.hh$\|\.hpp$\|\.hxx$\|\.tcc$\)/!d' /tmp/change_set.log > $CLANG_FORMAT_FILE_LIST
if [ -s $CLANG_FORMAT_FILE_LIST ]; then
echo "C/C++ source files kept for clang-format:"
cat $CLANG_FORMAT_FILE_LIST
fi
if [ -s $CLANG_FORMAT_FILE_LIST ]; then
echo "contains_c_source=true" >> $GITHUB_ENV
echo "contains_clang_errors=false" >> $GITHUB_ENV
else
echo "contains_c_source=false" >> $GITHUB_ENV
fi
- name: Install Clang-Format
if: env.contains_c_source == 'true'
run: sudo apt-get install -y clang-format
- name: Run clang-format on changed fileset.
if: env.contains_c_source == 'true'
continue-on-error: true
shell: bash
run: |
echo "Files to check:"
cat /tmp/clang_format_file_list.log
FILE_PATHS=$(cat /tmp/clang_format_file_list.log)
for FILE_PATH in $FILE_PATHS
do
options=(
"--style=file"
"--dry-run"
"--Werror")
# Clang format outputs to stderr... why do you do this clang-format
if ! clang-format "${options[@]}" $FILE_PATH &> /dev/null ; then
echo -e "\u001b[31;1m$FILE_PATH has clang-format errors!\u001b[0m"
echo $FILE_PATH >> /tmp/clang-format.log
echo "contains_clang_errors=true" >> $GITHUB_ENV
fi
done
- name: Check for clang-format output
if: env.contains_c_source == 'true' && env.contains_clang_errors == 'true'
run : |
if [ -s /tmp/clang-format.log ]; then
exit 1
fi
Aggregate-Lint-Output:
needs: [run-cppcheck, run-clang-format]
if: ${{ always() && inputs.nightly == false }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout Repo
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: /tmp/artifacts
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CPP_FILE=/tmp/artifacts/cppcheck-output/cppcheck.log
if test -f "$CPP_FILE"; then
cat "$CPP_FILE" | reviewdog -efm="%f:%l:%c:%m" -filter-mode=nofilter -reporter=github-pr-check
fi