Skip to content

Commit 2389d41

Browse files
chore: update global workflows (#23)
1 parent 20efbcd commit 2389d41

File tree

2 files changed

+245
-66
lines changed

2 files changed

+245
-66
lines changed

.github/workflows/common-lint.yml

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
---
2+
# This action is centrally managed in https://github.com/<organization>/.github/
3+
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
4+
# the above-mentioned repo.
5+
6+
# Common linting.
7+
8+
name: common lint
9+
10+
on:
11+
pull_request:
12+
branches: [master]
13+
types: [opened, synchronize, reopened]
14+
15+
concurrency:
16+
group: "${{ github.workflow }}-${{ github.ref }}"
17+
cancel-in-progress: true
18+
19+
jobs:
20+
lint:
21+
name: Common Lint
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: '3.12'
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade \
35+
pip \
36+
setuptools \
37+
wheel \
38+
cmakelang \
39+
flake8 \
40+
nb-clean \
41+
nbqa[toolchain]
42+
43+
- name: C++ - find files
44+
id: cpp_files
45+
run: |
46+
# find files
47+
found_files=$(find . -type f \
48+
-iname "*.c" -o \
49+
-iname "*.cpp" -o \
50+
-iname "*.h" -o \
51+
-iname "*.hpp" -o \
52+
-iname "*.m" -o \
53+
-iname "*.mm" \
54+
)
55+
ignore_files=$(find . -type f -iname ".clang-format-ignore")
56+
57+
# Loop through each C++ file
58+
for file in $found_files; do
59+
for ignore_file in $ignore_files; do
60+
ignore_directory=$(dirname "$ignore_file")
61+
# if directory of ignore_file is beginning of file
62+
if [[ "$file" == "$ignore_directory"* ]]; then
63+
echo "ignoring file: ${file}"
64+
found_files="${found_files//${file}/}"
65+
break 1
66+
fi
67+
done
68+
done
69+
70+
# remove empty lines
71+
found_files=$(echo "$found_files" | sed '/^\s*$/d')
72+
73+
echo "found cpp files: ${found_files}"
74+
75+
# do not quote to keep this as a single line
76+
echo found_files=${found_files} >> $GITHUB_OUTPUT
77+
78+
- name: C++ - Clang format lint
79+
if: always() && steps.cpp_files.outputs.found_files
80+
uses: DoozyX/clang-format-lint-action@v0.18
81+
with:
82+
source: ${{ steps.cpp_files.outputs.found_files }}
83+
extensions: 'c,cpp,h,hpp,m,mm'
84+
style: file
85+
inplace: false
86+
87+
- name: CMake - find files
88+
id: cmake_files
89+
if: always()
90+
run: |
91+
# find files
92+
found_files=$(find . -type f -iname "CMakeLists.txt" -o -iname "*.cmake")
93+
ignore_files=$(find . -type f -iname ".cmake-lint-ignore")
94+
95+
# Loop through each C++ file
96+
for file in $found_files; do
97+
for ignore_file in $ignore_files; do
98+
ignore_directory=$(dirname "$ignore_file")
99+
# if directory of ignore_file is beginning of file
100+
if [[ "$file" == "$ignore_directory"* ]]; then
101+
echo "ignoring file: ${file}"
102+
found_files="${found_files//${file}/}"
103+
break 1
104+
fi
105+
done
106+
done
107+
108+
# remove empty lines
109+
found_files=$(echo "$found_files" | sed '/^\s*$/d')
110+
111+
echo "found cmake files: ${found_files}"
112+
113+
# do not quote to keep this as a single line
114+
echo found_files=${found_files} >> $GITHUB_OUTPUT
115+
116+
- name: CMake - cmake-lint
117+
if: always() && steps.cmake_files.outputs.found_files
118+
run: |
119+
cmake-lint --line-width 120 --tab-size 4 ${{ steps.cmake_files.outputs.found_files }}
120+
121+
- name: Docker - find files
122+
id: dokcer_files
123+
if: always()
124+
run: |
125+
found_files=$(find . -type f -iname "Dockerfile" -o -iname "*.dockerfile")
126+
127+
echo "found_files: ${found_files}"
128+
129+
# do not quote to keep this as a single line
130+
echo found_files=${found_files} >> $GITHUB_OUTPUT
131+
132+
- name: Docker - hadolint
133+
if: always() && steps.dokcer_files.outputs.found_files
134+
run: |
135+
docker pull hadolint/hadolint
136+
137+
# create hadolint config file
138+
cat <<EOF > .hadolint.yaml
139+
---
140+
ignored:
141+
- DL3008
142+
- DL3013
143+
- DL3016
144+
- DL3018
145+
- DL3028
146+
- DL3059
147+
EOF
148+
149+
failed=0
150+
failed_files=""
151+
152+
for file in ${{ steps.dokcer_files.outputs.found_files }}; do
153+
echo "::group::${file}"
154+
docker run --rm -i \
155+
-e "NO_COLOR=0" \
156+
-e "HADOLINT_VERBOSE=1" \
157+
-v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \
158+
hadolint/hadolint < $file || {
159+
failed=1
160+
failed_files="$failed_files $file"
161+
}
162+
echo "::endgroup::"
163+
done
164+
165+
if [ $failed -ne 0 ]; then
166+
echo "::error:: hadolint failed for the following files: $failed_files"
167+
exit 1
168+
fi
169+
170+
- name: Python - flake8
171+
if: always()
172+
run: |
173+
python -m flake8 \
174+
--color=always \
175+
--verbose
176+
177+
- name: Python - nbqa flake8
178+
if: always()
179+
run: |
180+
python -m nbqa flake8 \
181+
--color=always \
182+
--verbose \
183+
.
184+
185+
- name: Python - nb-clean
186+
if: always()
187+
run: |
188+
output=$(find . -name '*.ipynb' -exec nb-clean check {} \;)
189+
190+
# fail if there are any issues
191+
if [ -n "$output" ]; then
192+
echo "$output"
193+
exit 1
194+
fi
195+
196+
- name: YAML - find files
197+
id: yaml_files
198+
if: always()
199+
run: |
200+
# space separated list of files
201+
FILES=.clang-format
202+
203+
# empty placeholder
204+
found_files=""
205+
206+
for FILE in ${FILES}; do
207+
if [ -f "$FILE" ]
208+
then
209+
found_files="$found_files $FILE"
210+
fi
211+
done
212+
213+
echo "found_files=${found_files}" >> $GITHUB_OUTPUT
214+
215+
- name: YAML - yamllint
216+
id: yamllint
217+
if: always()
218+
uses: ibiqlik/action-yamllint@v3
219+
with:
220+
# https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration
221+
config_data: |
222+
extends: default
223+
rules:
224+
comments:
225+
level: error
226+
document-start:
227+
level: error
228+
line-length:
229+
max: 120
230+
new-line-at-end-of-file:
231+
level: error
232+
new-lines:
233+
type: unix
234+
truthy:
235+
# GitHub uses "on" for workflow event triggers
236+
# .clang-format file has options of "Yes" "No" that will be caught by this, so changed to "warning"
237+
allowed-values: ['true', 'false', 'on']
238+
check-keys: true
239+
level: warning
240+
file_or_dir: . ${{ steps.yaml_files.outputs.found_files }}
241+
242+
- name: YAML - log
243+
if: always() && steps.yamllint.outcome == 'failure'
244+
run: |
245+
cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY

.github/workflows/yaml-lint.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)