Search code examples
pythongithubcontinuous-integrationgithub-actionsflake8

GitHub actions flake8 Lint failing upon commit "failed with exit code 1"


I have a repo on GitHub where I have included my.yaml file for a github actions configuration as below:

name: flake8 Lint

on: [push, pull_request]

jobs:
  flake8-lint:
    runs-on: ubuntu-latest
    name: Lint
    steps:
      - name: Check out source repository
        uses: actions/checkout@v2
      - name: Set up Python environment
        uses: actions/setup-python@v1
        with:
          python-version: "3.8"
      - name: flake8 Lint
        uses: py-actions/flake8@v2
        with:
          max-line-length: "100"
          path: "app"

This file was working perfectly fine and passing upon commits, however, I recently added some more code in my app folder (flask app code) and now it is failing and giving the error as shown below:

Run py-actions/flake8@v2
[*] Installing flake8 package @ latest...
/opt/hostedtoolcache/Python/3.8.12/x64/bin/python -m pip install --upgrade flake8
Collecting flake8
  Downloading flake8-4.0.1-py2.py3-none-any.whl (64 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.1/64.1 KB 14.6 MB/s eta 0:00:00
Collecting pyflakes<2.5.0,>=2.4.0
  Downloading pyflakes-2.4.0-py2.py3-none-any.whl (69 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 69.7/69.7 KB 18.3 MB/s eta 0:00:00
Collecting mccabe<0.7.0,>=0.6.0
  Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
Collecting pycodestyle<2.9.0,>=2.8.0
  Downloading pycodestyle-2.8.0-py2.py3-none-any.whl (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.1/42.1 KB 10.8 MB/s eta 0:00:00
Installing collected packages: mccabe, pyflakes, pycodestyle, flake8
Successfully installed flake8-4.0.1 mccabe-0.6.1 pycodestyle-2.8.0 pyflakes-2.4.0
WARNING: You are using pip version 22.0.3; however, version 22.0.4 is available.
You should consider upgrading via the '/opt/hostedtoolcache/Python/3.8.12/x64/bin/python -m pip install --upgrade pip' command.
[*] Installed flake8 package version:
/opt/hostedtoolcache/Python/3.8.12/x64/bin/flake8 --version
4.0.1 (mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.8.12 on
Linux
/opt/hostedtoolcache/Python/3.8.12/x64/bin/flake8 --max-line-length 100 app
app/__init__.py:5:1: W293 blank line contains whitespace
app/__init__.py:6:1: E302 expected 2 blank lines, found 1
app/__init__.py:6:28: E251 unexpected spaces around keyword / parameter equals
app/__init__.py:6:30: E251 unexpected spaces around keyword / parameter equals
app/__init__.py:9:1: W293 blank line contains whitespace
app/__init__.py:12:1: W293 blank line contains whitespace
app/__init__.py:15:1: W293 blank line contains whitespace
app/config.py:7:1: E302 expected 2 blank lines, found 1
app/main/routes.py:1:1: F401 'flask.Flask' imported but unused
app/main/routes.py:1:1: F401 'flask.url_for' imported but unused
app/main/routes.py:1:1: F401 'flask.redirect' imported but unused
app/main/routes.py:1:1: F401 'flask.request' imported but unused
app/main/routes.py:4:1: W293 blank line contains whitespace
app/main/routes.py:6:1: E302 expected 2 blank lines, found 1
app/main/routes.py:6:32: E231 missing whitespace after ','
app/main/routes.py:8:1: W293 blank line contains whitespace
app/main/routes.py:9:41: W292 no newline at end of file
Error: The process '/opt/hostedtoolcache/Python/3.8.12/x64/bin/flake8' failed with exit code 1

I have files in my app folder that aren't .py, could that be the issue that causes the failure of the github actions flake8 tests, if so how can I ignore the other files?


Solution

  • Your issue appears to be that your code doesn't pass PEP8, which the Flake8 check will fail if you don't (that's the point of it). Note that the Flake8 check does not reformat files, it only tells you they are wrong! The error log will tell you the individual error code (such as W293 blank line contains whitespace)