Skip to content

Commit 3f10695

Browse files
feat(workflows): add actionlint and problem matchers
1 parent 708c2a4 commit 3f10695

15 files changed

Lines changed: 276 additions & 109 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "cargo-fmt",
5+
"severity": "error",
6+
"pattern": [
7+
{
8+
"regexp": "^Diff in (.+):(\\d+):$",
9+
"file": 1,
10+
"line": 2
11+
},
12+
{
13+
"regexp": "^([ +-].*)$",
14+
"message": 1,
15+
"loop": true
16+
}
17+
]
18+
}
19+
]
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "clang-format",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+):(\\d+):(\\d+):\\s(error|warning|info):\\s(.+)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5
13+
}
14+
]
15+
}
16+
]
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "cmake-lint",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+?):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5
13+
}
14+
]
15+
}
16+
]
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "flake8-error",
5+
"severity": "error",
6+
"pattern": [
7+
{
8+
"regexp": "^([^:]*):(\\d+):(\\d+): ([EF]\\d\\d\\d) (.*)$",
9+
"file": 1,
10+
"line": 2,
11+
"column": 3,
12+
"code": 4,
13+
"message": 5
14+
}
15+
]
16+
},
17+
{
18+
"owner": "flake8-warning",
19+
"severity": "warning",
20+
"pattern": [
21+
{
22+
"regexp": "^([^:]*):(\\d+):(\\d+): ([W]\\d\\d\\d) (.*)$",
23+
"file": 1,
24+
"line": 2,
25+
"column": 3,
26+
"code": 4,
27+
"message": 5
28+
}
29+
]
30+
}
31+
]
32+
}

.github/problem-matchers/gcc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "gcc",
5+
"pattern": [
6+
{
7+
"regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5
13+
}
14+
]
15+
}
16+
]
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "pytest",
5+
"severity": "error",
6+
"pattern": [
7+
{
8+
"regexp": "^(\\S+):(\\d+): (.*)$",
9+
"file": 1,
10+
"line": 2,
11+
"message": 3
12+
}
13+
]
14+
}
15+
]
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "yamllint",
5+
"pattern": [
6+
{
7+
"regexp": "^(.*\\.ya?ml)$",
8+
"file": 1
9+
},
10+
{
11+
"regexp": "^\\s{2}(\\d+):(\\d+)\\s+(error|warning)\\s+(.*?)\\s+\\((.*)\\)$",
12+
"line": 1,
13+
"column": 2,
14+
"severity": 3,
15+
"message": 4,
16+
"code": 5,
17+
"loop": true
18+
}
19+
]
20+
}
21+
]
22+
}

.github/workflows/__call-common-lint.yml

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,52 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@v4
2626

27+
- name: Download problem matchers
28+
shell: bash
29+
working-directory: .github/problem-matchers
30+
run: |
31+
declare -A files=(
32+
[actionlint]="https://raw.githubusercontent.com/rhysd/actionlint/main/.github/actionlint-matcher.json"
33+
[hadolint]="https://raw.githubusercontent.com/actions-marketplace-validations/hadolint_hadolint-action/refs/heads/master/problem-matcher.json"
34+
)
35+
36+
# TODO: add more problem matchers
37+
# clang-format: # https://github.com/jidicula/clang-format-action/issues/137#issuecomment-3043722359
38+
39+
for name in "${!files[@]}"; do
40+
url="${files[$name]}"
41+
curl -sSL "$url" -o "${name}.json"
42+
done
43+
2744
- name: Set up Python
2845
uses: actions/setup-python@v5
2946
with:
3047
python-version: '3.12'
3148

32-
- name: Install dependencies
49+
- name: Install Python dependencies
3350
run: |
51+
# shellcheck disable=SC2102 # this is triggered by the [toolchain] extra
3452
python -m pip install --upgrade \
3553
pip \
3654
setuptools \
3755
wheel \
3856
cmakelang \
3957
flake8 \
4058
nb-clean \
41-
nbqa[toolchain]
59+
nbqa[toolchain] \
60+
yamllint
61+
62+
- name: Install actionlint
63+
id: get_actionlint
64+
shell: bash
65+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
66+
67+
- name: actionlint
68+
shell: bash
69+
run: |
70+
echo "::add-matcher::.github/problem-matchers/actionlint.json"
71+
${{ steps.get_actionlint.outputs.executable }} -color
72+
echo "::remove-matcher owner=actionlint::"
4273
4374
- name: C++ - find files
4475
id: cpp_files
@@ -72,9 +103,10 @@ jobs:
72103
73104
echo "found cpp files: ${found_files}"
74105
75-
# do not quote to keep this as a single line
76-
echo found_files=${found_files} >> $GITHUB_OUTPUT
106+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
107+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
77108
109+
- run: echo "::add-matcher::.github/problem-matchers/clang-format.json"
78110
- name: C++ - Clang format lint
79111
if: always() && steps.cpp_files.outputs.found_files
80112
uses: DoozyX/clang-format-lint-action@v0.20
@@ -84,6 +116,7 @@ jobs:
84116
extensions: 'c,cpp,h,hpp,m,mm'
85117
style: file
86118
inplace: false
119+
- run: echo "::remove-matcher owner=clang-format::"
87120

