name: Test setup script

on:
  push:
    branches:
      - main
    paths:
      - 'docker-compose/**'
      - '.github/workflows/test.yml'

jobs:
  test:
    name: Test setup script
    runs-on: [self-hosted, Linux]
    steps:
      - name: Login to GitHub container registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Create working directory
        run: mkdir temp
      - name: Run setup script
        env:
          DEFGUARD_DOMAIN: "id.localhost"
          DEFGUARD_ENROLLMENT_DOMAIN: "enrollment.localhost"
          DEFGUARD_VPN_NAME: "test_location"
          DEFGUARD_VPN_IP: "10.0.60.1/24"
          DEFGUARD_VPN_GATEWAY_IP: "10.20.20.40"
          DEFGUARD_VPN_GATEWAY_PORT: "50050"
          CORE_IMAGE_TAG: latest
          PROXY_IMAGE_TAG: latest
          GATEWAY_IMAGE_TAG: latest
        working-directory: temp
        run: curl --proto '=https' --tlsv1.2 -sSf -L https://raw.githubusercontent.com/DefGuard/deployment/main/docker-compose/setup.sh | bash -s - --non-interactive
      - name: Sleep for 10 seconds
        working-directory: temp
        run: sleep 10s
      - name: Test defguard is available
        working-directory: temp
        run: curl -f http://id.localhost/api/v1/health
      - name: Stop compose stack
        if: always()
        working-directory: temp
        run: docker-compose down
