trigger:
  batch: true
  branches:
    include:
      - master
      - dev*
      - refs/tags/*

pool:
  vmImage: "ubuntu-latest"

variables:
  - group: GithubToken

steps:
  - checkout: self
  - task: GoTool@0
    inputs:
      version: "1.15.5"
  - script: |
      go version
      go mod download
    workingDirectory: $(system.defaultWorkingDirectory)
    displayName: "Fetch sources"
  - script: |
      bazel build --action_env=PATH=$PATH --action_env=GOPATH=$(go env GOPATH) --action_env=GOCACHE=$(go env GOCACHE) --action_env=SPWD=$(pwd) --spawn_strategy local //release:all
    workingDirectory: $(system.defaultWorkingDirectory)
    displayName: "Build Binaries"
  - script: |
      echo $RELEASE_TAG
      ./release/bleedingrelease.sh
    workingDirectory: $(system.defaultWorkingDirectory)
    displayName: "Generate Bleeding Edge Release"
    env:
      WORKDIR: $(system.defaultWorkingDirectory)
      GITHUB_TOKEN: $(GITHUB_TOKEN)
      PRERELEASE: true
      RELEASE_TAG: unstable-$(Build.SourceVersion)
      RELEASE_SHA: $(Build.SourceVersion)
      TRIGGER_REASON: $(Build.SourceBranch)
      GITHUB_REPO_OWNER: v2fly
      GITHUB_REPO_NAME: v2ray-core
  - script: |
      echo $RELEASE_TAG
      ./release/tagrelease.sh
    workingDirectory: $(system.defaultWorkingDirectory)
    displayName: "Generate Tag Release"
    env:
      WORKDIR: $(system.defaultWorkingDirectory)
      GITHUB_TOKEN: $(GITHUB_TOKEN)
      PRERELEASE: true
      RELEASE_TAG: unstable-$(Build.SourceVersion)
      RELEASE_SHA: $(Build.SourceVersion)
      TRIGGER_REASON: $(Build.SourceBranch)
