diff --git a/.github/workflows/spring-kafka-example.yml b/.github/workflows/spring-kafka-example.yml index ac0f2c7..b2a6cd0 100644 --- a/.github/workflows/spring-kafka-example.yml +++ b/.github/workflows/spring-kafka-example.yml @@ -1,11 +1,8 @@ name: spring-kafka-example CI Build on: - push: - paths: - - "spring-kafka-example/**" - branches: [master] pull_request: + branches: [master] paths: - "spring-kafka-example/**" types: @@ -14,7 +11,8 @@ on: - reopened jobs: - build: + + integration-tests: name: Run Unit & Integration Tests runs-on: ubuntu-latest defaults: @@ -27,7 +25,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + fetch-depth: 0 - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v4.7.1 @@ -36,4 +34,44 @@ jobs: distribution: ${{ matrix.distribution }} cache: 'maven' - name: Build and analyze - run: ./mvnw clean verify \ No newline at end of file + run: ./mvnw clean verify + + health-check: + runs-on: ubuntu-latest + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v3 + with: + submodules: true + + - name: Start containers with Compose Action + uses: hoverkraft-tech/compose-action@v2.3.0 + with: + compose-file: './spring-kafka-example/compose.yaml' + services: | + app + kafka + up-flags: '--build' + down-flags: '--volumes' + + - name: Wait for containers to initialize + run: sleep 10 + + - name: Check container health + run: | + echo "Verificando saúde dos containers..." + + APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false") + KAFKA_STATUS=$(docker inspect -f '{{.State.Running}}' kafka || echo "false") + + echo "Status do app: $APP_STATUS" + echo "Status do kafka: $KAFKA_STATUS" + + if [ "$APP_STATUS" != "true" ] || [ "$KAFKA_STATUS" != "true" ]; then + echo "::error ::Um ou ambos os containers estão inativos. PR não deve ser autorizado!" + exit 1 + fi + + # Se chegou aqui, ambos estão ativos + - name: Success message + run: echo "✅ Todos os containers estão rodando com sucesso!"