Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 52 additions & 19 deletions .github/workflows/code-quality-check.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Python Code Quality Check
name: Python Check

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**.py'
Comment thread
varundhall marked this conversation as resolved.

jobs:
lint:
code-quality-check:
name: Code Quality
runs-on: ubuntu-latest

steps:
Expand All @@ -15,11 +17,32 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'

- name: Install dependencies
run: |
pip install flake8
pip install flake8 black

- name: Run black and generate diff
id: black_check
run: |
echo "Running black in check mode with diff output..."
black --check --diff --line-length 99 . > formatting.diff || true

if [ -s formatting.diff ]; then
echo "Formatting issues detected:"
cat formatting.diff
echo "black_failed=true" >> $GITHUB_OUTPUT
else
echo "No formatting issues found."
Comment thread
varundhall marked this conversation as resolved.
fi

- name: Upload formatting.diff
if: steps.black_check.outputs.black_failed == 'true'
uses: actions/upload-artifact@v4
with:
name: python-formatting-diff
path: formatting.diff

- name: Detect changed Python files
id: detect_changes
Expand All @@ -42,7 +65,6 @@ jobs:
fi

- name: Run Flake8 on changed files
if: env.SKIP != 'true'
run: |
echo "Running flake8 on: $CHANGED"
flake8 $CHANGED > flake8_output.txt || true
Comment on lines 67 to 70

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable $CHANGED is referenced but no longer defined since the detection logic was removed. This will result in an empty or undefined variable being passed to flake8.

Copilot uses AI. Check for mistakes.
Comment on lines 67 to 70

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable $CHANGED is undefined since the file detection logic was removed, causing flake8 to run without any target files specified, which may not behave as expected.

Copilot uses AI. Check for mistakes.
Comment thread
varundhall marked this conversation as resolved.
Expand All @@ -53,12 +75,8 @@ jobs:
import os

try:
skip = os.getenv("SKIP") == "true"
if skip:
lines = []
else:
with open("flake8_output.txt") as f:
lines = f.read().splitlines()
with open("flake8_output.txt") as f:
lines = f.read().splitlines()

except FileNotFoundError:
lines = []
Expand Down Expand Up @@ -86,7 +104,7 @@ jobs:
EOF

- name: Upload full report
if: env.SKIP != 'true' && env.FLAKE8_ISSUE_PRESENT == 'true'
if: env.FLAKE8_ISSUE_PRESENT == 'true'
uses: actions/upload-artifact@v4
with:
name: python-code-quality-report
Expand All @@ -108,10 +126,25 @@ jobs:
body-path: flake8_summary.md
edit-mode: replace

- name: Fail if Flake8 issues found
if: env.SKIP != 'true'
- name: Fail if both black and flake8 failed
if: steps.black_check.outputs.black_failed == 'true' && env.FLAKE8_ISSUE_PRESENT == 'true'
run: |
if [ "$FLAKE8_ISSUE_PRESENT" == "true" ]; then
echo "❌ Issues detected in Python files. Please fix them before merging."
exit 1
fi
echo "Python formatting check failed. See formatting.diff artifact for details."
echo "To fix the error(s) run the command below from the root of the repo and commit the changes:"
echo "./scripts/fix-python-formatting.sh"
echo "We also detected Linting Issues in Python files. Please fix them before merging."
exit 1

- name: Fail if only black failed
if: steps.black_check.outputs.black_failed == 'true' && env.FLAKE8_ISSUE_PRESENT != 'true'
run: |
echo "Python formatting check failed. See formatting.diff artifact for details."
echo "To fix the error(s) run the command below from the root of the repo and commit the changes:"
echo "./scripts/fix-python-formatting.sh"
exit 1

- name: Fail if only flake8 failed
if: steps.black_check.outputs.black_failed != 'true' && env.FLAKE8_ISSUE_PRESENT == 'true'
run: |
echo "❌ Issues detected in Python files. Please fix them before merging."
exit 1
Comment thread
varundhall marked this conversation as resolved.
3 changes: 2 additions & 1 deletion .github/workflows/enforce-readme-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ jobs:
'.circleci',
'.devops',
'ci',
'.ci'
'.ci',
'scripts'
];

// Get all files changed in this PR
Expand Down
31 changes: 31 additions & 0 deletions scripts/fix-python-formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -euo pipefail

echo "Checking if 'black' is installed..."
if ! command -v black &> /dev/null; then
echo "Installing black via pip..."
if command -v pip3 &> /dev/null; then
pip3 install --user black
export PATH="$HOME/.local/bin:$PATH"
elif command -v pip &> /dev/null; then
pip install --user black
export PATH="$HOME/.local/bin:$PATH"
else
echo "pip not found. Please install pip to continue."
exit 1
fi
fi

echo "Finding all Python files..."
py_files=$(find . -type f -name '*.py')

if [ -z "$py_files" ]; then
echo "No Python files found to format."
exit 0
fi

echo "Formatting all Python files with black (line length = 99)..."
black --line-length 99 $py_files

Comment thread
varundhall marked this conversation as resolved.
echo "All Python files are now formatted!"