name: Deploy and Test Volumes Web Application
on:
  pull_request:
    paths:
    - tests/install_KinD_create_KinD_cluster_install_kustomize.sh
    - .github/workflows/volumes_web_application_test.yaml
    - applications/volumes-web-app/upstream/**
    - tests/istio*
    - common/istio*/**
    - common/oauth2-proxy/**
    - tests/oauth2-proxy_install.sh
    - tests/multi_tenancy_install.sh
    - tests/volumes_web_application_install.sh
    - tests/volumes_web_application_test.sh

permissions:
  contents: read
  actions: read

env:
  KF_PROFILE: kubeflow-user-example-com

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Install KinD, Create KinD cluster and Install kustomize
      run: ./tests/install_KinD_create_KinD_cluster_install_kustomize.sh

    - name: Install kubectl
      run: ./tests/kubectl_install.sh

    - name: Create Kubeflow Namespace
      run: kustomize build common/kubeflow-namespace/base | kubectl apply -f -

    - name: Install Certificate Manager
      run: ./tests/cert_manager_install.sh

    - name: Install Istio CNI
      run: ./tests/istio-cni_install.sh

    - name: Install OAuth2 Proxy
      run: ./tests/oauth2-proxy_install.sh

    - name: Install Kubeflow Istio Resources
      run: kustomize build common/istio/kubeflow-istio-resources/base | kubectl apply -f -

    - name: Install Multi-Tenancy
      run: ./tests/multi_tenancy_install.sh

    - name: Create KF Profile
      run: ./tests/kubeflow_profile_install.sh

    - name: Install Volumes Web Application
      run: ./tests/volumes_web_application_install.sh

    - name: Wait for VWA Pods
      run: |
        kubectl wait --for=condition=Ready pods --all -n kubeflow --timeout 300s
        sleep 15

    - name: Port-forward the istio-ingress gateway
      run: ./tests/port_forward_gateway.sh

    - name: Test Volumes Web Application API
      run: ./tests/volumes_web_application_test.sh "${KF_PROFILE}"
