|
1 | | -name: CI Pipeline |
| 1 | +name: CI Pipeline (Docker Compose) |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
7 | 7 | branches: [ main, develop ] |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - build-and-test: |
11 | | - name: 🧪 Build, Lint & Test |
| 10 | + test: |
| 11 | + name: 🐳 Build & Test (Docker Compose) |
12 | 12 | runs-on: ubuntu-latest |
13 | 13 |
|
14 | | - services: |
15 | | - postgres: |
16 | | - image: postgres:15 |
17 | | - env: |
18 | | - POSTGRES_USER: ${{ secrets.POSTGRES_USER || 'user' }} |
19 | | - POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD || 'password' }} |
20 | | - POSTGRES_DB: ${{ secrets.POSTGRES_DB || 'api_workout_db' }} |
21 | | - ports: |
22 | | - - 5432:5432 |
23 | | - options: >- |
24 | | - --health-cmd="pg_isready -U ${{ secrets.POSTGRES_USER || 'user' }}" |
25 | | - --health-interval=10s |
26 | | - --health-timeout=5s |
27 | | - --health-retries=5 |
28 | | -
|
29 | | - env: |
30 | | - # Variáveis usadas nos testes e na aplicação |
31 | | - DATABASE_URL: postgresql+psycopg2://${{ secrets.POSTGRES_USER || 'user' }}:${{ secrets.POSTGRES_PASSWORD || 'password' }}@localhost:5432/${{ secrets.POSTGRES_DB || 'api_workout_db' }} |
32 | | - PYTHONPATH: ./app |
33 | | - ENVIRONMENT: test |
34 | | - |
35 | 14 | steps: |
36 | 15 | - name: 📥 Checkout do repositório |
37 | 16 | uses: actions/checkout@v4 |
38 | 17 |
|
39 | | - - name: 🐍 Configurar Python 3.11 |
40 | | - uses: actions/setup-python@v5 |
| 18 | + - name: 🛠️ Configurar Docker Buildx |
| 19 | + uses: docker/setup-buildx-action@v3 |
| 20 | + |
| 21 | + - name: 🐳 Cache de camadas do Docker |
| 22 | + uses: actions/cache@v4 |
41 | 23 | with: |
42 | | - python-version: '3.11' |
| 24 | + path: /tmp/.buildx-cache |
| 25 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 26 | + restore-keys: | |
| 27 | + ${{ runner.os }}-buildx- |
| 28 | +
|
| 29 | + - name: 🐳 Subir containers (em background) |
| 30 | + run: | |
| 31 | + docker compose -f docker-compose.yml up -d --build |
| 32 | +
|
| 33 | + - name: ⏳ Aguardar Postgres ficar pronto |
| 34 | + run: | |
| 35 | + echo "Aguardando Postgres inicializar..." |
| 36 | + until docker compose exec -T db pg_isready -U ${POSTGRES_USER:-user}; do |
| 37 | + sleep 2 |
| 38 | + done |
43 | 39 |
|
44 | | - - name: 📦 Instalar dependências |
| 40 | + - name: 🗃️ Rodar migrações Alembic |
45 | 41 | run: | |
46 | | - python -m pip install --upgrade pip |
47 | | - pip install -r requirements.txt |
| 42 | + docker compose exec -T app alembic upgrade head |
48 | 43 |
|
49 | | - - name: 🧹 Rodar Linter (flake8) |
| 44 | + - name: 🧹 Lint (black + flake8) |
50 | 45 | run: | |
51 | | - pip install flake8 |
52 | | - flake8 app tests |
| 46 | + docker compose exec -T app bash -c "black --check . && flake8 app tests" |
53 | 47 |
|
54 | | - - name: 🧪 Rodar Testes com Pytest |
| 48 | + - name: 🧪 Rodar Testes |
55 | 49 | run: | |
56 | | - pip install pytest pytest-asyncio |
57 | | - pytest -v --maxfail=1 --disable-warnings |
| 50 | + docker compose exec -T app pytest -v --maxfail=1 --disable-warnings |
58 | 51 |
|
59 | | - - name: 🗃️ Verificar Migrations Alembic |
| 52 | + - name: 🧼 Derrubar containers |
| 53 | + if: always() |
60 | 54 | run: | |
61 | | - alembic upgrade head |
| 55 | + docker compose down -v |
0 commit comments