Add: first version of a flake8 checker with annotation (#1)

This uses a ProblemMatcher together with GitHub Actions 'add-matcher'.
To allow warnings/errors to show up correctly, a 'sed' is used to handled that correctly.
This commit is contained in:
Patric Stout
2019-10-30 16:22:43 +01:00
committed by GitHub
parent f891d3601a
commit e05d0c65cb
9 changed files with 118 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
name: Testing
on: [pull_request]
jobs:
run_action:
name: Test run action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
with:
path: example
only_warn: 1
+13
View File
@@ -0,0 +1,13 @@
FROM python:3.8-alpine
COPY LICENSE \
README.md \
entrypoint.sh \
flake8-matcher.json \
requirements.txt \
/code/
RUN pip install -r /code/requirements.txt
ENTRYPOINT ["/code/entrypoint.sh"]
CMD []
+21
View File
@@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2019, Patric "TrueBrain" Stout
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+10
View File
@@ -0,0 +1,10 @@
# Flake8 with GitHub Actions -- including annotations for Pull Requests
This GitHub Actions runs flake8 over your code.
Any warnings or errors will be annoted in the Pull Request.
## Example usages
```
uses: TrueBrain/actions-flake8@master
```
+14
View File
@@ -0,0 +1,14 @@
name: 'Flake8'
description: 'Flake8 with annotations for Pull Request'
inputs:
path:
description: 'Path to run flake8 in'
requred: false
default: ''
only_warn:
description: 'If set, only warn, never error'
requred: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
Executable
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
# Copy the matcher to the host system; otherwise "add-matcher" can't find it.
cp /code/flake8-matcher.json /github/workflow/flake8-matcher.json
echo "::add-matcher::${RUNNER_TEMP}/_github_workflow/flake8-matcher.json"
# Run flake8. We add 'error/warning' as GitHub Actions ProblemMatcher needs
# the text 'error/warning' to know how to classify it.
# The weird piping is needed because we want to get the exitcode from flake8,
# but there is no other good universal way of doing so.
# e.g. PIPESTATUS and pipestatus only work in bash/zsh respectively.
exec 5>&1
res=`{ { flake8 ${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`
# Remove the matcher, so no other jobs hit it.
echo "::remove-matcher owner=flake8::"
# If we are in warn-only mode, return always as if we pass
if [ -n "${INPUT_ONLY_WARN}" ]; then
exit 0
else
exit $res
fi
+5
View File
@@ -0,0 +1,5 @@
def test():
pass
def test() :
pass
+17
View File
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "flake8",
"pattern": [
{
"regexp": "^([^:]*):(\\d+):(\\d+): (error|warning): (\\w\\d\\d\\d) (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 6
}
]
}
]
}
+1
View File
@@ -0,0 +1 @@
flake8==3.7.9