Skip to content

Commit 28db96f

Browse files
committed
Fix #10: use the "severity" field in matchers
This removes the ugly "sed" hack needed to make flake8 work.
1 parent 5a412a2 commit 28db96f

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

entrypoint.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
#!/bin/sh
22

3-
# Copy the matcher to the host system; otherwise "add-matcher" can't find it.
4-
cp /code/flake8-matcher.json /github/workflow/flake8-matcher.json
5-
echo "::add-matcher::${RUNNER_TEMP}/_github_workflow/flake8-matcher.json"
3+
# Copy the matcher to a shared volume with the host; otherwise "add-matcher"
4+
# can't find it.
5+
cp /code/flake8-matcher.json ${HOME}/
6+
echo "::add-matcher::${HOME}/flake8-matcher.json"
67

7-
# Run flake8. We add 'error/warning' as GitHub Actions ProblemMatcher needs
8-
# the text 'error/warning' to know how to classify it.
9-
# The weird piping is needed because we want to get the exitcode from flake8,
10-
# but there is no other good universal way of doing so.
11-
# e.g. PIPESTATUS and pipestatus only work in bash/zsh respectively.
12-
echo "Running flake8 on '${INPUT_PATH}' with the following options..."
8+
# Create the flake8 arguments
9+
echo "Running flake8 on '${INPUT_PATH}' with the following options:"
1310
command_args=""
14-
echo "Ignoring '${INPUT_IGNORE}'"
15-
if [ "x${INPUT_IGNORE}" != "x" ]; then
11+
echo " - ignoring: '${INPUT_IGNORE}'"
12+
if [ "x${INPUT_IGNORE}" != "x" ]; then
1613
command_args="${command_args} --ignore ${INPUT_IGNORE}"
1714
fi
18-
echo "Max line length '${INPUT_MAX_LINE_LENGTH}'"
19-
if [ "x${INPUT_MAX_LINE_LENGTH}" != "x" ]; then
15+
echo " - nax line length: '${INPUT_MAX_LINE_LENGTH}'"
16+
if [ "x${INPUT_MAX_LINE_LENGTH}" != "x" ]; then
2017
command_args="${command_args} --max-line-length ${INPUT_MAX_LINE_LENGTH}"
2118
fi
22-
echo "Resulting CLI options ${command_args}"
23-
exec 5>&1
24-
res=`{ { flake8 ${command_args} ${INPUT_PATH}; echo $? 1>&4; } | sed -r 's/: ([^W][0-9][0-9][0-9])/: error: \1/;s/: (W[0-9][0-9][0-9])/: warning: \1/' 1>&5; } 4>&1`
25-
if [ "$res" = "0" ]; then
19+
echo " - path: '${INPUT_PATH}'"
20+
command_args="${command_args} ${INPUT_PATH}"
21+
echo "Resulting command: flake8 ${command_args}"
22+
23+
# Run flake8
24+
flake8 ${command_args}
25+
if [ "$?" = "0" ]; then
2626
echo "Flake8 found no problems"
2727
else
2828
echo "Flake8 found one or more problems"
2929
fi
3030

3131
# Remove the matcher, so no other jobs hit it.
32-
echo "::remove-matcher owner=flake8::"
32+
echo "::remove-matcher owner=flake8-error::"
33+
echo "::remove-matcher owner=flake8-warning::"
3334

3435
# If we are in warn-only mode, return always as if we pass
3536
if [ -n "${INPUT_ONLY_WARN}" ]; then

flake8-matcher.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
{
22
"problemMatcher": [
33
{
4-
"owner": "flake8",
4+
"owner": "flake8-error",
5+
"severity": "error",
56
"pattern": [
67
{
7-
"regexp": "^([^:]*):(\\d+):(\\d+): (error|warning): (\\w\\d\\d\\d) (.*)$",
8+
"regexp": "^([^:]*):(\\d+):(\\d+): ([EF]\\d\\d\\d) (.*)$",
89
"file": 1,
910
"line": 2,
1011
"column": 3,
11-
"severity": 4,
12-
"message": 6
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
1328
}
1429
]
1530
}

0 commit comments

Comments
 (0)