# Reference GitHub Actions workflow — copy into a platform repo.
# This file is not wired into this operator's own CI.
#
# Each matrix.context is one cluster. fail-fast is false so one red
# cluster does not hide the rest. Upload the JUnit / diff JSON as
# artifacts for a test reporter or PR review.
name: convctl fleet

on:
  pull_request:
    paths:
      - "**/xrdconversionconfig.yaml"
      - "**/crdconversionconfig.yaml"
      - ".github/workflows/convctl-fleet.yml"

permissions:
  contents: read

jobs:
  fleet:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        context: [prod-us, prod-eu]
    steps:
      - uses: actions/checkout@v4

      - name: Install convctl
        run: |
          # Pin to a released convctl, or build from this repo:
          # go install github.com/terasky-oss/declarative-conversion-operator/cmd/convctl@latest
          echo "install convctl and place it on PATH" >&2
          exit 1

      - name: Write kubeconfig
        env:
          KUBECONFIG_B64: ${{ secrets.FLEET_KUBECONFIG }}
        run: |
          mkdir -p "${HOME}/.kube"
          printf '%s' "${KUBECONFIG_B64}" | base64 -d > "${HOME}/.kube/config"
          chmod 600 "${HOME}/.kube/config"

      - name: convctl diff --live
        # Exit 1 is a coverage/claim delta (review artifact). Exit 2 is a
        # usage/cluster error and must fail the job.
        run: |
          mkdir -p fleet-out
          set +e
          convctl diff --config path/to/xrdconversionconfig.yaml --live \
            --context "${{ matrix.context }}" -o json \
            > "fleet-out/${{ matrix.context }}.diff.json"
          rc=$?
          if [ "${rc}" -eq 2 ]; then exit 2; fi
          exit 0

      - name: convctl test --live
        if: ${{ always() }}
        run: |
          convctl test --config path/to/xrdconversionconfig.yaml \
            --xrd path/to/xrd.yaml --live \
            --context "${{ matrix.context }}" \
            --output junit --output-file "fleet-out/${{ matrix.context }}.junit.xml"

      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: convctl-${{ matrix.context }}
          path: fleet-out/
