-
Notifications
You must be signed in to change notification settings - Fork 6
208 lines (174 loc) · 6.64 KB
/
merge-criteria.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
name: Merge Criteria
on:
pull_request:
push:
branches: main
jobs:
generate_matrix:
name: Generate Matrix
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get changed directories
id: changed-files
uses: tj-actions/changed-files@v37
with:
dir_names: 'true'
dir_names_max_depth: '1'
json: 'true'
escape_json: 'false'
- name: Filter changed directories
id: changed-files-filtered
# The build pipeline is triggered only for the project in which the changes happened.
# For example if a change was made in flight_computer/src/main.cpp, a pipeline will
# run only for the flight_computer project.
# Additionally, if changes happened at the root of the repository, or in .github/,
# the pipeline will run for all three projects.
run: |
contains_dot=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | jq 'map(select(. == ".")) | length')
contains_dotgithub=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | jq 'map(select(. == ".github")) | length')
if [[ $contains_dot -gt 0 || $contains_dotgithub -gt 0 ]]; then
filtered_array='["flight_computer","ground_station","telemetry"]'
else
filtered_array='${{ steps.changed-files.outputs.all_changed_files }}'
fi
echo "$filtered_array"
echo "matrix=$filtered_array" >> "$GITHUB_OUTPUT"
outputs:
matrix: ${{ steps.changed-files-filtered.outputs.matrix }}
format_check:
if: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
name: Format Check
needs: generate_matrix
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run clang-format
uses: jidicula/[email protected]
with:
clang-format-version: '13'
check-path: '${{ matrix.project }}/src'
exclude-regex: '(lib|telemetry/src/st|ground_station/src/format)'
build_lint:
if: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
needs: [generate_matrix, format_check]
name: '[Ubuntu] Build + Lint'
# We are linting on Ubuntu because the linter seems to work better on Linux
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check cache
uses: actions/cache@v3
with:
path: ~/.platformio/.cache
# Add OS to key if testing with multiple OSes
key: ${{ matrix.project }}-pio
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'pip'
- name: Install dependencies
run: pip install --upgrade platformio
- name: Install PlatformIO Libraries
run: pio pkg install --global
- name: Build
shell: bash
run: |
if [[ "${{ matrix.project }}" == "flight_computer" ]]; then
platformio run -d ${{ matrix.project }} --environment debug
else
platformio run -d ${{ matrix.project }}
fi
- name: Generate compile_commands.json
run: |
if [[ "${{ matrix.project }}" == "flight_computer" ]]; then
platformio run -d ${{ matrix.project }} --target compiledb --environment debug
else
platformio run -d ${{ matrix.project }} --target compiledb
fi
- name: Lint
working-directory: ./${{ matrix.project }}
run: |
if [[ "${{ matrix.project }}" == "flight_computer" ]]; then
output=$(platformio check --environment debug)
else
output=$(platformio check)
fi
echo "$output"
echo "Note: Warnings 'clang-diagnostic-c++17-extensions' and 'clang-analyzer-valist.Uninitialized' are excluded from checking since they seem to be false-positives. Fix everything else!"
# filter the output to exclude false positives
filtered_output=$(echo "$output" | grep -vE 'clang-diagnostic-c\+\+17-extensions|clang-analyzer-valist.Uninitialized')
if echo "$filtered_output" | grep -q "warning"; then
echo "clang-tidy check failed!"
exit 1
fi
- name: Upload Compile Commands
uses: actions/upload-artifact@v3
with:
name: ubuntu_compile_commands
path: |
./${{ matrix.project }}/.pio/build/**/compile_commands.json
if-no-files-found: error
retention-days: 90
build_upload:
if: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
needs: [generate_matrix, format_check]
name: '[Windows] Build + Upload'
# We are running this on windows because the users get binaries compiled on windows.
runs-on: windows-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check cache
uses: actions/cache@v3
with:
path: ~/.platformio/.cache
# Add OS to key if testing with multiple OSes
key: ${{ matrix.project }}-pio
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'pip'
- name: Install dependencies
run: pip install --upgrade platformio
- name: Install PlatformIO Libraries
run: pio pkg install --global
- name: Build
shell: bash
run: |
platformio run -d ${{ matrix.project }}
if [[ "${{ matrix.project }}" == "ground_station" ]]; then
python ${{ matrix.project }}/uf2_loader.py ${{ matrix.project }}/.pio/build/ground_station/firmware
fi
- name: Generate compile_commands.json
run: platformio run -d ${{ matrix.project }} --target compiledb
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
./${{ matrix.project }}/.pio/build/**/firmware.UF2
./${{ matrix.project }}/.pio/build/**/firmware.bin
./${{ matrix.project }}/.pio/build/**/firmware.elf
./${{ matrix.project }}/.pio/build/**/compile_commands.json
if-no-files-found: error
retention-days: 90