language: go

go:
  - "1.14"

os:
  - linux

git:
  depth: 1
  quiet: true
  submodules: false

notifications:
  email: false

env:
  global:
    - GO111MODULE=on
    - GOPROXY=https://proxy.golang.org
    - BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"

before_install:
  - echo "current branch is ${BRANCH}"
  - if [ "${BRANCH}" == "master" ]; then travis_terminate 0; fi
  - ls ${BRANCH} && cd ${BRANCH}

stages:
  - name: Tests

jobs:
  include:
    - stage: "Tests"
      name: "go get"
      install: echo "skip"
      script: cd /tmp && go get "github.com/${TRAVIS_REPO_SLUG}/${BRANCH}@${BRANCH}"
      if: |
        (type = push AND branch != hw12_13_14_15_calendar) OR \
        (type = pull_request AND head_branch != hw12_13_14_15_calendar)

    - stage: "Tests"
      name: "Linters"
      install: go install github.com/golangci/golangci-lint/cmd/golangci-lint
      script: golangci-lint run ./...
      if: |
        (type = push AND branch != hw12_13_14_15_calendar) OR \
        (type = pull_request AND head_branch != hw12_13_14_15_calendar)

    - stage: "Tests"
      name: "Unit tests"
      install: go mod download
      script: go test -v -count=1 -race -gcflags=-l -timeout=30s ./...
      if: |
        (type = push AND branch != hw12_13_14_15_calendar) OR \
        (type = pull_request AND head_branch != hw12_13_14_15_calendar)

    - stage: "Tests"
      name: "Optimization tests"
      install: go mod download
      script: go test -v -count=1 -timeout=30s -tags bench ./...
      if: |
        (type = push AND branch == hw10_program_optimization) OR \
        (type = pull_request AND head_branch == hw10_program_optimization)

    - stage: "Tests"
      name: "Bash tests"
      install: echo "skip"
      script: ./test.sh
      if: |
        (type = push AND branch IN (hw07_file_copying, hw08_envdir_tool, hw09_generator_of_validators, hw11_telnet_client)) OR \
        (type = pull_request AND head_branch IN (hw07_file_copying, hw08_envdir_tool, hw09_generator_of_validators, hw11_telnet_client))

    - stage: "Tests"
      name: "Makefile"
      install: go mod download
      script:
        - make lint
        - make test
        - make build
      if: |
        (type = push AND branch == hw12_13_14_15_calendar) OR \
        (type = pull_request AND head_branch == hw12_13_14_15_calendar)
