From 0d4dbafb46d529aa296310941661faadb18dbf2f Mon Sep 17 00:00:00 2001 From: Sondre Haugen Date: Sun, 22 Sep 2024 11:37:17 +0200 Subject: [PATCH] refactor: formatter and linter in one workflow --- .github/workflows/black-formatter.yml | 40 ++++++++++++++++++++--- .github/workflows/flake8-linter.yml | 47 --------------------------- 2 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 .github/workflows/flake8-linter.yml diff --git a/.github/workflows/black-formatter.yml b/.github/workflows/black-formatter.yml index 61be86d5..ce2ad370 100644 --- a/.github/workflows/black-formatter.yml +++ b/.github/workflows/black-formatter.yml @@ -1,4 +1,4 @@ -name: Python formatter +name: Python formatter and linter on: push: @@ -6,10 +6,10 @@ on: - main pull_request: branches: - - '*' + - '**' jobs: - linter_name: + formatter: name: runner / black runs-on: ubuntu-latest steps: @@ -32,4 +32,36 @@ jobs: author_email: black-formatter@example.com message: 'Committing Black formatter changes' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + lint: + name: runner / flake8 + runs-on: ubuntu-latest + needs: formatter + steps: + # Step 1: Check out the current repository so that the files are available to the workflow + - uses: actions/checkout@v4 + + # Step 2: Install `flake8` + - name: Install flake8 + run: | + pip install flake8 # Install flake8 linter + + # Step 3: Set up flake8 annotations (this is optional, to annotate lint issues in the pull request) + - name: Setup flake8 annotations + uses: rbialon/flake8-annotations@v1 + + # Step 4: Run flake8 linter with two sets of rules + - name: Lint with flake8 + run: | + # First run: Focus on catching critical errors related to syntax and undefined names + # This command checks for Python syntax errors (E9) and issues related to undefined names (F63, F7, F82) + # The build will stop and fail if any of these critical errors are found. + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + + # Second run: Check for general linting issues but ignore some rules + # --ignore=C901: Ignore complexity-related issues + # --ignore=W503: Ignore line break before binary operator + # --ignore=E203: Ignore whitespace before ':' + # This will fail the build if there are other linting issues, except the ignored ones. + flake8 . --count --max-complexity=10 --max-line-length=150 --ignore=C901,W503,E203 --statistics diff --git a/.github/workflows/flake8-linter.yml b/.github/workflows/flake8-linter.yml deleted file mode 100644 index 324ba416..00000000 --- a/.github/workflows/flake8-linter.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Python Linter - -on: - workflow_run: - workflows: ["Python formatter"] # Run only after the 'Python Formatter' workflow completes - types: - - completed # Trigger when the formatter workflow finishes - -jobs: - lint: - - runs-on: ubuntu-latest - - steps: - # Step 1: Check out the current repository so that the files are available to the workflow - - uses: actions/checkout@v4 - - # Step 2: Set up Python version 3.x for the workflow environment - - name: Set up Python 3.x - uses: actions/setup-python@v1 - with: - python-version: 3.x - - # Step 3: Install `flake8`, a Python linter, by upgrading pip and then installing `flake8` - - name: Install flake8 - run: | - python -m pip install --upgrade pip # Upgrade pip to the latest version - pip install flake8 # Install flake8 linter - - # Step 4: Set up flake8 annotations (this is optional, to annotate lint issues in the pull request) - - name: Setup flake8 annotations - uses: rbialon/flake8-annotations@v1 - - # Step 5: Run flake8 linter with two sets of rules - - name: Lint with flake8 - run: | - # First run: Focus on catching critical errors related to syntax and undefined names - # This command checks for Python syntax errors (E9) and issues related to undefined names (F63, F7, F82) - # The build will stop and fail if any of these critical errors are found. - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - - # Second run: Check for general linting issues but ignore some rules - # --ignore=C901: Ignore complexity-related issues - # --ignore=W503: Ignore line break before binary operator - # --ignore=E203: Ignore whitespace before ':' - # This will fail the build if there are other linting issues, except the ignored ones. - flake8 . --count --max-complexity=10 --max-line-length=150 --ignore=C901,W503,E203 --statistics