|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Job 1: Python Code Quality Checks |
| 12 | + lint-and-format: |
| 13 | + name: Code Quality & Linting |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: '3.11' |
| 24 | + cache: 'pip' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: | |
| 28 | + python -m pip install --upgrade pip |
| 29 | + pip install flake8 black pylint |
| 30 | + pip install -r requirements.txt |
| 31 | + |
| 32 | + - name: Check code formatting with Black |
| 33 | + run: | |
| 34 | + black --check --diff . |
| 35 | + continue-on-error: true |
| 36 | + |
| 37 | + - name: Lint with flake8 |
| 38 | + run: | |
| 39 | + # Stop the build if there are Python syntax errors or undefined names |
| 40 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 41 | + # Exit-zero treats all errors as warnings |
| 42 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 43 | + continue-on-error: true |
| 44 | + |
| 45 | + - name: Lint with pylint |
| 46 | + run: | |
| 47 | + pylint --disable=all --enable=E,F --fail-under=5 routes/ utils/ services/ || true |
| 48 | + continue-on-error: true |
| 49 | + |
| 50 | + - name: Check Python syntax |
| 51 | + run: | |
| 52 | + python -m py_compile app.py |
| 53 | + find . -name "*.py" -not -path "./.venv/*" -not -path "./venv/*" -exec python -m py_compile {} \; |
| 54 | + |
| 55 | + - name: Check for common issues |
| 56 | + run: | |
| 57 | + # Prüfe auf TODO/FIXME ohne Issue-Nummer |
| 58 | + if grep -r "TODO\|FIXME" --include="*.py" . | grep -v "# TODO:" | grep -v "# FIXME:"; then |
| 59 | + echo "⚠️ Gefundene TODO/FIXME Kommentare" |
| 60 | + fi |
| 61 | +
|
| 62 | + # Job 2: Test Docker Build |
| 63 | + docker-build: |
| 64 | + name: Docker Build Test |
| 65 | + runs-on: ubuntu-latest |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Set up Docker Buildx |
| 72 | + uses: docker/setup-buildx-action@v3 |
| 73 | + |
| 74 | + - name: Build Docker image |
| 75 | + uses: docker/build-push-action@v5 |
| 76 | + with: |
| 77 | + context: . |
| 78 | + file: ./Dockerfile |
| 79 | + push: false |
| 80 | + tags: finanzapp:test |
| 81 | + cache-from: type=gha |
| 82 | + cache-to: type=gha,mode=max |
| 83 | + |
| 84 | + - name: Test Docker image |
| 85 | + run: | |
| 86 | + docker run --rm finanzapp:test python -c "import flask; import mysql.connector; print('✅ Imports erfolgreich')" |
| 87 | + docker run --rm finanzapp:test python -m py_compile app.py |
| 88 | + echo "✅ Docker Image Build erfolgreich" |
| 89 | +
|
| 90 | + # Job 3: Test Migrations |
| 91 | + test-migrations: |
| 92 | + name: Test Database Migrations |
| 93 | + runs-on: ubuntu-latest |
| 94 | + |
| 95 | + services: |
| 96 | + mysql: |
| 97 | + image: mysql:8.0 |
| 98 | + env: |
| 99 | + MYSQL_ROOT_PASSWORD: test_password |
| 100 | + MYSQL_DATABASE: test_db |
| 101 | + ports: |
| 102 | + - 3306:3306 |
| 103 | + options: >- |
| 104 | + --health-cmd="mysqladmin ping -h localhost" |
| 105 | + --health-interval=10s |
| 106 | + --health-timeout=5s |
| 107 | + --health-retries=3 |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Checkout code |
| 111 | + uses: actions/checkout@v4 |
| 112 | + |
| 113 | + - name: Set up Python |
| 114 | + uses: actions/setup-python@v5 |
| 115 | + with: |
| 116 | + python-version: '3.11' |
| 117 | + cache: 'pip' |
| 118 | + |
| 119 | + - name: Install dependencies |
| 120 | + run: | |
| 121 | + python -m pip install --upgrade pip |
| 122 | + pip install -r requirements.txt |
| 123 | + |
| 124 | + - name: Wait for MySQL |
| 125 | + run: | |
| 126 | + while ! mysqladmin ping -h 127.0.0.1 -u root -ptest_password --silent; do |
| 127 | + echo "Warte auf MySQL..." |
| 128 | + sleep 2 |
| 129 | + done |
| 130 | + echo "✅ MySQL ist bereit" |
| 131 | + |
| 132 | + - name: Test migrations |
| 133 | + env: |
| 134 | + DB_HOST: 127.0.0.1 |
| 135 | + DB_USER: root |
| 136 | + DB_PASSWORD: test_password |
| 137 | + DB_NAME: test_db |
| 138 | + run: | |
| 139 | + python migrate.py |
| 140 | + echo "✅ Migrationen erfolgreich ausgeführt" |
| 141 | + |
| 142 | + - name: Verify schema |
| 143 | + env: |
| 144 | + DB_HOST: 127.0.0.1 |
| 145 | + DB_USER: root |
| 146 | + DB_PASSWORD: test_password |
| 147 | + DB_NAME: test_db |
| 148 | + run: | |
| 149 | + python -c " |
| 150 | + import mysql.connector |
| 151 | + conn = mysql.connector.connect( |
| 152 | + host='127.0.0.1', |
| 153 | + user='root', |
| 154 | + password='test_password', |
| 155 | + database='test_db' |
| 156 | + ) |
| 157 | + cur = conn.cursor() |
| 158 | + cur.execute('SHOW TABLES') |
| 159 | + tables = [row[0] for row in cur.fetchall()] |
| 160 | + print(f'✅ Gefundene Tabellen: {tables}') |
| 161 | + assert 'buchungen' in tables, 'Tabelle buchungen fehlt' |
| 162 | + assert 'schema_migrations' in tables, 'Tabelle schema_migrations fehlt' |
| 163 | + cur.close() |
| 164 | + conn.close() |
| 165 | + print('✅ Schema-Verifikation erfolgreich') |
| 166 | + " |
| 167 | +
|
| 168 | + # Job 4: Test Import Scripts |
| 169 | + test-imports: |
| 170 | + name: Test Import Scripts |
| 171 | + runs-on: ubuntu-latest |
| 172 | + |
| 173 | + steps: |
| 174 | + - name: Checkout code |
| 175 | + uses: actions/checkout@v4 |
| 176 | + |
| 177 | + - name: Set up Python |
| 178 | + uses: actions/setup-python@v5 |
| 179 | + with: |
| 180 | + python-version: '3.11' |
| 181 | + cache: 'pip' |
| 182 | + |
| 183 | + - name: Install dependencies |
| 184 | + run: | |
| 185 | + python -m pip install --upgrade pip |
| 186 | + pip install -r requirements.txt |
| 187 | + |
| 188 | + - name: Test import syntax |
| 189 | + run: | |
| 190 | + python -c "import app; import db; import migrate; import init_db" |
| 191 | + python -c "from routes import dashboard, actions, settings, upload" |
| 192 | + python -c "from utils import beleg_upload, csrf, csv_parser, helpers, logging_config, version" |
| 193 | + python -c "from services import data_service" |
| 194 | + echo "✅ Alle Imports erfolgreich" |
| 195 | +
|
| 196 | + # Job 5: Security Checks |
| 197 | + security: |
| 198 | + name: Security Checks |
| 199 | + runs-on: ubuntu-latest |
| 200 | + |
| 201 | + steps: |
| 202 | + - name: Checkout code |
| 203 | + uses: actions/checkout@v4 |
| 204 | + |
| 205 | + - name: Run Bandit security linter |
| 206 | + uses: securecodewarrior/github-action-bandit@v1 |
| 207 | + with: |
| 208 | + path: . |
| 209 | + exit_zero: true |
| 210 | + continue-on-error: true |
| 211 | + |
| 212 | + - name: Check for secrets |
| 213 | + run: | |
| 214 | + # Prüfe auf mögliche hardcodierte Secrets |
| 215 | + if grep -r "password.*=.*['\"].*[A-Za-z0-9]" --include="*.py" . | grep -v "test_password" | grep -v "# "; then |
| 216 | + echo "⚠️ Mögliche hardcodierte Passwörter gefunden" |
| 217 | + fi |
| 218 | + if grep -r "SECRET_KEY.*=.*['\"].*[A-Za-z0-9]" --include="*.py" . | grep -v "change-me" | grep -v "# "; then |
| 219 | + echo "⚠️ Mögliche hardcodierte Secret Keys gefunden" |
| 220 | + fi |
| 221 | +
|
| 222 | + # Job 6: Documentation Check |
| 223 | + docs: |
| 224 | + name: Documentation Check |
| 225 | + runs-on: ubuntu-latest |
| 226 | + |
| 227 | + steps: |
| 228 | + - name: Checkout code |
| 229 | + uses: actions/checkout@v4 |
| 230 | + |
| 231 | + - name: Check README exists |
| 232 | + run: | |
| 233 | + test -f README.md && echo "✅ README.md vorhanden" || exit 1 |
| 234 | + |
| 235 | + - name: Check for broken links in README |
| 236 | + run: | |
| 237 | + # Einfache Prüfung auf Markdown-Links |
| 238 | + if grep -r "\[.*\](" README.md | grep -v "http" | grep -v "mailto"; then |
| 239 | + echo "⚠️ Lokale Links gefunden - bitte prüfen" |
| 240 | + fi |
| 241 | + continue-on-error: true |
0 commit comments