name: Tests
on:
  pull_request:
    branches:
      - '*'
  push:
    branches:
      - main
      - release/**

env:
  DOCKER_HOST: unix:///var/run/dind.sock

jobs:
  sdk_tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Checkout laconicd
        uses: actions/checkout@v3
        with:
          path: "./laconicd/"
          repository: cerc-io/laconicd
          fetch-depth: 0
          ref: main
      - name: Environment
        run: ls -tlh && env

      - name: Start dockerd
        run: |
          dockerd -H $DOCKER_HOST --userland-proxy=false &
          sleep 5

      - name: Build laconicd container
        working-directory: laconicd/tests/sdk_tests
        run: ./build-laconicd-container.sh
      - name: Build sdk container
        run: ./scripts/build-sdk-test-container.sh

      - name: Start containers
        working-directory: laconicd/tests/sdk_tests
        run: docker compose up -d
      - name: Run tests
        working-directory: laconicd/tests/sdk_tests
        run: ./run-tests.sh

      - name: Start containers (auctions enabled)
        working-directory: laconicd/tests/sdk_tests
        env:
          TEST_AUCTION_ENABLED: true
        run: docker compose up -d
      - name: Run auction tests
        working-directory: laconicd/tests/sdk_tests
        run: ./run-tests.sh test:auctions

      - name: Start containers (expiry enabled)
        working-directory: laconicd/tests/sdk_tests
        env:
          TEST_REGISTRY_EXPIRY: true
        run: docker compose up -d
      - name: Run nameservice expiry tests
        working-directory: laconicd/tests/sdk_tests
        run: ./run-tests.sh test:nameservice-expiry

      - name: Start containers (onboarding enabled)
        working-directory: laconicd/tests/sdk_tests
        env:
          ONBOARDING_ENABLED: true
        run: docker compose up -d
      - name: Run participants onboarding tests
        working-directory: laconicd/tests/sdk_tests
        run: ./run-tests.sh test:onboarding