name: ovn-ci-periodic

on:
  schedule:
    - cron:  '0 6 * * *'
  workflow_dispatch:

env:
  GO_VERSION: "1.16.3"
  K8S_VERSION: v1.20.2
  KIND_CLUSTER_NAME: ovn
  KIND_INSTALL_INGRESS: true
  KIND_ALLOW_SYSTEM_WRITES: true
  # This skips tests tagged as Serial
  # Current Serial tests are not relevant for OVN
  PARALLEL: true

jobs:
  build:
    if: github.repository == 'ovn-org/ovn-kubernetes' || github.event_name == 'workflow_dispatch'
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: ${{ env.GO_VERSION }}
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2
      with:
        ref: master

    - name: Build
      run: |
        set -x
        pushd go-controller
           make
           make windows
        popd

    - name: Build docker image
      run: |
        pushd dist/images
          sudo cp -f ../../go-controller/_output/go/bin/ovn* .
          echo "ref: $(git rev-parse  --symbolic-full-name HEAD)  commit: $(git rev-parse  HEAD)" > git_info
          docker build -t ovn-daemonset-f:dev -f Dockerfile.fedora .
          mkdir _output
          docker save ovn-daemonset-f:dev > _output/image.tar
        popd

    - uses: actions/upload-artifact@v2
      with:
        name: test-image
        path: dist/images/_output/image.tar

  k8s:
    if: github.repository == 'ovn-org/ovn-kubernetes' || github.event_name == 'workflow_dispatch'
    name: Build k8s
    runs-on: ubuntu-latest
    steps:

    - name: Set up environment
      run: |
        export GOPATH=$(go env GOPATH)
        echo "GOPATH=$GOPATH" >> $GITHUB_ENV
        echo "$GOPATH/bin" >> $GITHUB_PATH

    - name: Set up Go
      uses: actions/setup-go@v1
      with:
        go-version: ${{ env.GO_VERSION }}

    - name: Install KIND
      run: |
        sudo curl -Lo /usr/local/bin/kind https://github.com/aojea/kind/releases/download/dualstack/kind
        sudo chmod +x /usr/local/bin/kind
        
  e2e-dual:
    if: github.repository == 'ovn-org/ovn-kubernetes' || github.event_name == 'workflow_dispatch'
    name: e2e-dual
    runs-on: ubuntu-latest
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        target:
          - "shard-conformance"
          - "control-plane"
        ha: [ "HA", "noHA" ]
        ipfamily: [ "dualstack" ]
        exclude:
         # Not currently supported but needs to be.
         # See e2e in test.yml
         - {"ipfamily": "dualstack", "target": "control-plane"}
    needs: [build, k8s]
    env:
      JOB_NAME: "${{ matrix.target }}-${{ matrix.ha }}-${{ matrix.ipfamily }}"
      OVN_HA: "${{ matrix.ha == 'HA' }}"
      # Deploy dual stack cluster
      KIND_IPV4_SUPPORT: "${{ matrix.ipfamily == 'IPv4' || matrix.ipfamily == 'dualstack' }}"
      KIND_IPV6_SUPPORT: "${{ matrix.ipfamily == 'IPv6' || matrix.ipfamily == 'dualstack' }}"
    steps:

    - name: Set up Go
      uses: actions/setup-go@v1
      with:
        go-version: ${{ env.GO_VERSION }}
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

    - name: Set up environment
      run: |
        export GOPATH=$(go env GOPATH)
        echo "GOPATH=$GOPATH" >> $GITHUB_ENV
        echo "$GOPATH/bin" >> $GITHUB_PATH

    - name: Install KIND
      run: |
        sudo curl -Lo /usr/local/bin/kind https://github.com/aojea/kind/releases/download/dualstack/kind
        sudo chmod +x /usr/local/bin/kind

    - uses: actions/download-artifact@v2
      with:
        name: test-image
   
    - name: Load docker image
      run: |
        docker load --input image.tar
        
    - name: kind setup
      run: |
        export OVN_IMAGE="ovn-daemonset-f:dev"
        make -C test install-kind

    - name: Run Tests
      run: |
        make -C test ${{ matrix.target }}

    - name: Upload Junit Reports
      if: always()
      uses: actions/upload-artifact@v2
      with:
        name: kind-junit-${{ env.JOB_NAME }}-${{ github.run_id }}
        path: './test/_artifacts/*.xml'

    - name: Export logs
      if: always()
      run: |
        mkdir -p /tmp/kind/logs
        kind export logs --name ${KIND_CLUSTER_NAME} --loglevel=debug /tmp/kind/logs

    - name: Upload logs
      if: always()
      uses: actions/upload-artifact@v2
      with:
        name: kind-logs-${{ env.JOB_NAME }}-${{ github.run_id }}
        path: /tmp/kind/logs
