ckb 0.39.1

CKB is the layer 1 of Nervos Network, a public/permissionless blockchain.
trigger:
  branches:
    include:
    - '*'
  tags:
    exclude:
    - '*'

variables:
  CKBClientVersion: v0.39.0

jobs:
  - job: UnitTest
    condition: |
      and(
        not(startsWith(variables['Build.SourceBranch'], 'refs/tags/')),
        or(
          and(
            eq(variables['Build.Reason'], 'PullRequest'),
            ne(variables['System.PullRequest.SourceBranch'], 'develop')
          ),
          eq(variables['Build.SourceBranch'], 'refs/heads/master')
        )
      )
    pool:
      vmImage: 'windows-2019'
    steps:
      - template: devtools/azure/windows-dependencies.yml
        parameters:
          rustup_toolchain: '1.46.0-x86_64-pc-windows-msvc'
      - pwsh: devtools/windows/make test
        displayName: Run unit tests
        env:
          CI: true

  - job: IntegrationTest
    timeoutInMinutes: 0
    condition: |
      and(
        not(startsWith(variables['Build.SourceBranch'], 'refs/tags/')),
        ne(variables['Build.Reason'], 'PullRequest'),
        or(
          startsWith(variables['Build.SourceBranch'], 'refs/heads/rc/'),
          in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/develop', 'refs/heads/staging2', 'refs/heads/trying')
        )
      )
    pool:
      vmImage: 'windows-2019'
    steps:
      - template: devtools/azure/windows-dependencies.yml
        parameters:
          rustup_toolchain: '1.46.0-x86_64-pc-windows-msvc'
      - pwsh: devtools/windows/make CKB_TEST_SEC_COEFFICIENT=5 CKB_TEST_ARGS="--max-time 1200 -c 4" integration
        displayName: Run integration tests
        env:
          CI: true

  - job: Package
    timeoutInMinutes: 0
    condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/pkg/')
    pool:
      vmImage: 'windows-2019'
    steps:
      - template: devtools/azure/windows-dependencies.yml
        parameters:
          rustup_toolchain: '1.46.0-x86_64-pc-windows-msvc'
      - pwsh: devtools/windows/make prod
        displayName: Build
      - script: |
          curl -LO https://github.com/nervosnetwork/ckb-cli/releases/download/$(CKBClientVersion)/ckb-cli_$(CKBClientVersion)_x86_64-pc-windows-msvc.zip
        displayName: Download ckb-cli
      - pwsh: |
          mkdir ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc
          cp -r target/release/ckb.exe,README.md,CHANGELOG.md,COPYING,docs ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc
          cp devtools/windows/ckb-init-mainnet.bat,devtools/windows/ckb-reinit-mainnet.bat,devtools/windows/ckb-run.bat ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc
          cp rpc/README.md ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc/docs/rpc.md
          unzip ckb-cli_$(CKBClientVersion)_x86_64-pc-windows-msvc.zip
          mv ckb-cli_$(CKBClientVersion)_x86_64-pc-windows-msvc/ckb-cli.exe ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc/
        displayName: Prepare archive
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: 'ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc'
          archiveFile: '$(Build.ArtifactStagingDirectory)/ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc.zip'
      - script: |
          scoop bucket add extras
          scoop install gpg4win
        displayName: Install GPG4Win
      - task: DownloadSecureFile@1
        inputs:
          secureFile: azure-secret.asc
      - script: |
          set PATH=%PATH%;%ProgramFiles(x86)%/GnuPG/bin
          gpg --import %DOWNLOADSECUREFILE_SECUREFILEPATH%
          echo "##vso[task.setvariable variable=PATH;]%PATH%;%ProgramFiles(x86)%/GnuPG/bin"
        displayName: Setup GPG
      - script: |
          gpg -u "Nervos Azure Builder <bot@nervos.org>" -ab "$(Build.ArtifactStagingDirectory)/ckb_$(Build.SourceBranchName)_x86_64-pc-windows-msvc.zip"
        displayName: Sign Archive
      - task: GitHubRelease@0
        inputs:
          gitHubConnection: nervos-bot
          repositoryName: nervosnetwork/ckb
          action: edit
          tag: $(Build.SourceBranchName)
          assets: |
            $(Build.ArtifactStagingDirectory)/*.zip
            $(Build.ArtifactStagingDirectory)/*.asc
          assetUploadMode: replace
          isDraft: true
          addChangeLog: false