name: Run test cases

on:
    push:
    pull_request:
    release:
        types:
            - published

jobs:
    run_test_case:
        runs-on: ubuntu-latest

        container:
            image: golang:1.14

        steps:
        - uses: actions/checkout@v2
        - name: run code static check
          run : |
            if [ ! -z "$(gofmt -l .)" ];then
              echo "code static check error"
              gofmt -l .
              exit 1
            fi
        - name: install lib
          run: apt-get update && apt-get install libzmq3-dev -y
        - name: run test case
          run: |
            set -e -u -x
            mkdir -p data
            mkdir -p log
            sed -i -r "s/debug: .*/debug: true/1" etc/kuiper.yaml
            go build --buildmode=plugin -o plugins/sources/Random@v2.0.0.so plugins/sources/random.go
            go build --buildmode=plugin -o plugins/sinks/File@v1.0.0.so plugins/sinks/file.go
            go build --buildmode=plugin -o plugins/functions/Echo.so plugins/functions/echo.go
            go build --buildmode=plugin -o plugins/functions/CountPlusOne@v1.0.0.so plugins/functions/countPlusOne.go
            go build --buildmode=plugin -o plugins/functions/AccumulateWordCount@v1.0.0.so plugins/functions/accumulateWordCount.go
            go test --tags=edgex ./...
        - uses: actions/upload-artifact@v1
          if: failure()
          with:
            name: stream.log
            path: log/stream.log
