# See https://aka.ms/yaml
# This pipeline runs to produce GitHub releases when tags are pushed. The
# pipeline is never run from a PR and has access to all the build secrets,
# including write permission to GitHub.

trigger:
  tags:
    include:
      - v*

resources:
  containers:
    - container: azp
      image: ucfconsort.azurecr.io/rdma-core/azure_pipelines:44.0
      endpoint: ucfconsort_registry

stages:
  - stage: Release
    jobs:
      - job: SrcPrep
        displayName: Build Source Tar
        pool:
          vmImage: 'ubuntu-latest'
        container: azp
        steps:
          - checkout: self
            fetchDepth: 1

          - bash: |
              set -e
              git_tag=$(git describe --exact-match HEAD)
              rel_ver=$(echo $git_tag | sed -e 's/^v//')
              echo "Version is $rel_ver"
              echo "##vso[task.setvariable variable=rel_ver]$rel_ver"
              mkdir build-pandoc artifacts
              cd build-pandoc
              CC=gcc-12 cmake -GNinja ..
              ninja docs

              cd ..
              python3 buildlib/cbuild make-dist-tar build-pandoc
            displayName: Prebuild Documentation

          - task: GithubRelease@1
            displayName: 'Create GitHub Release'
            inputs:
              githubConnection: github_release
              repositoryName: linux-rdma/rdma-core
              assets: ./*.tar.gz
              action: create
              title: rdma-core-$(rel_ver)
              isDraft: true
              addChangeLog: true
