|
| 1 | +name: Lint & Format Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 13 | + cancel-in-progress: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + lint-backend: |
| 17 | + name: Backend (Python) |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: ${{ !contains(github.event.head_commit.message, '🤖 Automated lint fixes') }} |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Set up Python |
| 32 | + uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: "3.11" |
| 35 | + cache: "pip" |
| 36 | + |
| 37 | + - name: Install linting tools |
| 38 | + run: | |
| 39 | + pip install ruff black isort mypy |
| 40 | + pip install -r backend/requirements.txt || true |
| 41 | +
|
| 42 | + - name: Run Ruff (lint + fix) |
| 43 | + id: ruff |
| 44 | + run: | |
| 45 | + echo "### 🐍 Ruff Linter" >> $GITHUB_STEP_SUMMARY |
| 46 | + ruff check backend/ --fix --output-format=github || echo "ruff_failed=true" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Run Black (format) |
| 49 | + run: | |
| 50 | + echo "### 🎨 Black Formatter" >> $GITHUB_STEP_SUMMARY |
| 51 | + black backend/ --check --diff || black backend/ |
| 52 | +
|
| 53 | + - name: Run isort (imports) |
| 54 | + run: | |
| 55 | + echo "### 📦 isort (Import Sorting)" >> $GITHUB_STEP_SUMMARY |
| 56 | + isort backend/ --check-only --diff || isort backend/ |
| 57 | +
|
| 58 | + - name: Run mypy (type checking) |
| 59 | + id: mypy |
| 60 | + continue-on-error: true |
| 61 | + run: | |
| 62 | + echo "### 🔍 mypy (Type Checking)" >> $GITHUB_STEP_SUMMARY |
| 63 | + mypy backend/ --pretty --show-error-codes || echo "mypy_failed=true" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + - name: Check for changes |
| 66 | + id: check_changes |
| 67 | + run: | |
| 68 | + if [[ -n $(git status --porcelain) ]]; then |
| 69 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 70 | + echo "## 📝 Auto-fixed issues" >> $GITHUB_STEP_SUMMARY |
| 71 | + echo '```diff' >> $GITHUB_STEP_SUMMARY |
| 72 | + git diff >> $GITHUB_STEP_SUMMARY |
| 73 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 74 | + else |
| 75 | + echo "changes=false" >> $GITHUB_OUTPUT |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Commit and push changes |
| 79 | + if: steps.check_changes.outputs.changes == 'true' && github.event_name == 'push' |
| 80 | + run: | |
| 81 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 82 | + git config --local user.name "github-actions[bot]" |
| 83 | + git add -A |
| 84 | + git commit -m "style(backend): auto-fix lint issues |
| 85 | +
|
| 86 | + 🤖 Automated lint fixes: |
| 87 | + - Ruff auto-fixes applied |
| 88 | + - Black formatting applied |
| 89 | + - isort import sorting applied |
| 90 | +
|
| 91 | + [skip ci]" |
| 92 | + git push |
| 93 | +
|
| 94 | + - name: Final status |
| 95 | + if: steps.ruff.outputs.ruff_failed == 'true' || steps.mypy.outputs.mypy_failed == 'true' |
| 96 | + run: | |
| 97 | + echo "## ⚠️ Manual fixes required" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 99 | + echo "Some issues couldn't be auto-fixed. Please review the errors above." >> $GITHUB_STEP_SUMMARY |
| 100 | + exit 1 |
| 101 | +
|
| 102 | + lint-frontend: |
| 103 | + name: Frontend (TypeScript) |
| 104 | + runs-on: ubuntu-latest |
| 105 | + if: ${{ !contains(github.event.head_commit.message, '🤖 Automated lint fixes') }} |
| 106 | + permissions: |
| 107 | + contents: write |
| 108 | + pull-requests: write |
| 109 | + |
| 110 | + steps: |
| 111 | + - name: Checkout code |
| 112 | + uses: actions/checkout@v4 |
| 113 | + with: |
| 114 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + fetch-depth: 0 |
| 116 | + |
| 117 | + - name: Setup Node.js |
| 118 | + uses: actions/setup-node@v4 |
| 119 | + with: |
| 120 | + node-version: "20" |
| 121 | + cache: "npm" |
| 122 | + cache-dependency-path: frontend/package-lock.json |
| 123 | + |
| 124 | + - name: Install dependencies |
| 125 | + working-directory: frontend |
| 126 | + run: npm ci |
| 127 | + |
| 128 | + - name: Run ESLint (lint + fix) |
| 129 | + id: eslint |
| 130 | + working-directory: frontend |
| 131 | + run: | |
| 132 | + echo "### 🔧 ESLint" >> $GITHUB_STEP_SUMMARY |
| 133 | + npx eslint . --ext .ts,.tsx,.js,.jsx --fix --format=stylish || echo "eslint_failed=true" >> $GITHUB_OUTPUT |
| 134 | +
|
| 135 | + - name: Run Prettier (format) |
| 136 | + working-directory: frontend |
| 137 | + run: | |
| 138 | + echo "### 💅 Prettier" >> $GITHUB_STEP_SUMMARY |
| 139 | + npx prettier --write "**/*.{ts,tsx,js,jsx,json,css,scss,md}" || true |
| 140 | +
|
| 141 | + - name: Run TypeScript compiler (type check) |
| 142 | + id: tsc |
| 143 | + continue-on-error: true |
| 144 | + working-directory: frontend |
| 145 | + run: | |
| 146 | + echo "### 📘 TypeScript Check" >> $GITHUB_STEP_SUMMARY |
| 147 | + npx tsc --noEmit --pretty || echo "tsc_failed=true" >> $GITHUB_OUTPUT |
| 148 | +
|
| 149 | + - name: Check for changes |
| 150 | + id: check_changes |
| 151 | + run: | |
| 152 | + if [[ -n $(git status --porcelain) ]]; then |
| 153 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 154 | + echo "## 📝 Auto-fixed issues" >> $GITHUB_STEP_SUMMARY |
| 155 | + echo '```diff' >> $GITHUB_STEP_SUMMARY |
| 156 | + git diff >> $GITHUB_STEP_SUMMARY |
| 157 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 158 | + else |
| 159 | + echo "changes=false" >> $GITHUB_STEP_SUMMARY |
| 160 | + fi |
| 161 | +
|
| 162 | + - name: Commit and push changes |
| 163 | + if: steps.check_changes.outputs.changes == 'true' && github.event_name == 'push' |
| 164 | + run: | |
| 165 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 166 | + git config --local user.name "github-actions[bot]" |
| 167 | + git add -A |
| 168 | + git commit -m "style(frontend): auto-fix lint issues |
| 169 | +
|
| 170 | + 🤖 Automated lint fixes: |
| 171 | + - ESLint auto-fixes applied |
| 172 | + - Prettier formatting applied |
| 173 | +
|
| 174 | + [skip ci]" |
| 175 | + git push |
| 176 | +
|
| 177 | + - name: Final status |
| 178 | + if: steps.eslint.outputs.eslint_failed == 'true' || steps.tsc.outputs.tsc_failed == 'true' |
| 179 | + run: | |
| 180 | + echo "## ⚠️ Manual fixes required" >> $GITHUB_STEP_SUMMARY |
| 181 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 182 | + echo "Some issues couldn't be auto-fixed. Please review the errors above." >> $GITHUB_STEP_SUMMARY |
| 183 | + exit 1 |
0 commit comments