#image: chain33-build:latest

before_script:
    - export GO_PROJECT_NAMESPACE="$GOPATH/src/gitlab.33.cn/$CI_PROJECT_NAMESPACE"
    - echo $GO_PROJECT_NAMESPACE
    - mkdir -p $GO_PROJECT_NAMESPACE
    - ln -srf $(pwd) $GO_PROJECT_NAMESPACE
    - export GO_PROJECT_PATH="$GO_PROJECT_NAMESPACE/$CI_PROJECT_NAME"
    - echo $GO_PROJECT_PATH
    - cd $GO_PROJECT_PATH
    - make clean

after_script:
    - make clean

stages:
    - build
    - test
    - deploy
    - fork_test
    - autotest

go_fmt:
    stage: build
    tags:
        - 33cn
    script:
        - make checkgofmt
        - make fmt
    only:
        - master
        - bty_develop

go_lint:
    stage: build
    tags:
        - 33cn
    script:
        - make linter
    only:
        - master
        - bty_develop

go_test:
    stage: test
    tags:
        - 33cn
    script:
        - make docker-compose-down dapp=all
        - make test
    only:
        - master
        - bty_develop

#memory_sanitizer:
#    stage: test
#    script:
#        - export CC=clang-5.0 && make msan
#    only:
#        - master
#        - develop
#        - bty_develop



#code_coverage_report:
#    stage: test
#    script:
#        - make coverhtml
#    only:
#        - master
#        - develop
#        - bty_develop

deploy:
    stage: deploy
    tags:
        - 33cn
    script:
        - make build_ci
        - make docker-compose
        - make docker-compose-down
    only:
        - master
        - bty_develop

deploy_relay:
    stage: deploy
    tags:
        - 33cn
    script:
        - make build_ci
        - make docker-compose proj=relay dapp=relay
        - make docker-compose-down proj=relay dapp=relay
    only:
        - master

deploy_paracross:
    stage: deploy
    tags:
        - 33cn
    script:
        - make build_ci
        - make docker-compose proj=paracross dapp=paracross
        - make docker-compose-down proj=paracross dapp=paracross
    only:
        - master

code_coverage:
    stage: fork_test
    tags:
        - 33cn
    script:
        - if [ -n "${onceEveryday}" ]; then
        - make coverage
        - fi
    only:
        - master
        - bty_develop

fork_test:
    stage: fork_test
    tags:
        - 33cn
    script:
         - if [ -n "${onceEveryday}" ]; then
         - make build_ci
         - make fork-test
         - make docker-compose-down
         - fi
    only:
        - master
        - forkTest

fork_test_privacy:
    stage: fork_test
    tags:
        - 33cn
    script:
         - if [ -n "${onceEveryday}" ]; then
         - make build_ci
         - make fork-test proj=privacy dapp=privacy
         - make docker-compose-down proj=privacy dapp=privacy
         - fi
    only:
        - master
        - forkTest

fork_test_paracross:
    stage: fork_test
    tags:
        - 33cn
    script:
         - if [ -n "${onceEveryday}" ]; then
         - make build_ci
         - make fork-test proj=paracross dapp=paracross
         - make docker-compose-down proj=paracross dapp=paracross
         - fi
    only:
        - master
        - forkTest

##serial run all dapp
fork_test_all:
    stage: fork_test
    tags:
        - 33cn
    script:
         - if [ -n "${onceEveryday}" ]; then
         - make build_ci
         - make fork-test proj=fork dapp=all
         - make docker-compose-down proj=fork dapp=all
         - fi
    only:
        - master
        - forkTest

##serial run all dapp
deploy_test_all:
    stage: fork_test
    tags:
        - 33cn
    script:
         - if [ -n "${onceEveryday}" ]; then
         - make build_ci
         - make docker-compose proj=deploy dapp=all
         - make docker-compose-down proj=deploy dapp=all
         - fi
    only:
        - master
        - forkTest


autotest:
    stage: autotest
    tags:
        - 33cn
    script:
        - if [ -n "${onceEveryday}" ]; then
        - make build_ci
        - make autotest
        - cd build/tools/autotest && ./run-autotest.sh build
        - cd $GO_PROJECT_PATH
        - fi
    when: always
    only:
        - master

