From 8eaa3ef2ea7fd4a5eabbaa0d1e8002517414867d Mon Sep 17 00:00:00 2001 From: Andreas Kluge Svendsrud Date: Fri, 20 Sep 2024 22:54:00 +0200 Subject: [PATCH 1/3] refactor: update python linter to always run after formatter --- .github/workflows/black-formatter.yml | 6 +++++- .github/workflows/flake8-linter.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/black-formatter.yml b/.github/workflows/black-formatter.yml index a76ccd77..0e906400 100644 --- a/.github/workflows/black-formatter.yml +++ b/.github/workflows/black-formatter.yml @@ -1,4 +1,4 @@ -name: Python-formatter +name: Python formatter on: [push, pull_request] @@ -27,3 +27,7 @@ jobs: message: 'Committing Black formatter changes' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Optional: Add a workflow output so the next workflow knows if formatting changes were made + outputs: + formatted: ${{ steps.action_black.outputs.is_formatted }} \ No newline at end of file diff --git a/.github/workflows/flake8-linter.yml b/.github/workflows/flake8-linter.yml index f3e18fd3..bbad3225 100644 --- a/.github/workflows/flake8-linter.yml +++ b/.github/workflows/flake8-linter.yml @@ -1,6 +1,10 @@ name: Python Linter -on: [push, pull_request] +on: + workflow_run: + workflows: ["Python formatter"] + types: + - completed jobs: lint: From ec2070aa7db5dbf715871446ca19a2c8f00bf8cd Mon Sep 17 00:00:00 2001 From: Andreas Kluge Svendsrud Date: Sun, 22 Sep 2024 06:53:35 +0200 Subject: [PATCH 2/3] ci(format): adjust triggers and remove unused outputs --- .github/workflows/black-formatter.yml | 14 ++++++++------ .github/workflows/flake8-linter.yml | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/black-formatter.yml b/.github/workflows/black-formatter.yml index 0e906400..61be86d5 100644 --- a/.github/workflows/black-formatter.yml +++ b/.github/workflows/black-formatter.yml @@ -1,6 +1,12 @@ name: Python formatter -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: + branches: + - '*' jobs: linter_name: @@ -26,8 +32,4 @@ jobs: author_email: black-formatter@example.com message: 'Committing Black formatter changes' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Optional: Add a workflow output so the next workflow knows if formatting changes were made - outputs: - formatted: ${{ steps.action_black.outputs.is_formatted }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/flake8-linter.yml b/.github/workflows/flake8-linter.yml index bbad3225..324ba416 100644 --- a/.github/workflows/flake8-linter.yml +++ b/.github/workflows/flake8-linter.yml @@ -2,9 +2,9 @@ name: Python Linter on: workflow_run: - workflows: ["Python formatter"] + workflows: ["Python formatter"] # Run only after the 'Python Formatter' workflow completes types: - - completed + - completed # Trigger when the formatter workflow finishes jobs: lint: @@ -13,13 +13,13 @@ jobs: steps: # Step 1: Check out the current repository so that the files are available to the workflow - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - # Step 2: Set up Python version 3.8 for the workflow environment - - name: Set up Python 3.8 + # 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.8 + python-version: 3.x # Step 3: Install `flake8`, a Python linter, by upgrading pip and then installing `flake8` - name: Install flake8 From 0d4dbafb46d529aa296310941661faadb18dbf2f Mon Sep 17 00:00:00 2001 From: Sondre Haugen Date: Sun, 22 Sep 2024 11:37:17 +0200 Subject: [PATCH 3/3] 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