Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions .github/workflows/spring-kafka-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,26 @@ jobs:
run: ./mvnw clean verify

health-check:
name: Health Check on Services
runs-on: ubuntu-latest
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v4
with:
submodules: true

- name: Extract service names from docker compose
id: services
run: |
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-kafka-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Start containers with Compose Action
uses: hoverkraft-tech/[email protected]
with:
compose-file: './spring-kafka-example/compose.yaml'
services: |
app
kafka
services: ${{ steps.services.outputs.services }}
up-flags: '--build'
down-flags: '--volumes'

Expand All @@ -59,19 +65,14 @@ jobs:

- 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
echo "Checking the health of the containers..."

# Se chegou aqui, ambos estão ativos
- name: Success message
run: echo "✅ Todos os containers estão rodando com sucesso!"
SERVICES="${{ steps.services.outputs.services }}"
for service in $SERVICES; do
status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Add a trailing newline

Identical lint warning as the other workflow—insert a newline at EOF.

-          done
\ No newline at end of file
+          done
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
done
done
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 78-78: no new line character at the end of file

(new-line-at-end-of-file)

🤖 Prompt for AI Agents
In .github/workflows/spring-kafka-example.yml at line 78, the file is missing a
trailing newline at the end of the file. Add a single newline character after
the last line to comply with linting rules and ensure proper file formatting.

38 changes: 18 additions & 20 deletions .github/workflows/spring-prometheus-grafana-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@ jobs:
run: ./mvnw clean verify

health-check:
name: Health Check on Services
runs-on: ubuntu-latest
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v4
with:
submodules: true

- name: Extract service names from docker compose
id: services
run: |
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

Comment on lines +48 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add strict shell-flags to surface failures early

If docker compose config --services fails (e.g., syntax error in compose.yaml or missing CLI plugin), the step will still succeed and later steps will receive an empty services output, masking the root cause. Enable set -euo pipefail so that the workflow aborts immediately on any error.

-      - name: Extract service names from docker compose
+      - name: Extract service names from docker compose
         id: services
         run: |
+          set -euo pipefail
           echo "services<<EOF" >> $GITHUB_OUTPUT
           docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
           echo "EOF" >> $GITHUB_OUTPUT
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Extract service names from docker compose
id: services
run: |
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Extract service names from docker compose
id: services
run: |
set -euo pipefail
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml around lines 48 to
54, the shell script running the docker compose command lacks strict error
handling, so failures do not abort the workflow immediately. Add `set -euo
pipefail` at the start of the run block to ensure the step fails fast on any
error, preventing silent failures and empty outputs downstream.

- name: Start containers with Compose Action
uses: hoverkraft-tech/[email protected]
with:
compose-file: './spring-prometheus-grafana-example/compose.yaml'
services: |
app
prometheus
grafana
services: ${{ steps.services.outputs.services }}
up-flags: '--build'
down-flags: '--volumes'

Expand All @@ -62,19 +67,12 @@ jobs:
run: |
echo "Checking the health of the containers..."

APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false")
PROMETHEUS_STATUS=$(docker inspect -f '{{.State.Running}}' prometheus || echo "false")
GRAFANA_STATUS=$(docker inspect -f '{{.State.Running}}' grafana || echo "false")

echo "App status: $APP_STATUS"
echo "Prometheus status: $PROMETHEUS_STATUS"
echo "Grafana status: $GRAFANA_STATUS"

if [ "$APP_STATUS" != "true" ] || [ "$PROMETHEUS_STATUS" != "true" ] || [ "$GRAFANA_STATUS" != "true" ]; then
echo "::error ::An error occurred while executing the containers."
exit 1
fi

# Se chegou aqui, ambos estão ativos
- name: Success message
run: echo "Container testing completed successfully!"
SERVICES="${{ steps.services.outputs.services }}"
for service in $SERVICES; do
status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
Comment on lines +70 to +77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Use container IDs from docker compose ps to avoid name-mismatch errors

docker inspect "$service" assumes every service sets container_name: and that the runtime name equals the service name. If those assumptions ever change, the health-check produces false negatives. Resolve by asking Compose for the container ID first:

-          for service in $SERVICES; do
-            status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
+          for service in $SERVICES; do
+            cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
+            status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
             echo "$service status: $status"
             if [ "$status" != "true" ]; then
               echo "::error ::Service $service is not running."
               exit 1
             fi
           done

I need to inspect the workflow to see how services are defined and whether a COMPOSE_FILE variable is in use. Gathering context now:


🏁 Script executed:

#!/bin/bash
# Locate and preview the workflow around the health-check step
file=$(fd spring-prometheus-grafana-example.yml)
echo "Workflow file: $file"
sed -n '1,200p' "$file"

Length of output: 155


Gathering workflow files and inspecting Docker commands:


🏁 Script executed:

#!/bin/bash
# List all workflow files
echo "Workflow files:"
find .github/workflows -type f \( -name '*.yml' -o -name '*.yaml' \)
echo ""

# Search for docker inspect in workflows
echo "docker inspect occurrences:"
rg -n 'docker inspect' .github/workflows || true
echo ""

# Search for docker compose usage in workflows
echo "docker compose occurrences:"
rg -n 'docker compose' .github/workflows || true

Length of output: 1294


Use container IDs from docker compose ps for reliable health checks

Relying on service names in docker inspect assumes the runtime container name matches the Compose service name (or a hard-coded container_name:). To avoid false negatives if that ever changes, first query the container ID with docker compose ps -q and then inspect that ID:

In .github/workflows/spring-prometheus-grafana-example.yml (around lines 70–77), update the loop as follows:

-          for service in $SERVICES; do
-            status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
+          for service in $SERVICES; do
+            # Get the container ID for this service
+            cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
+            # Inspect by ID to avoid name mismatches
+            status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
            echo "$service status: $status"
            if [ "$status" != "true" ]; then
              echo "::error ::Service $service is not running."
              exit 1
            fi
          done
  • Ensures the health check always targets the correct container, regardless of explicit container_name: settings or Compose naming conventions.
  • Uses the same Compose file path you already reference for config --services.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SERVICES="${{ steps.services.outputs.services }}"
for service in $SERVICES; do
status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
SERVICES="${{ steps.services.outputs.services }}"
for service in $SERVICES; do
# Get the container ID for this service
cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
# Inspect by ID to avoid name mismatches
status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
done
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml around lines 70 to
77, the current health check uses service names with docker inspect, which can
fail if container names differ from service names. To fix this, first retrieve
container IDs using docker compose ps -q with the same Compose file path, then
loop over these container IDs to inspect their running state. This ensures the
health check targets the correct containers regardless of naming conventions or
container_name overrides.

done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Add a trailing newline

The YAML file is missing a final newline, flagged by yamllint.
Fixing it avoids noisy lint failures.

-          done
\ No newline at end of file
+          done
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
done
done
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 78-78: no new line character at the end of file

(new-line-at-end-of-file)

🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml at line 78, the file
is missing a trailing newline at the end. Add a newline character after the last
line to comply with YAML formatting standards and prevent yamllint warnings.