88121
- name: CMake - find files
89122
id: cmake_files
@@ -111,13 +144,15 @@ jobs:
111144
112145
echo "found cmake files: ${found_files}"
113146
114-
# do not quote to keep this as a single line
115-
echo found_files=${found_files} >> $GITHUB_OUTPUT
147+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
148+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
116149
117150
- name: CMake - cmake-lint
118151
if: always() && steps.cmake_files.outputs.found_files
119152
run: |
153+
echo "::add-matcher::.github/problem-matchers/cmake-lint.json"
120154
cmake-lint --line-width 120 --tab-size 4 ${{ steps.cmake_files.outputs.found_files }}
155+
echo "::remove-matcher owner=cmake-lint::"
121156
122157
- name: Docker - find files
123158
id: docker_files
@@ -127,8 +162,8 @@ jobs:
127162
128163
echo "found_files: ${found_files}"
129164
130-
# do not quote to keep this as a single line
131-
echo found_files=${found_files} >> $GITHUB_OUTPUT
165+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
166+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
132167
133168
- name: Docker - hadolint
134169
if: always() && steps.docker_files.outputs.found_files
@@ -150,18 +185,20 @@ jobs:
150185
failed=0
151186
failed_files=""
152187
188+
echo "::add-matcher::.github/problem-matchers/hadolint.json"
153189
for file in ${{ steps.docker_files.outputs.found_files }}; do
154190
echo "::group::${file}"
155191
docker run --rm -i \
156192
-e "NO_COLOR=0" \
157193
-e "HADOLINT_VERBOSE=1" \
158-
-v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \
194+
-v "$(pwd)"/.hadolint.yaml:/.config/hadolint.yaml \
159195
hadolint/hadolint < $file || {
160196
failed=1
161197
failed_files="$failed_files $file"
162198
}
163199
echo "::endgroup::"
164200
done
201+
echo "::remove-matcher owner=brpaz/hadolint-action::"
165202
166203
if [ $failed -ne 0 ]; then
167204
echo "::error:: hadolint failed for the following files: $failed_files"
@@ -210,17 +247,23 @@ jobs:
210247
- name: Python - flake8
211248
if: always()
212249
run: |
250+
echo "::add-matcher::.github/problem-matchers/flake8.json"
213251
python -m flake8 \
214252
--color=always \
215253
--verbose
254+
echo "::remove-matcher owner=flake8-error::"
255+
echo "::remove-matcher owner=flake8-warning::"
216256
217257
- name: Python - nbqa flake8
218258
if: always()
219259
run: |
260+
echo "::add-matcher::.github/problem-matchers/flake8.json"
220261
python -m nbqa flake8 \
221262
--color=always \
222263
--verbose \
223264
.
265+
echo "::remove-matcher owner=flake8-error::"
266+
echo "::remove-matcher owner=flake8-warning::"
224267
225268
- name: Python - nb-clean
226269
if: always()
@@ -239,21 +282,23 @@ jobs:
239282
run: |
240283
# check if Cargo.toml exists
241284
if [ -f "Cargo.toml" ]; then
242-
echo "found_cargo=true" >> $GITHUB_OUTPUT
285+
echo "found_cargo=true" >> "${GITHUB_OUTPUT}"
243286
else
244-
echo "found_cargo=false" >> $GITHUB_OUTPUT
287+
echo "found_cargo=false" >> "${GITHUB_OUTPUT}"
245288
fi
246289
247290
- name: Setup Rust
248291
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
249292
with:
250-
target: ${{ matrix.target }}
251293
components: 'rustfmt'
252294
cache: false
253295

254296
- name: Rust - cargo fmt
255297
if: always() && steps.run_cargo.outputs.found_cargo == 'true'
256-
run: cargo fmt -- --check
298+
run: |
299+
echo "::add-matcher::.github/problem-matchers/cargo-fmt.json"
300+
cargo fmt -- --check
301+
echo "::remove-matcher owner=cargo-fmt::"
257302
258303
- name: YAML - find files
259304
id: yaml_files
@@ -272,35 +317,17 @@ jobs:
272317
fi
273318
done
274319
275-
echo "found_files=${found_files}" >> $GITHUB_OUTPUT
320+
echo "found_files=${found_files}" >> "${GITHUB_OUTPUT}"
276321
277322
- name: YAML - yamllint
278323
id: yamllint
279324
if: always()
280-
uses: ibiqlik/action-yamllint@v3
281-
with:
282-
# https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration
283-
config_data: |
284-
extends: default
285-
rules:
286-
comments:
287-
level: error
288-
document-start:
289-
level: error
290-
line-length:
291-
max: 120
292-
new-line-at-end-of-file:
293-
level: error
294-
new-lines:
295-
type: unix
296-
truthy:
297-
# GitHub uses "on" for workflow event triggers
298-
# .clang-format file has options of "Yes" "No" that will be caught by this, so changed to "warning"
299-
allowed-values: ['true', 'false', 'on']
300-
check-keys: true
301-
level: warning
302-
file_or_dir: . ${{ steps.yaml_files.outputs.found_files }}
303-
304-
- name: YAML - log
305-
if: always() && steps.yamllint.outcome == 'failure'
306-
run: cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY
325+
run: |
326+
if [ ! -f .yamllint.yml ]; then
327+
curl -sSL https://raw.githubusercontent.com/LizardByte/.github/master/.yamllint.yml -o .yamllint.yml
328+
fi
329+
330+
echo "::add-matcher::.github/problem-matchers/yamllint.json"
331+
yamllint -c .yamllint.yml . ${{ steps.yaml_files.outputs.found_files }}
332+
333+
echo "::remove-matcher owner=yamllint::"

0 commit comments

Comments
 (0)