Skip to content

Lint PR Check Workflow

This workflow enforces code quality standards by running the Ruff linter on every Pull Request. It ensures that no code violations are merged into the main codebase.

Workflow Configuration

View Workflow Configuration
name: Lint pr check
on:
  pull_request:
    branches:
      - main
      - Milestone-*
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.12
        uses: actions/setup-python@v3
        with:
          python-version: "3.12"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install ruff
      - name: Analysing the code with ruff
        run: ruff check turing/ --output-format=github .

Detailed Explanation

1. Triggers (on)

This automation starts exclusively on Pull Requests targeting specific branches.

  • main: The production branch.

  • Milestone-*: Any feature or release branch matching this pattern (e.g., Milestone-1).

Why only Pull Requests?

Running lint checks on PRs is a best practice. It catches errors before the code is merged, keeping the main branch clean and runnable at all times.

2. The Build Job

The job runs on a fresh Ubuntu Linux container for every check.

Step-by-Step Breakdown:

  1. Checkout Code: Uses actions/checkout@v4 to download a copy of the repository code so the linter can read it.

  2. Setup Python: Installs Python 3.12.

  3. Install Dependencies: Updates pip and installs Ruff

  4. Run Analysis: Executes the lint check:

    ruff check turing/ --output-format=github .
  • turing/: Specifies the specific directory to analyze.
  • .: Ensures the current directory is the root.
  • --output-format=github: This formats the error messages so they appear directly in the "Files Changed" tab of the Pull Request interface as annotations, rather than just in the raw log.

Troubleshooting

If this check fails, you will see an error in your Pull Request status.

To fix local linting errors: Run the following command in your terminal before pushing:

# Fix auto-fixable errors
ruff check turing/ --fix