# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
- release
pr: none

pool:
  vmImage: 'windows-latest'

variables:
- group: Release Secrets
- name: solution 
  value: '**/*.sln'
- name: archNumber
  value: '86'
- name: architecture
  value: 'x$(archNumber)'
- name: buildPlatform 
  value: 'win-$(architecture)'
- name: buildConfiguration
  value: 'Release'

steps:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '7.0.203'

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: DotNetCoreCLI@2
  displayName: "Build PixiEditor Solution"
  inputs:
    command: 'build'
    projects: 'src/PixiEditor'
    arguments: '-r "$(buildPlatform)" -c $(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: "Build release PixiEditor.UpdateInstaller"
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/PixiEditor.UpdateInstaller.csproj'
    arguments: '-o "UpdateInstaller" -r "$(buildPlatform)" --self-contained=false -p:PublishSingleFile=true -c $(buildConfiguration)'
    zipAfterPublish: false


- task: PowerShell@2
  displayName: "Set tag version"
  inputs:
    filePath: 'assemblyVerReader.ps1'

- task: PowerShell@2
  displayName: Publish PixiEditor
  inputs:
    filePath: 'src/PixiEditor.Builder/build.ps1'
    arguments: '--project-path "$(System.DefaultWorkingDirectory)\src\PixiEditor" --build-configuration "$(buildConfiguration)" --runtime "$(buildPlatform)" -o "$(System.DefaultWorkingDirectory)\Builds\PixiEditor-$(architecture)-light\PixiEditor" --crash-report-webhook-url "$(crash-webhook-url)"'
    workingDirectory: 'src/PixiEditor.Builder'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'Builds\PixiEditor-$(architecture)-light'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: 'PixiEditor.$(TagVersion).$(architecture).zip'
    replaceExistingArchive: true

- task: PublishPipelineArtifact@1
  displayName: "Publish zip artifact"
  inputs:
    targetPath: '$(System.DefaultWorkingDirectory)\PixiEditor.$(TagVersion).$(architecture).zip'
    artifact: 'PixiEditor.$(TagVersion).$(architecture).zip'
    publishLocation: 'pipeline'

- task: CopyFiles@2
  displayName: "Copy updater to PixiEditor target dir"
  inputs:
    SourceFolder: 'UpdateInstaller'
    Contents: '**'
    TargetFolder: 'Builds/PixiEditor-$(architecture)-light/PixiEditor'
    flattenFolders: true

- task: PowerShell@2
  displayName: "Compile installer"
  inputs:
    targetType: 'inline'
    script: '& "$env:userprofile\.nuget\packages\tools.innosetup\6.2.1\tools\ISCC.exe" src\Installer\installer-setup-$(architecture)-light.iss'

- task: PublishPipelineArtifact@1
  displayName: "Publish artifact"
  inputs:
    targetPath: 'src/Installer/Assets/PixiEditor-$(architecture)-light/'
    artifact: 'PixiEditor-setup-$(architecture).exe'
    publishLocation: 'pipeline'

- task: ArchiveFiles@2
  displayName: "Create zipped installer"
  inputs:
    rootFolderOrFile: 'src/Installer/Assets/PixiEditor-$(architecture)-light'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/PixiEditor-$(TagVersion)-setup$(archNumber).zip'
    replaceExistingArchive: true

- task: PublishPipelineArtifact@1
  displayName: "Publish installer zip artifact"
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)/PixiEditor-$(TagVersion)-setup$(archNumber).zip'
    artifact: 'PixiEditor-$(TagVersion)-setup$(archNumber).zip'
    publishLocation: 'pipeline'