Align CI/CD with the platform kit: reusable node-ci, job-network sidecars, and capped bake/migrate CD.
CI / changes (push) Successful in 28s
CI / frontend (push) Failing after 0s
CI / backend (push) Failing after 5m16s

This commit is contained in:
2026-09-30 18:18:56 +08:00
parent d90fc13955
commit e2e70fcb3b
10 changed files with 680 additions and 176 deletions
+141 -105
View File
@@ -1,93 +1,100 @@
# Phase 36 Step 11 — build and test on every push/PR.
# Fixtures read ConnectionStrings__* / Redis__* / RabbitMq__* / Kafka__* from the
# environment (see ApiFixture / GatewayApiFixture). Dependencies come from
# docker-compose.yml so Kafka, ES, and MinIO match local integration tests —
# ApiFixture starts hosted services that require those brokers.
# Backend stays local (onboarding §6 escape hatch): fixtures need RabbitMQ,
# Kafka, Elasticsearch, MinIO, and a second logical DB — beyond stock
# dotnet8-ci (Postgres + Redis services only). Frontend uses shared node-ci.
name: CI
on:
push:
branches: [master]
paths:
- "VigilCareClinicalAPI/**"
- "VigilCare.WardGateway/**"
- "VigilCare.ClinicalContracts/**"
- "VigilCare.ClinicalContracts.Tests/**"
- "VigilCareClinicalAPI.Tests/**"
- "VigilCare.WardGateway.Tests/**"
- "VigilCare.Simulation.Core/**"
- "VigilCare.Simulator/**"
- "vigilcare-dashboard/**"
- "VigilCareClinical.sln"
- "scripts/ci-*.sh"
- ".gitea/workflows/**"
pull_request:
branches: [master]
paths:
- "VigilCareClinicalAPI/**"
- "VigilCare.WardGateway/**"
- "VigilCare.ClinicalContracts/**"
- "VigilCare.ClinicalContracts.Tests/**"
- "VigilCareClinicalAPI.Tests/**"
- "VigilCare.WardGateway.Tests/**"
- "VigilCare.Simulation.Core/**"
- "VigilCare.Simulator/**"
- "vigilcare-dashboard/**"
- "VigilCareClinical.sln"
- "scripts/ci-*.sh"
- ".gitea/workflows/**"
workflow_dispatch:
jobs:
backend:
changes:
runs-on: ubuntu-latest
env:
# Kafka advertises this host on its EXTERNAL listener. The test process runs in
# a job container, so "localhost" (the compose default, correct for a dev box)
# would point the client at itself after bootstrap.
KAFKA_EXTERNAL_HOST: host.docker.internal
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Start dependency stack
- id: filter
name: Detect stack changes
run: |
docker compose up -d postgres redis rabbitmq kafka elasticsearch minio
docker compose --profile ward-gateway up -d ward-gateway-db ward-gateway-redis ward-gateway-rabbitmq
- name: Wait for Postgres (API + gateway)
run: |
for i in $(seq 1 60); do
docker compose exec -T postgres pg_isready -U postgres && break
sleep 2
done
docker compose exec -T postgres pg_isready -U postgres
docker compose exec -T ward-gateway-db pg_isready -U postgres
- name: Wait for Kafka
run: |
for i in $(seq 1 90); do
# Probe the INTERNAL listener: the EXTERNAL one advertises
# host.docker.internal, which does not resolve inside the broker container.
if docker compose exec -T kafka \
/opt/kafka/bin/kafka-broker-api-versions.sh \
--bootstrap-server kafka:29092 >/dev/null 2>&1; then
echo "Kafka is ready"
exit 0
set -euo pipefail
backend=false
frontend=false
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
backend=true
frontend=true
else
if [ "${{ github.event_name }}" = "pull_request" ]; then
base="${{ github.event.pull_request.base.sha }}"
else
base="${{ github.event.before }}"
fi
echo "waiting for Kafka ($i)..."
sleep 2
done
echo "Kafka failed to become ready" >&2
docker compose logs --tail=100 kafka
exit 1
if [ -z "${base:-}" ] || [ "$base" = "0000000000000000000000000000000000000000" ]; then
backend=true
frontend=true
else
files="$(git diff --name-only "$base" "${{ github.sha }}")"
printf '%s\n' "$files"
if printf '%s\n' "$files" | grep -qE '^(VigilCareClinicalAPI/|VigilCare\.WardGateway/|VigilCare\.ClinicalContracts|VigilCareClinicalAPI\.Tests/|VigilCare\.WardGateway\.Tests/|VigilCare\.Simulation\.Core/|VigilCare\.Simulator/|VigilCareClinical\.sln|scripts/ci-|\.gitea/workflows/)'; then
backend=true
fi
if printf '%s\n' "$files" | grep -qE '^(vigilcare-dashboard/|\.gitea/workflows/)'; then
frontend=true
fi
fi
fi
echo "backend=${backend}" >> "$GITHUB_OUTPUT"
echo "frontend=${frontend}" >> "$GITHUB_OUTPUT"
- name: Wait for Redis / RabbitMQ / Elasticsearch
# --user rabbitmq is required: docker exec defaults to root, and Erlang tooling
# creates $HOME/.erlang.cookie mode 400 when it is missing. Probing a broker
# that is still booting would leave a root-owned cookie the server itself
# cannot read, crashing it with "reading .erlang.cookie: eacces".
run: |
for i in $(seq 1 60); do
docker compose exec -T redis redis-cli ping 2>/dev/null | grep -q PONG \
&& docker compose exec -T ward-gateway-redis redis-cli ping 2>/dev/null | grep -q PONG \
&& docker compose exec -T --user rabbitmq rabbitmq rabbitmq-diagnostics -q ping \
&& docker compose exec -T --user rabbitmq ward-gateway-rabbitmq rabbitmq-diagnostics -q ping \
&& docker compose exec -T elasticsearch curl -sf http://localhost:9200/_cluster/health >/dev/null \
&& echo "Redis, RabbitMQ, and Elasticsearch are ready" && exit 0
echo "waiting for brokers ($i)..."
sleep 2
done
echo "Brokers failed to become ready" >&2
docker compose ps
docker compose logs --tail=50 redis rabbitmq elasticsearch ward-gateway-redis ward-gateway-rabbitmq
exit 1
backend:
needs: changes
if: needs.changes.outputs.backend == 'true'
runs-on: ubuntu-latest
steps:
- uses: builtin:checkout
- name: Create test databases
run: |
docker compose exec -T postgres psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='vigilcare_test'" \
| grep -q 1 \
|| docker compose exec -T postgres psql -U postgres -c "CREATE DATABASE vigilcare_test"
docker compose exec -T ward-gateway-db psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='vigilcare_ward_test'" \
| grep -q 1 \
|| docker compose exec -T ward-gateway-db psql -U postgres -c "CREATE DATABASE vigilcare_ward_test"
- name: Start dependency sidecars
run: bash scripts/ci-start-sidecars.sh
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
cache: true
cache-dependency-path: "**/*.csproj"
- name: Restore
run: dotnet restore VigilCareClinical.sln
@@ -95,55 +102,84 @@ jobs:
- name: Build
run: dotnet build VigilCareClinical.sln -c Release --no-restore
- name: Test
- name: Test (isolated — no service database)
env:
# act_runner runs in its own container; Compose publishes ports on the VM.
# host.docker.internal reaches those published ports (requires extra_hosts
# host-gateway on the runner). RabbitMQ guest remote access is enabled in
# infra/rabbitmq/rabbitmq.conf for this topology.
ConnectionStrings__DefaultConnection: "Host=host.docker.internal;Port=5436;Database=vigilcare_test;Username=postgres;Password=password"
ConnectionStrings__GatewayDb: "Host=host.docker.internal;Port=5437;Database=vigilcare_ward_test;Username=postgres;Password=password"
Redis__ConnectionString: "host.docker.internal:6382,defaultDatabase=1,allowAdmin=true"
Gateway__Redis__ConnectionString: "host.docker.internal:6383,defaultDatabase=2,allowAdmin=true"
RabbitMq__Host: "host.docker.internal"
RabbitMq__Port: "5674"
Gateway__RabbitMq__Host: "host.docker.internal"
Gateway__RabbitMq__Port: "5675"
Kafka__BootstrapServers: "host.docker.internal:9092"
ConnectionStrings__DefaultConnection: ""
ConnectionStrings__GatewayDb: ""
Redis__ConnectionString: ""
Gateway__Redis__ConnectionString: ""
RabbitMq__Host: ""
DOTNET_PROCESSOR_COUNT: "1"
DOTNET_gcServer: "0"
DOTNET_GCHeapCount: "1"
GITEA_TOKEN: ""
ASPNETCORE_ENVIRONMENT: Testing
run: |
set -euo pipefail
dotnet test VigilCare.ClinicalContracts.Tests/VigilCare.ClinicalContracts.Tests.csproj \
-c Release --no-build \
--blame-hang-timeout 2m \
--logger "trx;LogFileName=ClinicalContracts.Tests.trx" \
--results-directory ./TestResults \
-- xUnit.MaxParallelThreads=1
- name: Test (against sidecars)
env:
ConnectionStrings__DefaultConnection: "Host=ci-pg;Port=5432;Database=vigilcare_test;Username=postgres;Password=postgres;SSL Mode=Disable"
ConnectionStrings__GatewayDb: "Host=ci-pg;Port=5432;Database=vigilcare_ward_test;Username=postgres;Password=postgres;SSL Mode=Disable"
Redis__ConnectionString: "ci-redis:6379,defaultDatabase=1,allowAdmin=true"
Gateway__Redis__ConnectionString: "ci-redis:6379,defaultDatabase=2,allowAdmin=true"
RabbitMq__Host: "ci-rmq"
RabbitMq__Port: "5672"
RabbitMq__Username: "ciuser"
RabbitMq__Password: "cipass"
Gateway__RabbitMq__Host: "ci-rmq"
Gateway__RabbitMq__Port: "5672"
Kafka__BootstrapServers: "ci-kafka:9092"
Kafka__ReplicationFactor: "1"
Kafka__SecurityProtocol: "Plaintext"
Elasticsearch__Uri: "http://host.docker.internal:9200"
Minio__Endpoint: "host.docker.internal:9005"
Elasticsearch__Uri: "http://ci-es:9200"
Minio__Endpoint: "ci-minio:9000"
Minio__UseSSL: "false"
ASPNETCORE_ENVIRONMENT: "Testing"
ASPNETCORE_ENVIRONMENT: Testing
DOTNET_PROCESSOR_COUNT: "1"
DOTNET_gcServer: "0"
DOTNET_GCHeapCount: "1"
GITEA_TOKEN: ""
run: |
dotnet test VigilCareClinical.sln -c Release --no-build \
--logger "trx;LogFileName=test-results.trx" \
--results-directory ./TestResults
set -euo pipefail
for proj in \
VigilCareClinicalAPI.Tests/VigilCareClinicalAPI.Tests.csproj \
VigilCare.WardGateway.Tests/VigilCare.WardGateway.Tests.csproj
do
name="$(basename "$proj" .csproj)"
echo "::group::$name"
dotnet test "$proj" -c Release --no-build \
--blame-hang-timeout 2m \
--logger "trx;LogFileName=${name}.trx" \
--results-directory ./TestResults \
-- xUnit.MaxParallelThreads=1
echo "::endgroup::"
done
- name: Publish test results
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-results
path: ./TestResults
- name: Tear down stack
- name: Tear down sidecars
if: always()
run: docker compose --profile ward-gateway down -v
run: bash scripts/ci-stop-sidecars.sh
frontend:
runs-on: ubuntu-latest
container:
image: node:22-alpine
steps:
- uses: actions/checkout@v4
- name: Install
working-directory: vigilcare-dashboard
run: npm ci
- name: Test
working-directory: vigilcare-dashboard
run: npm run test
- name: Build
working-directory: vigilcare-dashboard
run: npm run build
needs: changes
if: needs.changes.outputs.frontend == 'true'
uses: infra/ci-workflows/.gitea/workflows/node-ci.yml@v1
with:
working_directory: vigilcare-dashboard
node_version: "22"
lint_command: "true"
extra_check_command: npm run test
build_command: npm run build