|
| 1 | +name: spring-prometheus-grafana-example CI Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [master] |
| 6 | + paths: |
| 7 | + - "spring-prometheus-grafana-example/**" |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - synchronize |
| 11 | + - reopened |
| 12 | + |
| 13 | +jobs: |
| 14 | + |
| 15 | + integration-tests: |
| 16 | + name: Run Unit & Integration Tests |
| 17 | + runs-on: ubuntu-latest |
| 18 | + defaults: |
| 19 | + run: |
| 20 | + working-directory: spring-prometheus-grafana-example |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + distribution: [ 'temurin' ] |
| 24 | + java: [ '21' ] |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Set up JDK ${{ matrix.java }} |
| 31 | + |
| 32 | + with: |
| 33 | + java-version: ${{ matrix.java }} |
| 34 | + distribution: ${{ matrix.distribution }} |
| 35 | + cache: 'maven' |
| 36 | + - name: Build and analyze |
| 37 | + run: ./mvnw clean verify |
| 38 | + |
| 39 | + health-check: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Checkout repository and submodules |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + submodules: true |
| 46 | + |
| 47 | + - name: Start containers with Compose Action |
| 48 | + uses: hoverkraft-tech/[email protected] |
| 49 | + with: |
| 50 | + compose-file: './spring-prometheus-grafana-example/compose.yaml' |
| 51 | + services: | |
| 52 | + app |
| 53 | + up-flags: '--build' |
| 54 | + down-flags: '--volumes' |
| 55 | + |
| 56 | + - name: Wait for containers to initialize |
| 57 | + run: sleep 10 |
| 58 | + |
| 59 | + - name: Check container health |
| 60 | + run: | |
| 61 | + echo "Verificando saúde dos containers..." |
| 62 | +
|
| 63 | + APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false") |
| 64 | +
|
| 65 | + echo "Status do app: $APP_STATUS" |
| 66 | +
|
| 67 | + if [ "$APP_STATUS" != "true" ]; then |
| 68 | + echo "::error ::An error occurred while executing the containers." |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + # Se chegou aqui, ambos estão ativos |
| 73 | + - name: Success message |
| 74 | + run: echo "Container testing completed successfully!" |
0 commit comments