name: Func Podman Test

on: [pull_request]

jobs:
  test:
    name: Podman Test
    strategy:
      matrix:
        os: ["ubuntu-latest"]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Set Environment Variables
        run: |
          echo "KUBECONFIG=${{ github.workspace }}/hack/bin/kubeconfig.yaml" >> "$GITHUB_ENV"
          echo "PATH=${{ github.workspace }}/hack/bin:$PATH" >> "$GITHUB_ENV"
      - uses: actions/checkout@v4
      - uses: knative/actions/setup-go@main
      - name: Install Podman
        run: |
          sudo apt update
          sudo apt install podman -y
          podman info
      - name: Install Binaries
        run: ./hack/install-binaries.sh
      - name: Allocate Cluster
        run: |
          attempt=0
          max_attempts=5
          until [ $attempt -ge $max_attempts ]
          do
            attempt=$((attempt+1))
            echo "------------------ Attempt $attempt ------------------"
            ./hack/allocate.sh && break
            echo "------------------ failed, retrying... ------------------"
            if [ $attempt -ge $max_attempts ]; then
              echo "------------------ max # of retries reached, exiting ------------------"
              exit 1
            fi
            ./hack/delete.sh
            echo "------------------ sleep for 5 minutes ------------------"
            sleep 300
          done
          echo "------------------ finished! attempt $attempt ------------------"
      - name: Local Registry
        run: ./hack/registry.sh
      - name: Setup testing images
        run: ./hack/setup-testing-images.sh
      - name: Integration Test Podman
        env:
          FUNC_REPO_REF: ${{ github.event.pull_request.head.repo.full_name }}
          FUNC_REPO_BRANCH_REF: ${{ github.head_ref }}
        run: ./hack/test-integration-podman.sh

