name: Func E2E Lifecycle Test

on: [pull_request]

concurrency:
  group: ci-e1e-${{ github.ref }}-1
  cancel-in-progress: true

jobs:
  test:
    name: E2E Test
    continue-on-error: true
    strategy:
      matrix:
        os: [ "ubuntu-latest", "ubuntu-24.04-arm" ]
        runtime: ["go", "quarkus"]
        include:
          - os: ubuntu-latest
            runtime: node
          - os: ubuntu-latest
            runtime: typescript
          - os: ubuntu-latest
            runtime: springboot
          - os: ubuntu-latest
            runtime: rust
          - os: ubuntu-24.04-arm
            arch: arm64
    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 Binaries
        env:
          ARCH: ${{ matrix.arch }}
        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 for ${{matrix.runtime}} ------------------"
            ./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: Build
        run: make
      - name: E2E runtime for ${{ matrix.runtime }}
        run: |
          attempt=0
          max_attempts=5
          until [ $attempt -ge $max_attempts ]
          do
            attempt=$((attempt+1))
            echo "------------------ Attempt $attempt for ${{matrix.runtime}} ------------------"
            make test-e2e-runtime runtime=${{ matrix.runtime }} && break
            echo "------------------ failed, retrying... ------------------"
            if [ $attempt -ge $max_attempts ]; then
              echo "------------------ max # of retries reached, exiting ------------------"
              exit 1
            fi
          done
          echo "------------------ finished! attempt $attempt ------------------"
