Skip to content

Commit 5324304

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

14 files changed

Lines changed: 266 additions & 80 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",
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",
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: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,31 @@ 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 \
@@ -40,6 +58,18 @@ jobs:
4058
nb-clean \
4159
nbqa[toolchain]
4260
61+
- name: Install actionlint
62+
id: get_actionlint
63+
shell: bash
64+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
65+
66+
- name: actionlint
67+
shell: bash
68+
run: |
69+
echo "::add-matcher::.github/problem-matchers/actionlint.json"
70+
${{ steps.get_actionlint.outputs.executable }} -color
71+
echo "::remove-matcher owner=actionlint::"
72+
4373
- name: C++ - find files
4474
id: cpp_files
4575
run: |
@@ -72,9 +102,10 @@ jobs:
72102
73103
echo "found cpp files: ${found_files}"
74104
75-
# do not quote to keep this as a single line
76-
echo found_files=${found_files} >> $GITHUB_OUTPUT
105+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
106+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
77107
108+
- run: echo "::add-matcher::.github/problem-matchers/clang-format.json"
78109
- name: C++ - Clang format lint
79110
if: always() && steps.cpp_files.outputs.found_files
80111
uses: DoozyX/clang-format-lint-action@v0.20
@@ -84,6 +115,7 @@ jobs:
84115
extensions: 'c,cpp,h,hpp,m,mm'
85116
style: file
86117
inplace: false
118+
- run: echo "::remove-matcher owner=clang-format::"
87119

88120
- name: CMake - find files
89121
id: cmake_files
@@ -111,13 +143,15 @@ jobs:
111143
112144
echo "found cmake files: ${found_files}"
113145
114-
# do not quote to keep this as a single line
115-
echo found_files=${found_files} >> $GITHUB_OUTPUT
146+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
147+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
116148
117149
- name: CMake - cmake-lint
118150
if: always() && steps.cmake_files.outputs.found_files
119151
run: |
152+
echo "::add-matcher::.github/problem-matchers/cmake-lint.json"
120153
cmake-lint --line-width 120 --tab-size 4 ${{ steps.cmake_files.outputs.found_files }}
154+
echo "::remove-matcher owner=cmake-lint::"
121155
122156
- name: Docker - find files
123157
id: docker_files
@@ -127,8 +161,8 @@ jobs:
127161
128162
echo "found_files: ${found_files}"
129163
130-
# do not quote to keep this as a single line
131-
echo found_files=${found_files} >> $GITHUB_OUTPUT
164+
# shellcheck disable=SC2086 # do not quote to keep this as a single line
165+
echo found_files=${found_files} >> "${GITHUB_OUTPUT}"
132166
133167
- name: Docker - hadolint
134168
if: always() && steps.docker_files.outputs.found_files
@@ -150,18 +184,20 @@ jobs:
150184
failed=0
151185
failed_files=""
152186
187+
echo "::add-matcher::.github/problem-matchers/hadolint.json"
153188
for file in ${{ steps.docker_files.outputs.found_files }}; do
154189
echo "::group::${file}"
155190
docker run --rm -i \
156191
-e "NO_COLOR=0" \
157192
-e "HADOLINT_VERBOSE=1" \
158-
-v $(pwd)/.hadolint.yaml:/.config/hadolint.yaml \
193+
-v "$(pwd)"/.hadolint.yaml:/.config/hadolint.yaml \
159194
hadolint/hadolint < $file || {
160195
failed=1
161196
failed_files="$failed_files $file"
162197
}
163198
echo "::endgroup::"
164199
done
200+
echo "::remove-matcher owner=brpaz/hadolint-action::"
165201
166202
if [ $failed -ne 0 ]; then
167203
echo "::error:: hadolint failed for the following files: $failed_files"
@@ -210,17 +246,21 @@ jobs:
210246
- name: Python - flake8
211247
if: always()
212248
run: |
249+
echo "::add-matcher::.github/problem-matchers/flake8.json"
213250
python -m flake8 \
214251
--color=always \
215252
--verbose
253+
echo "::remove-matcher owner=flake8::"
216254
217255
- name: Python - nbqa flake8
218256
if: always()
219257
run: |
258+
echo "::add-matcher::.github/problem-matchers/flake8.json"
220259
python -m nbqa flake8 \
221260
--color=always \
222261
--verbose \
223262
.
263+
echo "::remove-matcher owner=flake8::"
224264
225265
- name: Python - nb-clean
226266
if: always()
@@ -239,21 +279,23 @@ jobs:
239279
run: |
240280
# check if Cargo.toml exists
241281
if [ -f "Cargo.toml" ]; then
242-
echo "found_cargo=true" >> $GITHUB_OUTPUT
282+
echo "found_cargo=true" >> "${GITHUB_OUTPUT}"
243283
else
244-
echo "found_cargo=false" >> $GITHUB_OUTPUT
284+
echo "found_cargo=false" >> "${GITHUB_OUTPUT}"
245285
fi
246286
247287
- name: Setup Rust
248288
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
249289
with:
250-
target: ${{ matrix.target }}
251290
components: 'rustfmt'
252291
cache: false
253292

254293
- name: Rust - cargo fmt
255294
if: always() && steps.run_cargo.outputs.found_cargo == 'true'
256-
run: cargo fmt -- --check
295+
run: |
296+
echo "::add-matcher::.github/problem-matchers/cargo-fmt.json"
297+
cargo fmt -- --check
298+
echo "::remove-matcher owner=cargo-fmt::"
257299
258300
- name: YAML - find files
259301
id: yaml_files
@@ -272,7 +314,7 @@ jobs:
272314
fi
273315
done
274316
275-
echo "found_files=${found_files}" >> $GITHUB_OUTPUT
317+
echo "found_files=${found_files}" >> "${GITHUB_OUTPUT}"
276318
277319
- name: YAML - yamllint
278320
id: yamllint
@@ -303,4 +345,8 @@ jobs:
303345

304346
- name: YAML - log
305347
if: always() && steps.yamllint.outcome == 'failure'
306-
run: cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY
348+
run: |
349+
echo "::add-matcher::.github/problem-matchers/yamllint.json"
350+
cat "${{ steps.yamllint.outputs.logfile }}" >> "${GITHUB_STEP_SUMMARY}"
351+
352+
echo "::remove-matcher owner=yamllint::"

0 commit comments

Comments
 (0)