# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Grid Client Nightly

on:
  schedule:
    - cron: "0 6 * * *"
  workflow_dispatch:
jobs:
  deployment-scripts:
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        network: ["dev", "qa", "test", "main"]
    env:
      NETWORK: ${{ matrix.network }}
      RMB_PROXY: true
      STORE_SECRET: secret
      MNEMONIC: ${{ secrets.MNEMONIC }}
      SSH_KEY: ${{ secrets.SSH_KEY }}

    steps:
      - uses: actions/checkout@v2
        if: ${{ env.NETWORK == 'dev' }}
      - uses: actions/checkout@v2
        if: ${{ env.NETWORK == 'qa' }}
        with:
          ref: refs/tags/v2.0.0
      - uses: actions/checkout@v2
        if: ${{ env.NETWORK == 'test' }}
        with:
          ref: refs/tags/v2.0.0
      - uses: actions/checkout@v2
        if: ${{ env.NETWORK == 'main' }}
        with:
          ref: refs/tags/v2.0.0
      - name: Set up node 18
        uses: actions/setup-node@v2
        with:
          node-version: 18
          cache: "yarn"

      - name: Install deps
        run: |
          sudo apt-get update
          sudo apt-get install -y git libtool tmux redis net-tools
      - name: Install
        run: |
          yarn
          lerna run build --no-private
      - name: Run test dynamic single vm
        id: dynamicsinglevm
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/dynamic_single_vm.ts
      - name: Run test multiple vms
        id: multiplevm
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/multiple_vms.ts
      - name: Run test kubernetes
        id: kubernetes
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/kubernetes.ts
      - name: Run test vm with qsfs
        id: vmqsfs
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/vm_with_qsfs.ts
      - name: Run test kubernetes with qsfs
        id: kubernetesqsfs
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/kubernetes_with_qsfs.ts
      - name: Run test kvstore
        id: kvstore
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/kvstore_example.ts
      - name: Run test zdb
        id: zdb
        continue-on-error: true
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/zdb.ts
      - name: Cleanup - Delete all contracts
        run: |
          yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/delete_all_contracts.ts
      - name: Check test script status
        if: |
          steps.dynamicsinglevm.outcome != 'success' ||
          steps.multiplevm.outcome != 'success' ||
          steps.kubernetes.outcome != 'success' ||
          steps.vmqsfs.outcome != 'success' ||
          steps.kubernetesqsfs.outcome != 'success' ||
          steps.kvstore.outcome != 'success' ||
          steps.zdb.outcome != 'success'
        run: exit "Test scripts failed, Please check the failed step/s."
