language: go

go:
- "1.10"

# Skip the install step. Don't `go get` dependencies.
install: skip

notifications:
  email: false

# Skip the script step: Don't execute 'go test'.
script: skip

# Do not execute build on latest tag.
branch:
  except:
    - latest

jobs:
  include:
  - stage: check
    script: ./scripts/prepare-release-assets.sh --helm-lint --directories ./addons --helm-version v2.10.0

  # Creates a release from the tagged version from eny branch
  - stage: deploy
    sudo: required
    services:
      - docker
    before_deploy:
      - if [ -n "$TRAVIS_TAG" ] && [ "$TRAVIS_TAG" != 'latest' ]; then
          ./scripts/generate_changelog.sh ${TRAVIS_TAG} ${TRAVIS_REPO_SLUG};
        fi
      - ./scripts/prepare-release-assets.sh
    after_deploy:
     # Create a branch if the version ends with 0
     - ./scripts/create_release_branch_step.sh $TRAVIS_TAG ${TRAVIS_REPO_SLUG}
    env:
    deploy:
      provider: releases
      skip_cleanup: true
      api_key: $GITHUB_TOKEN
      file_glob: true
      file: "toCopy/*"
      name: $TRAVIS_TAG
      on:
        # Only tagged commit triggers a release deploy
        tags: true

  # Create a latest release from last master commit
  - stage: deploy
    if: (NOT type IN (pull_request)) AND (branch = master)
    before_deploy:
     - ./scripts/create_latest_tag_step.sh ${TRAVIS_REPO_SLUG}
     - ./scripts/prepare-release-assets.sh
    env:
    deploy:
      provider: releases
      overwrite: true
      skip_cleanup: true
      api_key: $GITHUB_TOKEN
      file_glob: true
      file: "toCopy/*"