# Copyright the Hyperledger Fabric contributors. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

name: RELEASE-$(Date:yyyyMMdd)$(Rev:.rrr)
trigger: none
pr: none

variables:
  - group: credentials
  - name: GOPATH
    value: $(Agent.BuildDirectory)/go
  - name: GOVER
    value: 1.14.12

stages:
  - stage: BuildBinaries
    dependsOn: []
    displayName: "Build Fabric Binaries"
    jobs:
      - job: Build
        pool:
          vmImage: ubuntu-16.04
        strategy:
          matrix:
            Linux-amd64:
              TARGET: linux-amd64
            MacOS-amd64:
              TARGET: darwin-amd64
            Windows-amd64:
              TARGET: windows-amd64
        steps:
          - template: install_deps.yml
          - checkout: self
            path: 'go/src/github.com/hyperledger/fabric'
            displayName: Checkout Fabric Code
          - script: ./ci/scripts/create_binary_package.sh
            displayName: Compile Binary and Create Tarball
          - publish: release/$(TARGET)/hyperledger-fabric-$(TARGET)-$(RELEASE).tar.gz
            artifact: hyperledger-fabric-$(TARGET)-$(RELEASE).tar.gz
            displayName: Publish Release Artifact

  - stage: BuildAndPushDockerImages
    dependsOn: []
    displayName: "Build and Push Fabric Docker Images"
    jobs:
      - job: Docker
        pool:
          vmImage: ubuntu-16.04
        steps:
          - template: install_deps.yml
          - checkout: self
            path: 'go/src/github.com/hyperledger/fabric'
            displayName: Checkout Fabric Code
          - script: ./ci/scripts/publish_docker.sh
            env:
              DOCKER_PASSWORD: $(DockerHub-Password)
              DOCKER_USERNAME: $(DockerHub-Username)
            displayName: Publish Docker Images

  - stage: DraftRelease
    displayName: "Draft GitHub Release"
    dependsOn:
      - BuildBinaries
      - BuildAndPushDockerImages
    jobs:
      - job: Release
        pool:
          vmImage: ubuntu-16.04
        steps:
          - download: current
            patterns: '*.tar.gz'
            displayName: Download Artifacts
          - checkout: self
          - task: GitHubRelease@0
            inputs:
              action: create
              addChangeLog: true
              assets: $(Pipeline.Workspace)/*amd64*/*
              compareWith: lastFullRelease
              gitHubConnection: hyperledger
              isDraft: true
              releaseNotesFile: release_notes/v$(RELEASE).md
              repositoryName: $(Build.Repository.Name)
              releaseNotesSource: file
              tag: v$(RELEASE)
              tagSource: manual
              title: v$(RELEASE)
            displayName: Draft Release of Fabric
