|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master, develop, feature/** ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ci-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + |
| 16 | + secrets: |
| 17 | + name: Secrets Scan (Gitleaks) |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - name: Scan for secrets |
| 22 | + uses: gitleaks/gitleaks-action@v2 |
| 23 | + env: |
| 24 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + |
| 27 | + backend: |
| 28 | + name: Backend (Python) |
| 29 | + runs-on: ubuntu-latest |
| 30 | + if: ${{ hashFiles('backend/**', 'requirements.txt') != '' }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Setup Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: '3.12' |
| 38 | + |
| 39 | + - name: Cache pip |
| 40 | + uses: actions/cache@v4 |
| 41 | + with: |
| 42 | + path: ~/.cache/pip |
| 43 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-pip- |
| 46 | +
|
| 47 | + - name: Install deps |
| 48 | + run: | |
| 49 | + python -m pip install --upgrade pip |
| 50 | + pip install -r requirements.txt |
| 51 | + pip install ruff pytest pip-audit |
| 52 | +
|
| 53 | + - name: Lint (ruff) |
| 54 | + working-directory: backend |
| 55 | + run: ruff check . |
| 56 | + |
| 57 | + - name: Syntax check |
| 58 | + run: python -m py_compile $(git ls-files 'backend/**/*.py' 'backend/*.py' || true) |
| 59 | + |
| 60 | + - name: Unit tests (if any) |
| 61 | + run: | |
| 62 | + if [ -d "tests" ] || ls -1 backend | grep -qi "test"; then |
| 63 | + pytest -q |
| 64 | + else |
| 65 | + echo "No tests found — skipping." |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Dependency vulnerabilities (pip-audit) |
| 69 | + run: | |
| 70 | + pip-audit --requirement requirements.txt || true |
| 71 | +
|
| 72 | + frontend: |
| 73 | + name: Frontend (Node) |
| 74 | + runs-on: ubuntu-latest |
| 75 | + if: ${{ hashFiles('frontend/**', 'frontend/package.json') != '' }} |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Setup Node |
| 80 | + uses: actions/setup-node@v4 |
| 81 | + with: |
| 82 | + node-version: '20' |
| 83 | + cache: 'npm' |
| 84 | + cache-dependency-path: frontend/package-lock.json |
| 85 | + |
| 86 | + - name: Install deps |
| 87 | + working-directory: frontend |
| 88 | + run: npm ci |
| 89 | + |
| 90 | + - name: Lint (if script exists) |
| 91 | + working-directory: frontend |
| 92 | + run: npm run -s lint || echo "No lint script — skipping." |
| 93 | + |
| 94 | + - name: Tests (if script exists) |
| 95 | + working-directory: frontend |
| 96 | + run: npm test --if-present || echo "No tests — skipping." |
| 97 | + |
| 98 | + - name: Build (ensures it compiles) |
| 99 | + working-directory: frontend |
| 100 | + run: npm run -s build || echo "No build step — skipping." |
| 101 | + |
| 102 | + |
| 103 | + iac: |
| 104 | + name: IaC Scan (Checkov) |
| 105 | + runs-on: ubuntu-latest |
| 106 | + if: ${{ hashFiles('**/*.tf', '**/*.tfvars', '**/kubernetes/*.y*ml', '**/helm/**') != '' }} |
| 107 | + steps: |
| 108 | + - uses: actions/checkout@v4 |
| 109 | + - name: Checkov |
| 110 | + uses: bridgecrewio/checkov-action@v12 |
| 111 | + with: |
| 112 | + quiet: true |
| 113 | + soft_fail: true |
| 114 | + |
| 115 | + |
| 116 | + status: |
| 117 | + name: Status Gate |
| 118 | + needs: [secrets, backend, frontend] |
| 119 | + runs-on: ubuntu-latest |
| 120 | + steps: |
| 121 | + - run: echo "All core checks finished." |
0 commit comments