name: Func Podman Next Test

on:
  schedule:
    - cron: '0 2 * * *'

jobs:
  test:
    name: Podman Next Test
    strategy:
      matrix:
        os: ["ubuntu-latest"]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Remove Unnecessary Software
        run: |
          sudo rm -rf /usr/share/dotnet || true
          sudo rm -rf /usr/local/lib/android || true
          sudo rm -rf /opt/ghc || true
      - name: Install Podman Next (Nightly Build)
        env:
          FEDORA_RELEASE: 41
          BASE_ARCH: x86_64
        run: |
          sudo apt update 
          sudo mkdir -p /etc/yum.repos.d
          sudo apt install dnf -y
          sudo apt install dnf-plugins-core -y
          sudo apt install alien -y
          sudo touch /etc/yum.repos.d/fedora.repo
          sudo chmod 666 /etc/yum.repos.d/fedora.repo
          cat << EOF >> /etc/yum.repos.d/fedora.repo
          [fedora]
          name=Fedora $FEDORA_RELEASE
          metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$FEDORA_RELEASE&arch=$BASE_ARCH
          enabled=1
          countme=1
          metadata_expire=7d
          repo_gpgcheck=0
          type=rpm
          gpgcheck=0
          EOF
          sudo chmod 644 /etc/yum.repos.d/fedora.repo
          sudo dnf copr enable rhcontainerbot/podman-next fedora-$FEDORA_RELEASE-$BASE_ARCH --releasever=$FEDORA_RELEASE -y
          sudo dnf download crun conmon podman --releasever=$FEDORA_RELEASE -y
          sudo alien --to-deb $(ls -1 crun*.rpm) --install
          sudo alien --to-deb $(ls -1 conmon*.rpm) --install
          sudo alien --to-deb $(ls -1 podman*.rpm) --install
          podman info
      - 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
        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
