if: repo = AdguardTeam/AdGuardHome
language: go
sudo: false

go:
  - 1.14.x
os:
  - linux
  - osx
  - windows

before_install:
  - |-
    case $TRAVIS_OS_NAME in
      linux | osx)
        nvm install node
        npm install -g npm
        curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.23.8
        ;;
      windows)
        # Using NVS for managing Node.js versions on Windows
        NVS_HOME="C:\ProgramData\nvs"
        git clone --single-branch https://github.com/jasongin/nvs $NVS_HOME
        source $NVS_HOME/nvs.sh
        nvs add latest
        nvs use latest
        ;;
    esac

install:
  - |-
    case $TRAVIS_OS_NAME in
      linux | osx)
        node --version
        npm --version
        npm --prefix client ci
        ;;
      windows)
        node --version
        npm --version
        nvs --version
        npm --prefix client ci
        ;;
    esac

cache:
  directories:
    - $HOME/.cache/go-build
    - $HOME/gopath/pkg/mod
    - $HOME/Library/Caches/go-build

script:
  - |-
    case $TRAVIS_OS_NAME in
      linux | osx)
        /bin/bash ci.sh
        ;;
      windows)
        npm --prefix client run build-prod
        go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
        ;;
    esac

after_success:
  - |-
    case $TRAVIS_OS_NAME in
      linux)
        bash <(curl -s https://codecov.io/bash)
        ;;
    esac

notifications:
  slack: performix:yXTihlSzsLFSZiqbXMNzvTSX

matrix:
  include:
    # Release build configuration
    - if: repo = AdguardTeam/AdGuardHome
    - name: release
      go:
        - 1.14.x
      os:
        - linux

      script:
        - node -v
        - npm -v
        # Prepare releases
        - ./build_release.sh
        - ls -l dist

      deploy:
        provider: releases
        api_key: $GITHUB_TOKEN
        file:
          - dist/AdGuardHome_*
        on:
          repo: AdguardTeam/AdGuardHome
          tags: true
        draft: true
        file_glob: true
        skip_cleanup: true

    # Docker build configuration
    - if: repo = AdguardTeam/AdGuardHome
    - name: docker
      if: type != pull_request AND (branch = master OR tag IS present) AND repo = AdguardTeam/AdGuardHome
      go:
        - 1.14.x
      os:
        - linux
      services:
        - docker
      before_script:
        - nvm install node
        - npm install -g npm
      script:
        - docker login -u="$DOCKER_USER" -p="$DOCKER_PASSWORD"
        - ./build_docker.sh
      after_script:
        - docker images