continuous-integrationgithub-actionsflake8linter

exclude migrations files from flake8 and black in github actions


I am looking for an approach to exclude django migration files from black and flake8 in github-actions.

Here's what I've done so far:

[flake8]
exclude = 
    */migrations/*
max-complexity = 10
max-line-length = 127
  linting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: psf/black@stable
      - name: Install dependencies
        run: pip install flake8
      - name: Lint with flake8
        run: |
          # stop the build if there are Python syntax errors or undefined names
          flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
          # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
          flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

[UPDATE]:

Out:

6s
Run psf/black@stable
  with:
    options: --check --diff
    src: .
    jupyter: false
Run if [ "$RUNNER_OS" == "Windows" ]; then
  if [ "$RUNNER_OS" == "Windows" ]; then
    python $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
  else
    python3 $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
  fi
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_OPTIONS: --check --diff
    INPUT_SRC: .
    INPUT_JUPYTER: false
    INPUT_BLACK_ARGS: 
    INPUT_VERSION: 
    pythonioencoding: utf-8
Installing black[colorama]==23.7.0...
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0001_initial.py  2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0001_initial.py  2023-09-10 16:56:29.804008+00:00
@@ -2,11 +2,10 @@
 
 from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
-
     initial = True
 
     dependencies = []
 
     operations = [
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0001_initial.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0002_alter_content_text.py   2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0002_alter_content_text.py   2023-09-10 16:56:29.804642+00:00
@@ -2,11 +2,10 @@
 
 from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("contents", "0001_initial"),
     ]
 
     operations = [
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/contents/migrations/0002_alter_content_text.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0002_alter_rating_content.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0002_alter_rating_content.py 2023-09-10 16:56:29.841362+00:00
@@ -3,11 +3,10 @@
 from django.db import migrations, models
 import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("contents", "0001_initial"),
         ("star_ratings", "0001_initial"),
     ]
 
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0002_alter_rating_content.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0003_alter_rating_content.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0003_alter_rating_content.py 2023-09-10 16:56:29.855460+00:00
@@ -3,11 +3,10 @@
 from django.db import migrations, models
 import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("contents", "0001_initial"),
         ("star_ratings", "0002_alter_rating_content"),
     ]
 
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0003_alter_rating_content.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0001_initial.py  2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0001_initial.py  2023-09-10 16:56:29.868224+00:00
@@ -5,11 +5,10 @@
 from django.db import migrations, models
 import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
-
     initial = True
 
     dependencies = [
         ("contents", "0001_initial"),
         migrations.swappable_dependency(settings.AUTH_USER_MODEL),
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0001_initial.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0004_alter_userrating_score.py   2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0004_alter_userrating_score.py   2023-09-10 16:56:29.869773+00:00
@@ -3,11 +3,10 @@
 import django.core.validators
 from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("star_ratings", "0003_alter_rating_content"),
     ]
 
     operations = [
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0004_alter_userrating_score.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0005_alter_rating_content.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0005_alter_rating_content.py 2023-09-10 16:56:29.880033+00:00
@@ -4,11 +4,10 @@
 import django.db.models.deletion
 import django.utils.timezone
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("contents", "0002_alter_content_text"),
         ("star_ratings", "0004_alter_userrating_score"),
     ]
 
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/star_ratings/migrations/0005_alter_rating_content.py
--- /home/runner/work/bitpin-project/bitpin-project/bitpin/users/migrations/0001_initial.py 2023-09-10 16:56:24.096492+00:00
+++ /home/runner/work/bitpin-project/bitpin-project/bitpin/users/migrations/0001_initial.py 2023-09-10 16:56:29.973121+00:00
@@ -5,11 +5,10 @@
 from django.db import migrations, models
 import django.utils.timezone
 
 
 class Migration(migrations.Migration):
-
     initial = True
 
     dependencies = [
         ("auth", "0012_alter_user_first_name_max_length"),
     ]
would reformat /home/runner/work/bitpin-project/bitpin-project/bitpin/users/migrations/0001_initial.py

Oh no! 💥 💔 💥
8 files would be reformatted, 35 files would be left unchanged.

Error: Process completed with exit code 1.

Solution

  • Eventually I overcame the problem. Actually, the issue was not related to the flake8 it was related to the black linter by the following line:

    - uses: psf/black@stable

    So to tackle this issue (excluding migration files) I created a pyproject.toml in the project root with the following content:

    [tool.black]
    exclude = '''
    (
      /(
          \.git
        | \.hg
        | \.mypy_cache
        | \.tox
        | \.venv
        | _build
        | buck-out
        | build
        | dist
      )/
    | migrations
    )
    '''