|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + python-version: ['3.12', '3.13'] |
| 15 | + |
| 16 | + services: |
| 17 | + # Optional: PostgreSQL service for more comprehensive testing |
| 18 | + # postgres: |
| 19 | + # image: postgres:15 |
| 20 | + # env: |
| 21 | + # POSTGRES_PASSWORD: postgres |
| 22 | + # POSTGRES_DB: test_db |
| 23 | + # options: >- |
| 24 | + # --health-cmd pg_isready |
| 25 | + # --health-interval 10s |
| 26 | + # --health-timeout 5s |
| 27 | + # --health-retries 5 |
| 28 | + # ports: |
| 29 | + # - 5432:5432 |
| 30 | + |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Install uv |
| 35 | + uses: astral-sh/setup-uv@v3 |
| 36 | + with: |
| 37 | + version: 'latest' |
| 38 | + |
| 39 | + - name: Set up Python ${{ matrix.python-version }} |
| 40 | + run: uv python install ${{ matrix.python-version }} |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: | |
| 44 | + uv sync --frozen |
| 45 | +
|
| 46 | + - name: Create test environment file |
| 47 | + run: | |
| 48 | + cat > .env << EOF |
| 49 | + SECRET_KEY=test-secret-key-for-ci-only-not-secure |
| 50 | + DATABASE_URL=sqlite+aiosqlite:///./test.db |
| 51 | + DEBUG=true |
| 52 | + TESTING=true |
| 53 | + EOF |
| 54 | +
|
| 55 | + - name: Run database migrations |
| 56 | + run: | |
| 57 | + uv run alembic upgrade head |
| 58 | +
|
| 59 | + - name: Run tests with coverage |
| 60 | + run: | |
| 61 | + uv run pytest --cov=app --cov-report=xml --cov-report=term-missing |
| 62 | +
|
| 63 | + lint: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Install uv |
| 69 | + uses: astral-sh/setup-uv@v3 |
| 70 | + with: |
| 71 | + version: 'latest' |
| 72 | + |
| 73 | + - name: Set up Python |
| 74 | + run: uv python install 3.12 |
| 75 | + |
| 76 | + - name: Install dependencies |
| 77 | + run: | |
| 78 | + uv sync --frozen |
| 79 | +
|
| 80 | + - name: Run ruff linting |
| 81 | + run: | |
| 82 | + uv run ruff check app/ |
| 83 | +
|
| 84 | + - name: Run ruff formatting check |
| 85 | + run: | |
| 86 | + uv run ruff format --check app/ |
| 87 | +
|
| 88 | + - name: Run Black formatting check |
| 89 | + run: | |
| 90 | + uv run black --check app/ |
| 91 | +
|
| 92 | + - name: Run isort import sorting check |
| 93 | + run: | |
| 94 | + uv run isort --check-only app/ |
| 95 | +
|
| 96 | + type-check: |
| 97 | + runs-on: ubuntu-latest |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v4 |
| 100 | + |
| 101 | + - name: Install uv |
| 102 | + uses: astral-sh/setup-uv@v3 |
| 103 | + with: |
| 104 | + version: 'latest' |
| 105 | + |
| 106 | + - name: Set up Python |
| 107 | + run: uv python install 3.12 |
| 108 | + |
| 109 | + - name: Install dependencies |
| 110 | + run: | |
| 111 | + uv sync --frozen |
| 112 | +
|
| 113 | + - name: Run MyPy type checking |
| 114 | + run: | |
| 115 | + uv run mypy app/ |
| 116 | +
|
| 117 | + security: |
| 118 | + runs-on: ubuntu-latest |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - name: Install uv |
| 123 | + uses: astral-sh/setup-uv@v3 |
| 124 | + with: |
| 125 | + version: 'latest' |
| 126 | + |
| 127 | + - name: Set up Python |
| 128 | + run: uv python install 3.12 |
| 129 | + |
| 130 | + - name: Install dependencies |
| 131 | + run: | |
| 132 | + uv sync --frozen |
| 133 | +
|
| 134 | + - name: Run security checks with bandit |
| 135 | + run: | |
| 136 | + uv run pip install bandit |
| 137 | + uv run bandit -r app/ -f json -o bandit-report.json || true |
| 138 | +
|
| 139 | + - name: Upload security scan results |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + if: always() |
| 142 | + with: |
| 143 | + name: security-scan-results |
| 144 | + path: bandit-report.json |
| 145 | + |
| 146 | + build: |
| 147 | + runs-on: ubuntu-latest |
| 148 | + needs: [test, lint, type-check] |
| 149 | + steps: |
| 150 | + - uses: actions/checkout@v4 |
| 151 | + |
| 152 | + - name: Install uv |
| 153 | + uses: astral-sh/setup-uv@v3 |
| 154 | + with: |
| 155 | + version: 'latest' |
| 156 | + |
| 157 | + - name: Set up Python |
| 158 | + run: uv python install 3.12 |
| 159 | + |
| 160 | + - name: Install dependencies |
| 161 | + run: | |
| 162 | + uv sync --frozen |
| 163 | +
|
| 164 | + - name: Create test environment file |
| 165 | + run: | |
| 166 | + cat > .env << EOF |
| 167 | + SECRET_KEY=test-secret-key-for-ci-only-not-secure |
| 168 | + DATABASE_URL=sqlite+aiosqlite:///./test.db |
| 169 | + DEBUG=false |
| 170 | + EOF |
| 171 | +
|
| 172 | + - name: Test application startup |
| 173 | + run: | |
| 174 | + uv run alembic upgrade head |
| 175 | + timeout 10s uv run uvicorn app.main:app --host 0.0.0.0 --port 8000 || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi |
| 176 | +
|
| 177 | + - name: Build package |
| 178 | + run: | |
| 179 | + uv build |
| 180 | +
|
| 181 | + - name: Upload build artifacts |
| 182 | + uses: actions/upload-artifact@v4 |
| 183 | + with: |
| 184 | + name: dist-files |
| 185 | + path: dist/ |
0 commit comments