# Universal Windows Platform pipeline config

trigger:
  branches:
    include:
      - master
  paths:
    exclude:
      - '*'
    include:
      - changelogs/windows.json

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Release'
  outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
  buildPlatform: 'x86|x64|ARM'

steps:
- task: NuGetToolInstaller@1
  displayName: 'Install NuGet Tool'

- task: NuGetCommand@2
  displayName: 'Restore Solution'
  inputs:
    restoreSolution: '**/*.sln'

- task: PowerShell@2
  displayName: 'Update version number'
  inputs:
    targetType: 'inline'
    script: |
      (Get-Content Package.appxmanifest -encoding UTF8 | Out-String) -replace '(?<=\bVersion=")[^"]*', "$(Get-Date -Format "yy")$((Get-Date).DayOfYear.ToString('000')).$(Build.BuildId).0" | set-content Package.appxmanifest -encoding UTF8
    workingDirectory: '$(Build.SourcesDirectory)\GUT.Schedule\GUTSchedule.UWP'

- task: DownloadSecureFile@1
  name: assoc
  displayName: 'Downloading Store association data file'
  inputs:
    secureFile: 'PackageStoreAssociation.xml'

- task: CopyFiles@2
  displayName: 'Copy Store association data'
  inputs:
    Contents: '$(assoc.secureFilePath)'
    TargetFolder: '$(Build.Repository.LocalPath)/GUTSchedule/GUTSchedule.UWP'

- task: DownloadSecureFile@1
  name: cert
  displayName: 'Downloading PFX certificate file'
  inputs:
    secureFile: 'GUTScheduleCert.pfx'

- task: VSBuild@1
  inputs:
    platform: 'x86'
    solution: '**/**.UWP.csproj'
    configuration: '$(buildConfiguration)'
    msbuildArgs: '/p:AppxBundlePlatforms="$(buildPlatform)"
                  /p:AppxPackageDir="$(Build.ArtifactStagingDirectory)\AppxPackages" 
                  /p:AppxBundle=Always
                  /p:UapAppxPackageBuildMode=StoreUpload
                  /p:AppxPackageSigningEnabled=true
                  /p:PackageCertificateKeyFile="$(cert.secureFilePath)"
                  /p:PackageCertificatePassword=$(certPassword)
                  /p:PackageCertificateThumbprint=""'

- task: CopyFiles@2
  displayName: 'Copy changelog to output'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/changelogs'
    Contents: 'windows.json'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Drop Artifact'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'WindowsBundle'
    publishLocation: 'Container'