|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, feat/* ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + name: Lint & Format |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Setup Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: '3.12' |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + pip install ruff black |
| 24 | +
|
| 25 | + - name: Run ruff |
| 26 | + run: ruff check app/ |
| 27 | + |
| 28 | + - name: Run black |
| 29 | + run: black --check app/ |
| 30 | + |
| 31 | + test: |
| 32 | + name: Tests |
| 33 | + runs-on: ubuntu-latest |
| 34 | + needs: lint |
| 35 | + |
| 36 | + services: |
| 37 | + postgres: |
| 38 | + image: postgres:16-alpine |
| 39 | + env: |
| 40 | + POSTGRES_USER: fleetops |
| 41 | + POSTGRES_PASSWORD: fleetops |
| 42 | + POSTGRES_DB: fleetops |
| 43 | + ports: |
| 44 | + - 5432:5432 |
| 45 | + options: >- |
| 46 | + --health-cmd pg_isready |
| 47 | + --health-interval 5s |
| 48 | + --health-timeout 5s |
| 49 | + --health-retries 5 |
| 50 | +
|
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Setup Python |
| 55 | + uses: actions/setup-python@v5 |
| 56 | + with: |
| 57 | + python-version: '3.12' |
| 58 | + |
| 59 | + - name: Install dependencies |
| 60 | + run: pip install -r requirements.txt |
| 61 | + |
| 62 | + - name: Run tests |
| 63 | + env: |
| 64 | + DATABASE_URL: postgresql+asyncpg://fleetops:fleetops@localhost:5432/fleetops |
| 65 | + run: pytest tests/ --cov=app --cov-report=term-missing |
| 66 | + |
| 67 | + security: |
| 68 | + name: Security Scan |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: lint |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Setup Python |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: '3.12' |
| 78 | + |
| 79 | + - name: Install security tools |
| 80 | + run: pip install bandit pip-audit |
| 81 | + |
| 82 | + - name: Run Bandit |
| 83 | + run: bandit -r app/ -ll |
| 84 | + |
| 85 | + - name: Run pip-audit |
| 86 | + run: | |
| 87 | + pip-audit -r requirements.txt \ |
| 88 | + --ignore-vuln PYSEC-2026-161 \ |
| 89 | + --ignore-vuln PYSEC-2026-248 \ |
| 90 | + --ignore-vuln PYSEC-2026-249 \ |
| 91 | + --ignore-vuln PYSEC-2026-1943 \ |
| 92 | + --ignore-vuln PYSEC-2026-1941 \ |
| 93 | + --ignore-vuln PYSEC-2026-2281 \ |
| 94 | + --ignore-vuln PYSEC-2026-2280 \ |
| 95 | + --ignore-vuln PYSEC-2026-1845 |
| 96 | +
|
| 97 | + build: |
| 98 | + name: Build & Push Docker Image |
| 99 | + runs-on: ubuntu-latest |
| 100 | + needs: [ test, security ] |
| 101 | + if: github.ref == 'refs/heads/main' |
| 102 | + |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Configure AWS credentials |
| 107 | + uses: aws-actions/configure-aws-credentials@v4 |
| 108 | + with: |
| 109 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 110 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 111 | + aws-region: us-east-1 |
| 112 | + |
| 113 | + - name: Login to Amazon ECR |
| 114 | + id: login-ecr |
| 115 | + uses: aws-actions/amazon-ecr-login@v2 |
| 116 | + |
| 117 | + - name: Build and push image |
| 118 | + env: |
| 119 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 120 | + IMAGE_TAG: ${{ github.sha }} |
| 121 | + run: | |
| 122 | + docker build -t $ECR_REGISTRY/fleetops:$IMAGE_TAG . |
| 123 | + docker build -t $ECR_REGISTRY/fleetops:latest . |
| 124 | + docker push $ECR_REGISTRY/fleetops:$IMAGE_TAG |
| 125 | + docker push $ECR_REGISTRY/fleetops:latest |
0 commit comments