name: build
on: [push,pull_request]

jobs:
  check_fmt:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Intsall Golangci-lint
        run: |
          # add executables installed with go get to PATH
          # TODO: this will hopefully be fixed by
          # https://github.com/actions/setup-go/issues/14
          export PATH=${PATH}:`go env GOPATH`/bin
          echo $GOPATH
          echo $PATH
          go get -u golang.org/x/tools/cmd/goimports
          go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.18.0
          go get -u mvdan.cc/sh/cmd/shfmt
          go get -u mvdan.cc/sh/cmd/gosh

      - name: Lint
        run: |
          make largefile-check
          make checkgofmt && make fmt_go
          make linter

  unit-test:
    name: unit-test
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: unit-test
        run: make test

  coverage:
    name: coverage
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: ut coverage
        run: make coverage
      - name: cover report
        if: success()
        run: bash <(curl -s https://codecov.io/bash)

  autotest:
    name: autotest
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: deploy
        run: |
          make build_ci
          make autotest dapp=all

  ci_base:
    name: ci_base
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: deploy
        run: |
          make docker-compose
          make docker-compose-down

  ci_relay:
    name: ci_relay
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: deploy
        run: |
          make docker-compose dapp=relay
          make docker-compose-down dapp=relay

  ci_paracross:
    name: ci_paracross
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: deploy
        run: |
          make docker-compose dapp=paracross
          make docker-compose-down dapp=paracross

  ci_paracross_bls:
    name: ci_paracross_bls
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: set go env
        run: export PATH=${PATH}:`go env GOPATH`/bin
      - name: checkout
        uses: actions/checkout@v2
      - name: deploy
        run: |
          make docker-compose dapp=paracross extra=1
          make docker-compose-down dapp=paracross

  ci_x2ethereum:
    name: ci_x2ethereum
    runs-on: ubuntu-latest
    steps:
      - name: Set up Golang
        uses: actions/setup-go@v2
        with:
          go-version: 1.14
        id: go
      - name: checkout
        uses: actions/checkout@v2
      - name: deploy
        run: |
          export GOPATH=$HOME/go
          export PATH=${PATH}:`go env GOPATH`/bin
          echo $GOPATH
          make
          make docker-compose dapp=x2ethereum
          make docker-compose-down dapp=x2ethereum



