|
| 1 | +name: CI (Strict) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ci-strict-${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +env: |
| 17 | + PYTHON_VERSION: "3.12" |
| 18 | + NODE_VERSION: "20" |
| 19 | + PNPM_VERSION: "9" |
| 20 | + # Use official PyPI in CI (override any mirror settings) |
| 21 | + UV_INDEX_URL: "https://pypi.org/simple/" |
| 22 | + |
| 23 | +jobs: |
| 24 | + # ============================================ |
| 25 | + # Job: Dependency Integrity Check |
| 26 | + # ============================================ |
| 27 | + lockfile-check: |
| 28 | + name: 🔒 Lockfile Integrity |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Set up Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: ${{ env.PYTHON_VERSION }} |
| 38 | + |
| 39 | + - name: Set up uv |
| 40 | + uses: astral-sh/setup-uv@v5 |
| 41 | + with: |
| 42 | + enable-cache: true |
| 43 | + |
| 44 | + - name: Replace PyPI mirror in uv.lock |
| 45 | + run: | |
| 46 | + # Replace Tsinghua mirror URLs with official PyPI for CI compatibility |
| 47 | + sed -i 's|https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/|https://pypi.org/simple/|g' uv.lock |
| 48 | + sed -i 's|https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/|https://files.pythonhosted.org/packages/|g' uv.lock |
| 49 | + # Re-sync to update lockfile hashes after URL replacement |
| 50 | + uv sync |
| 51 | +
|
| 52 | + - name: Set up pnpm |
| 53 | + uses: pnpm/action-setup@v4 |
| 54 | + with: |
| 55 | + version: ${{ env.PNPM_VERSION }} |
| 56 | + |
| 57 | + - name: Set up Node.js |
| 58 | + uses: actions/setup-node@v4 |
| 59 | + with: |
| 60 | + node-version: ${{ env.NODE_VERSION }} |
| 61 | + cache: pnpm |
| 62 | + cache-dependency-path: ui/pnpm-lock.yaml |
| 63 | + |
| 64 | + - name: Verify pnpm-lock.yaml is up to date |
| 65 | + working-directory: ui |
| 66 | + run: | |
| 67 | + pnpm install --frozen-lockfile || ( |
| 68 | + echo "❌ pnpm-lock.yaml is out of date. Run 'pnpm install' in ui/ locally and commit the changes." |
| 69 | + exit 1 |
| 70 | + ) |
| 71 | +
|
| 72 | + # ============================================ |
| 73 | + # Job: Python Backend Checks |
| 74 | + # ============================================ |
| 75 | + backend: |
| 76 | + name: 🐍 Backend |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: lockfile-check |
| 79 | + strategy: |
| 80 | + fail-fast: true |
| 81 | + matrix: |
| 82 | + check: [format, lint, test] |
| 83 | + steps: |
| 84 | + - name: Checkout |
| 85 | + uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Set up Python |
| 88 | + uses: actions/setup-python@v5 |
| 89 | + with: |
| 90 | + python-version: ${{ env.PYTHON_VERSION }} |
| 91 | + |
| 92 | + - name: Set up uv |
| 93 | + uses: astral-sh/setup-uv@v5 |
| 94 | + with: |
| 95 | + enable-cache: true |
| 96 | + |
| 97 | + - name: Install dependencies |
| 98 | + run: | |
| 99 | + # Replace Tsinghua mirror URLs with official PyPI for CI compatibility |
| 100 | + sed -i 's|https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/|https://pypi.org/simple/|g' uv.lock |
| 101 | + sed -i 's|https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/|https://files.pythonhosted.org/packages/|g' uv.lock |
| 102 | + uv sync |
| 103 | +
|
| 104 | + # Format Check |
| 105 | + - name: Check Python formatting |
| 106 | + if: matrix.check == 'format' |
| 107 | + run: uv run ruff format --check swarmmind/ tests/ |
| 108 | + |
| 109 | + # Lint |
| 110 | + - name: Run Python linter |
| 111 | + if: matrix.check == 'lint' |
| 112 | + run: uv run ruff check swarmmind/ tests/ |
| 113 | + |
| 114 | + # Test with Coverage (skip LLM tests in CI) |
| 115 | + - name: Run Python tests with coverage |
| 116 | + if: matrix.check == 'test' |
| 117 | + run: uv run python -m pytest tests/ -v -m "not requires_llm" --cov=swarmmind --cov-report=xml --cov-report=term-missing |
| 118 | + |
| 119 | + - name: Upload coverage report |
| 120 | + if: matrix.check == 'test' |
| 121 | + uses: codecov/codecov-action@v4 |
| 122 | + with: |
| 123 | + files: ./coverage.xml |
| 124 | + fail_ci_if_error: false |
| 125 | + verbose: true |
| 126 | + env: |
| 127 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 128 | + |
| 129 | + # ============================================ |
| 130 | + # Job: Frontend Checks |
| 131 | + # ============================================ |
| 132 | + frontend: |
| 133 | + name: ⚛️ Frontend |
| 134 | + runs-on: ubuntu-latest |
| 135 | + needs: lockfile-check |
| 136 | + strategy: |
| 137 | + fail-fast: true |
| 138 | + matrix: |
| 139 | + check: [lint, typecheck, build] |
| 140 | + steps: |
| 141 | + - name: Checkout |
| 142 | + uses: actions/checkout@v4 |
| 143 | + |
| 144 | + - name: Set up pnpm |
| 145 | + uses: pnpm/action-setup@v4 |
| 146 | + with: |
| 147 | + version: ${{ env.PNPM_VERSION }} |
| 148 | + |
| 149 | + - name: Set up Node.js |
| 150 | + uses: actions/setup-node@v4 |
| 151 | + with: |
| 152 | + node-version: ${{ env.NODE_VERSION }} |
| 153 | + cache: pnpm |
| 154 | + cache-dependency-path: ui/pnpm-lock.yaml |
| 155 | + |
| 156 | + - name: Install dependencies |
| 157 | + working-directory: ui |
| 158 | + run: pnpm install --frozen-lockfile |
| 159 | + |
| 160 | + # Lint |
| 161 | + - name: Run ESLint |
| 162 | + if: matrix.check == 'lint' |
| 163 | + working-directory: ui |
| 164 | + run: pnpm run lint |
| 165 | + |
| 166 | + # Type Check |
| 167 | + - name: Run TypeScript type check |
| 168 | + if: matrix.check == 'typecheck' |
| 169 | + working-directory: ui |
| 170 | + run: pnpm run typecheck |
| 171 | + |
| 172 | + # Build |
| 173 | + - name: Build for production |
| 174 | + if: matrix.check == 'build' |
| 175 | + working-directory: ui |
| 176 | + run: pnpm run build |
| 177 | + |
| 178 | + # ============================================ |
| 179 | + # Job: Spell Check |
| 180 | + # ============================================ |
| 181 | + spellcheck: |
| 182 | + name: 📝 Spell Check |
| 183 | + runs-on: ubuntu-latest |
| 184 | + steps: |
| 185 | + - name: Checkout |
| 186 | + uses: actions/checkout@v4 |
| 187 | + |
| 188 | + - name: Check for typos |
| 189 | + uses: crate-ci/typos@v1.21.0 |
| 190 | + with: |
| 191 | + files: . |
| 192 | + config: ./typos.toml |
| 193 | + |
| 194 | + # ============================================ |
| 195 | + # Job: Summary |
| 196 | + # ============================================ |
| 197 | + ci-summary: |
| 198 | + name: ✅ CI Summary |
| 199 | + runs-on: ubuntu-latest |
| 200 | + needs: [backend, frontend, spellcheck] |
| 201 | + if: always() |
| 202 | + steps: |
| 203 | + - name: Check all jobs status |
| 204 | + run: | |
| 205 | + echo "Backend: ${{ needs.backend.result }}" |
| 206 | + echo "Frontend: ${{ needs.frontend.result }}" |
| 207 | + echo "Spell Check: ${{ needs.spellcheck.result }}" |
| 208 | +
|
| 209 | + - name: Fail if any job failed |
| 210 | + if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') |
| 211 | + run: | |
| 212 | + echo "❌ CI failed" |
| 213 | + exit 1 |
| 214 | +
|
| 215 | + - name: Success |
| 216 | + run: echo "✅ All CI checks passed!" |
0 commit comments