# Nightly E2E job. Runs against the docker-dev four-node fleet (admin-a +
# admin-b + driver-a + driver-b + SQL + LDAP + Traefik). Trigger:
#   - cron at 03:00 UTC daily
#   - workflow_dispatch from the Actions UI for on-demand runs
#
# The E2E test project (tests/Server/ZB.MOM.WW.OtOpcUa.E2ETests) does not yet
# exist — it lands when the F-series follow-ups F10/F11/F12 wire enough of the
# SDK/historian/probe so an end-to-end driver round-trip is meaningful. Until
# then this workflow is a green no-op (the `--filter Category=E2E` matches
# zero tests, and `dotnet test` returns 0).

name: v2-e2e

on:
  schedule:
    - cron: "0 3 * * *"
  workflow_dispatch: {}

env:
  DOTNET_NOLOGO: "1"
  DOTNET_CLI_TELEMETRY_OPTOUT: "1"

jobs:

  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 10.0.x

      - name: dotnet restore
        run: dotnet restore ZB.MOM.WW.OtOpcUa.slnx

      - name: Build docker-dev fleet
        run: docker compose -f docker-dev/docker-compose.yml up -d --build

      - name: Wait for cluster
        run: |
          for i in $(seq 1 30); do
            if curl -sf http://localhost/health/active >/dev/null; then
              echo "Admin leader healthy after ${i}s"
              exit 0
            fi
            sleep 2
          done
          echo "Timed out waiting for /health/active"
          docker compose -f docker-dev/docker-compose.yml logs --tail=200
          exit 1

      - name: dotnet test (E2E only)
        run: dotnet test --configuration Release --filter "Category=E2E"

      - name: Tear down
        if: always()
        run: docker compose -f docker-dev/docker-compose.yml down -v
