name: Lint & Type Check on: push: branches: [ 'main' ] pull_request: branches: [ '*' ] workflow_dispatch: jobs: lint: name: Run Linters runs-on: ubuntu-latest permissions: pull-requests: write contents: read defaults: run: working-directory: backend steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' - name: Cache pip dependencies uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('backend/pyproject.toml') }} restore-keys: | ${{ runner.os }}-pip- - name: Install dependencies run: | python -m pip install --upgrade pip pip install -e ".[dev]" - name: Run pylint id: pylint run: | echo "Running pylint..." if pylint . > pylint-output.txt 2>&1; then echo "PYLINT_PASSED=true" >> $GITHUB_ENV echo "✅ No pylint errors found!" else echo "PYLINT_PASSED=false" >> $GITHUB_ENV echo "⚠️ Pylint found issues!" fi cat pylint-output.txt continue-on-error: true - name: Run ruff id: ruff run: | echo "Running ruff check..." if ruff check . > ruff-output.txt 2>&1; then echo "RUFF_PASSED=true" >> $GITHUB_ENV echo "✅ No ruff errors found!" else echo "RUFF_PASSED=false" >> $GITHUB_ENV echo "⚠️ Ruff found issues" fi cat ruff-output.txt continue-on-error: true - name: Run mypy id: mypy run: | echo "Running mypy..." if mypy . > mypy-output.txt 2>&1; then echo "MYPY_PASSED=true" >> $GITHUB_ENV echo "✅ No mypy errors found" else echo "MYPY_PASSED=false" >> $GITHUB_ENV echo "⚠️ Mypy found issues" fi cat mypy-output.txt continue-on-error: true - name: Create Lint Summary id: create_summary if: github.event_name == 'pull_request' run: | { echo '## 🔍 Lint & Type Check Results' echo '' # Pylint Status if [[ "${{ env.PYLINT_PASSED }}" == "true" ]]; then echo '### ✅ Pylint: **Passed**' echo 'No pylint issues found.' else echo '### ⚠️ Pylint: **Issues Found**' echo '
View pylint output' echo '' echo '```' head -100 pylint-output.txt echo '```' echo '
' fi echo '' # Ruff Status if [[ "${{ env.RUFF_PASSED }}" == "true" ]]; then echo '### ✅ Ruff: **Passed**' echo 'No ruff issues found.' else echo '### ⚠️ Ruff: **Issues Found**' echo '
View ruff output' echo '' echo '```' head -100 ruff-output.txt echo '```' echo '
' fi echo '' # Mypy Status if [[ "${{ env.MYPY_PASSED }}" == "true" ]]; then echo '### ✅ Mypy: **Passed**' echo 'No mypy issues found.' else echo '### ⚠️ Mypy: **Issues Found**' echo '
View mypy output' echo '' echo '```' head -100 mypy-output.txt echo '```' echo '
' fi echo '' # Overall Summary if [[ "${{ env.PYLINT_PASSED }}" == "true" ]] && [[ "${{ env.RUFF_PASSED }}" == "true" ]] && [[ "${{ env.MYPY_PASSED }}" == "true" ]]; then echo '---' echo '### All checks passed!' else echo '---' echo '### Review the issues above and consider fixing them.' fi echo '' echo '' } > ../lint-report.md - name: Post PR Comment if: github.event_name == 'pull_request' uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ github.event.pull_request.number }} body-path: lint-report.md comment-marker: lint-check-comment-marker