trigger: none

# needed to disable CI trigger and allow manual trigger
# when the branch is same as pipline source, the latest build from the source is used.
# all environment used are for manual tasks and approvals.

resources:
  pipelines:
  - pipeline: releasePipeline
    source: 'Coordinated Packages'
    trigger:
      branches:
      - release/*

variables:
  - name: runCodesignValidationInjection
    value : false
  - name: NugetSecurityAnalysisWarningLevel
    value: none
  - name: skipComponentGovernanceDetection
    value: true

stages:
- stage: MSIXBundle
  displayName: Create MSIX Bundle package
  dependsOn: []
  jobs:
  - template: templates/release-MsixBundle.yml

- stage: ValidateSDK
  displayName: Validate SDK
  dependsOn: []
  jobs:
  - template: templates/release-SDKTests.yml
    parameters:
      jobName: WinSDK
      displayName: Windows SDK Test
      imageName: windows-latest

  - template: templates/release-SDKTests.yml
    parameters:
      jobName: LinuxSDK
      displayName: Linux SDK Test
      imageName: ubuntu-latest

  - template: templates/release-SDKTests.yml
    parameters:
      jobName: macOSSDK
      displayName: macOS SDK Test
      imageName: macOS-latest

- stage: PRCreation
  displayName: Create PR in GH Master
  dependsOn: []
  jobs:
  - deployment: CreatePRInMaster
    displayName: Update README.md and metadata.json
    pool: server
    environment: PSReleaseCreatePR

- stage: ValidateGlobalTool
  displayName: Validate Global Tool
  dependsOn: []
  jobs:
  - template: templates/release-GlobalToolTest.yml
    parameters:
      jobName: WinGblTool
      displayName: Global Tool Test Windows
      imageName: windows-latest
      globalToolExeName: 'pwsh.exe'
      globalToolPackageName: 'PowerShell.Windows.x64'

  - template: templates/release-GlobalToolTest.yml
    parameters:
      jobName: LinuxWinGblTool
      displayName: Global Tool Test Linux
      imageName: ubuntu-latest
      globalToolExeName: 'pwsh'
      globalToolPackageName: 'PowerShell.Linux.x64'

- stage: StaticPkgValidation
  dependsOn: []
  displayName: Static package validation
  jobs:
  - job: ValidatePkgNames
    displayName: Validate Package Names
    pool:
      vmImage: windows-latest
    variables:
    - group: 'Azure Blob variable group'
    steps:
      - template: templates/release-ValidatePackageNames.yml
  - job: ValidatePkgBOM
    displayName: Validate Package BOM
    pool:
      vmImage: windows-latest
    variables:
    - group: 'Azure Blob variable group'
    steps:
      - template: templates/release-ValidatePackageBOM.yml

- stage: StartDocker
  dependsOn: []
  displayName: Kick Off Docker Staging build
  jobs:
  - deployment: PSDockerKickOff
    displayName: Start Docker build
    pool: server
    environment: PSReleaseDockerKickOff

- stage: ManualValidation
  dependsOn: []
  displayName: Manual Validation
  jobs:
  - deployment: ValidateWinPkg
    displayName: Validate Windows Packages
    pool: server
    environment: PSReleaseWinPkgValidate

  - deployment: ValidateLinuxPkg
    displayName: Validate Linux Packages
    pool: server
    environment: PSReleaseLinuxPkgValidate

- stage: ReleaseAutomation
  displayName: Release Automation
  dependsOn: []
  jobs:
  - deployment: ReleaseAutomationKickOff
    displayName: Kick off release ReleaseAutomation
    pool: server
    environment: PSReleaseAutomationKickOff

- stage: GitHubDraftRelease
  displayName: Create GitHub draft release
  # do not include stages that are likely to fail in dependency as there is no way to force deploy.
  dependsOn:
  - MSIXBundle
  - ValidateSDK
  - PRCreation
  - StaticPkgValidation
  - StartDocker
  - ManualValidation
  - ReleaseAutomation

# The environment here is used for approval.
  jobs:
  - deployment: AzureBlobPublic
    displayName: Make Azure Blob Public
    pool:
      vmImage: windows-latest
    variables:
    - group: 'Staging_ACR'
    environment: PSReleaseAzureBlobPublic
    strategy:
      runOnce:
        deploy:
          steps:
          - template: templates/release-MakeContainerPublic.yml

  - job: GitHubDraft
    displayName: Create GitHub Draft release
    pool:
      vmImage: windows-latest
    variables:
    - group: 'Azure Blob variable group'
    - group: 'AzDevOpsArtifacts'
    dependsOn: AzureBlobPublic
    steps:
    - template: templates/release-CreateGitHubDraft.yml

- stage: GitHubManualTasks
  displayName: GitHub manual tasks
  dependsOn: GitHubDraftRelease
  jobs:
  - deployment: UpdateChangeLog
    displayName: Update Change Log
    pool : server
    environment: PSReleaseUpdateChangeLog

  - deployment: PushTag
    displayName: Push Git Tag
    pool : server
    environment: PSReleasePushTag

  - deployment: MakeDraftPublic
    displayName: Make GitHub Draft public
    pool : server
    environment: PSReleaseDraftPublic

- stage: PublishPackages
  displayName: Publish packages
  dependsOn: GitHubManualTasks
  jobs:
  - job: PublishNuget
    pool:
      vmImage: windows-latest
    steps:
    - template: templates/release-ReleaseToNuGet.yml

  - job: PublishPkgsMsftCom
    pool:
      vmImage: ubuntu-latest
    variables:
    - group: 'AzDevOpsArtifacts'
    - group: 'packages.microsoft.com'
    steps:
    - template: templates/release-PublishPackageMsftCom.yml

- stage: ChangesToMaster
  displayName: Ensure changes are in GH master
  dependsOn: PublishPackages
  jobs:
  - deployment: MergeToMaster
    displayName: Make sure changes are in master
    pool: server
    environment: PSReleaseChangesToMaster

- stage: ReleaseDocker
  displayName: Release Docker
  dependsOn:
    - GitHubManualTasks
  jobs:
  - deployment: ReleaseDocker
    displayName: Release Docker
    pool: server
    environment: PSReleaseDockerRelease

- stage: ReleaseSnap
  displayName: Release Snap
  dependsOn:
    - PublishPackages
    - ChangesToMaster
  jobs:
  - deployment: ReleaseSnap
    displayName: Release Snap
    pool: server
    environment: PSReleaseSnapRelease

- stage: UpdateDotnetDocker
  dependsOn: GitHubManualTasks
  displayName: Update DotNet SDK Docker images
  jobs:
  - deployment: DotnetSDkDocker
    displayName: Update .NET SDK docker images
    pool: server
    environment: PSReleaseUpdateDotnetDocker

- stage: UpdateWinGet
  dependsOn: GitHubManualTasks
  displayName: Add manifest entry to winget
  jobs:
  - deployment: UpdateWinGet
    displayName: Add manifest entry to winget
    pool: server
    environment: PSReleaseUpdateWinGet

- stage: PublishMsix
  dependsOn: GitHubManualTasks
  displayName: Publish MSIX to store
  jobs:
  - deployment: PublishMsix
    displayName: Publish the MSIX Bundle package to store
    pool: server
    environment: PSReleasePublishMsix

- stage: BuildInfoJson
  dependsOn: GitHubManualTasks
  displayName: Upload BuildInfoJson
  jobs:
  - deployment: UploadJson
    displayName: Upload BuildInfoJson
    pool:
      vmImage: windows-latest
    variables:
    - group: 'Azure Blob variable group'
    environment: PSReleaseBuildInfoJson
    strategy:
      runOnce:
        deploy:
          steps:
          - template: templates/release-BuildJson.yml

- stage: ReleaseVPack
  dependsOn: GitHubManualTasks
  displayName: Release VPack
  jobs:
  - deployment: ReleaseVPackManual
    displayName: Release VPack
    pool: server
    environment: PSReleaseVpack

- stage: ReleaseDeps
  dependsOn: GitHubManualTasks
  displayName: Update pwsh.deps.json links
  jobs:
  - template: templates/release-UpdateDepsJson.yml

- stage: ReleaseClose
  displayName: Finish Release
  dependsOn:
  - ReleaseVPack
  - BuildInfoJson
  - UpdateDotnetDocker
  - ReleaseDocker
  - ReleaseSnap
  - ChangesToMaster
  - ReleaseDeps
  jobs:
  - deployment: RetainBuild
    displayName: Retain Build
    pool: server
    environment: PSReleaseRetainBuild

  - deployment: DeleteBranch
    displayName: Delete release branch
    pool: server
    environment: PSReleaseDeleteBranch
