name: Essential Test

on:
  push:
  pull_request:
  schedule:
    # Schedule to run everyday at 6PM UTC (2AM CST)
    - cron:  '0 18 * * *'

# Cancel previous running jobs on push or pull request
concurrency:
  group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  Make_test_on_ubuntu:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v1
      with:
        submodules: true
    
    - uses: ./.github/workflows/composite_action/sim
      with:
        container-name: ${{ github.job }}
        build-envs: 'OCCLUM_RELEASE_BUILD=1'

    - name: Check format
      run:  docker exec ${{ github.job }} bash -c 'cd /root/occlum; info=$(make format-check);
        if [[ -n $info ]]; then
          echo "Format error detected.";
          echo "$info";
          exit 1;
        fi'

    - name: Integration test
      run:  docker exec ${{ github.job }} bash -c "cd /root/occlum; OCCLUM_LOG_LEVEL=trace SGX_MODE=SIM make test"

    - name: Integration test with Glibc
      run:  docker exec ${{ github.job }} bash -c "cd /root/occlum; OCCLUM_LOG_LEVEL=trace SGX_MODE=SIM make test-glibc"

    - name: Show failed cases
      if: ${{ failure() }}
      run: docker exec ${{ github.job }} bash -c "cat /root/occlum/build/test/.fail"

  # Make_test_on_centos:
  #   runs-on: ubuntu-18.04

  #   steps:
  #   - uses: actions/checkout@v1
  #     with:
  #       submodules: true

  #   - uses: ./.github/workflows/composite_action/sim
  #     with:
  #       container-name: ${{ github.job }}
  #       build-envs: 'OCCLUM_RELEASE_BUILD=1'
  #       os: 'centos8.2'

  #   - name: Check format
  #     run:  docker exec ${{ github.job }} bash -c 'cd /root/occlum; info=$(make format-check);
  #       if [[ -n $info ]]; then
  #         echo "Format error detected.";
  #         echo "$info";
  #         exit 1;
  #       fi'

  #   - name: Integration test
  #     run:  docker exec ${{ github.job }} bash -c "cd /root/occlum; OCCLUM_LOG_LEVEL=trace SGX_MODE=SIM make test"

  #   - name: Integration test with Glibc
  #     run:  docker exec ${{ github.job }} bash -c "cd /root/occlum; OCCLUM_LOG_LEVEL=trace SGX_MODE=SIM make test-glibc"

  #   - name: Show failed cases
  #     if: ${{ failure() }}
  #     run: docker exec ${{ github.job }} bash -c "cat /root/occlum/build/test/.fail"
