diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index 9548c9b8..4c589123 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -36,6 +36,7 @@ stages: dotNetCoreVersion: $(DOTNET_CORE_SDK) checkoutSubmodules: true useVersionSuffix: true + propsFile: 'firely-validator-api.props' packageArtifacts: true restoreDependencies: true nuGetServiceConnections: GitHubPackageGetFeed @@ -49,6 +50,7 @@ stages: dotNetCoreVersion: $(DOTNET_CORE_SDK) checkoutSubmodules: true useVersionSuffix: false + propsFile: 'firely-validator-api.props' packageArtifacts: true restoreDependencies: true nuGetServiceConnections: GitHubPackageGetFeed @@ -73,4 +75,22 @@ stages: parameters: artifact: NuGetPackages source: https://nuget.pkg.github.com/FirelyTeam/index.json - apiKey: $(GITHUB_PACKAGES_APIKEY) \ No newline at end of file + apiKey: $(GITHUB_PACKAGES_APIKEY) + +- stage: deployToNuget + dependsOn: deploy_gitHub + displayName: Deploy packages to NuGet + condition: and(succeeded(), startswith(variables['Build.SourceBranch'], 'refs/tags/v')) + jobs: + - deployment: NuGet + displayName: Publish to Nuget + environment: NuGet + strategy: + runOnce: + deploy: + steps: + - template: push-nuget-package.yml@templates + parameters: + artifact: 'NuGetPackages' + source: https://api.nuget.org/v3/index.json + apiKey: $(NUGET_APIKEY) \ No newline at end of file diff --git a/build/templates/build.yml b/build/templates/build.yml index 9dbceef0..2e0cf8b8 100644 --- a/build/templates/build.yml +++ b/build/templates/build.yml @@ -2,13 +2,15 @@ # File: build.yml parameters: - # Default values - name: dotNetCoreVersion type: string default: '3.1.102' # can also be use with wildcards: latest minor version of 3. , use '3.x' - name: useVersionSuffix type: boolean default: true +- name: propsFile # used for versionSuffix, if not empty, the versionSuffix will be read from the props file + type: string + default: '' - name: restoreDependencies type: boolean default: false @@ -47,23 +49,75 @@ jobs: - checkout: self submodules: true + ## retrieve the version suffix from the props file and set it as a variable + - powershell: | + [string]$propsFile = '${{ parameters.propsFile }}' + [string]$versionSuffix = '' + if ([string]::IsNullOrEmpty($propsFile) -eq $false) + { + $xml = [xml](get-content $propsFile) + #Get the suffix version + $versionSuffix = $xml.Project.PropertyGroup.VersionSuffix + $versionSuffix = $versionSuffix.Trim() + } + Write-Host "Version Suffix: $versionSuffix" + Write-Host "##vso[task.setvariable variable=VersionSuffix]$versionSuffix" + displayName: 'Retrieve version suffix' + + - powershell: | + Write-Host "Updating Build Number to Version Suffix" + [string]$versionSuffix = '$(VersionSuffix)' + if ([string]::IsNullOrEmpty($versionSuffix)) + { + $versionSuffix = $env:BUILD_BUILDNUMBER + } + else + { + $versionSuffix = $versionSuffix + "-" + $env:BUILD_BUILDNUMBER + } + Write-Host "Updated version Suffix: $versionSuffix" + Write-Host "##vso[task.setvariable variable=VersionSuffix]$versionSuffix" + displayName: 'Add buildnumber to version suffix' + condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'true')) + + - powershell: | + Write-Host "Determining if version suffix should be used" + + [string]$useVersionSuffix = 'true' + [string]$versionSuffix = '$(VersionSuffix)' + + Write-Host "Version Suffix: $versionSuffix" + + if ([string]::IsNullOrEmpty($versionSuffix)) + { + $useVersionSuffix = 'false' + } + + Write-Host "Use Version Suffix: $useVersionSuffix" + Write-Host "##vso[task.setvariable variable=UseVersionSuffix]$useVersionSuffix" + displayName: 'Determine version suffix use' + - ${{ if eq(parameters.restoreDependencies, 'true') }}: - template: restore.yml@templates parameters: nuGetServiceConnections: ${{ parameters.nuGetServiceConnections }} nuGetSources: ${{ parameters.nuGetSources }} - - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(build.buildNumber) --no-restore /p:ContinuousIntegrationBuild=true - displayName: 'dotnet build $(buildConfiguration) with version suffix and no restore' - condition: and(succeeded(), and(eq('${{ parameters.useVersionSuffix }}', 'true'), eq('${{ parameters.restoreDependencies }}', 'true'))) - - - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(build.buildNumber) /p:ContinuousIntegrationBuild=true - displayName: 'dotnet build $(buildConfiguration) with version suffix' - condition: and(succeeded(), and(eq('${{ parameters.useVersionSuffix }}', 'true'), eq('${{ parameters.restoreDependencies }}', 'false'))) + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --no-restore /p:ContinuousIntegrationBuild=true + displayName: 'dotnet build $(buildConfiguration) with no restore' + condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'true'), eq(variables.UseVersionSuffix, 'false'))) - - script: dotnet build --configuration $(buildConfiguration) /p:ContinuousIntegrationBuild=true + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) /p:ContinuousIntegrationBuild=true displayName: 'dotnet build $(buildConfiguration)' - condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'false')) + condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'false'), eq(variables.UseVersionSuffix, 'false'))) + + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --no-restore /p:ContinuousIntegrationBuild=true + displayName: 'dotnet build $(buildConfiguration) with version suffix and with no restore' + condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'true'), eq(variables.UseVersionSuffix, 'true'))) + + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) /p:ContinuousIntegrationBuild=true + displayName: 'dotnet build $(buildConfiguration) with version suffix' + condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'false'), eq(variables.UseVersionSuffix, 'true'))) - task: DotNetCoreCLI@2 displayName: 'dotnet test UnitTests' @@ -78,11 +132,13 @@ jobs: - template: package.yml parameters: useVersionSuffix: ${{ parameters.useVersionSuffix }} + versionSuffix: $(VersionSuffix) - ${{ if eq(parameters.publishArtifacts, 'true') }}: - template: publish.yml@templates parameters: useVersionSuffix: ${{ parameters.useVersionSuffix }} + versionSuffix: $(VersionSuffix) publishWebProjects: ${{ parameters.publishWebProjects }} zipAfterPublish: ${{ parameters.zipAfterPublish }} diff --git a/build/templates/package.yml b/build/templates/package.yml index 32372c41..3c44c049 100644 --- a/build/templates/package.yml +++ b/build/templates/package.yml @@ -1,16 +1,50 @@ parameters: # Default values useVersionSuffix: true + versionSuffix: '' steps: + - powershell: | + [string] $versionSuffix = '${{ parameters.versionSuffix }}' + [string] $addBuildNumber = '${{ parameters.useVersionSuffix }}' + + Write-Host "Add Build Number: $addBuildNumber" + + if ([string]::IsNullOrEmpty($versionSuffix) -and $addBuildNumber -eq 'true') + { + $versionSuffix = $env:BUILD_BUILDNUMBER + } + + Write-Host "Version Suffix: $versionSuffix" + Write-Host "##vso[task.setvariable variable=VersionSuffix]$versionSuffix" + displayName: 'Retrieve version suffix for packaging' + + + - powershell: | + Write-Host "Determining if version suffix should be used" + + [string]$useVersionSuffix = 'true' + [string]$versionSuffix = '$(VersionSuffix)' + + Write-Host "Version Suffix: $versionSuffix" + + if ([string]::IsNullOrEmpty($versionSuffix)) + { + $useVersionSuffix = 'false' + } + + Write-Host "Use Version Suffix: $useVersionSuffix" + Write-Host "##vso[task.setvariable variable=UseVersionSuffix]$useVersionSuffix" + displayName: 'Determine version suffix use for packaging' + # Package nugets - - script: dotnet pack --no-build --configuration $(buildConfiguration) --version-suffix $(build.buildNumber) --output $(Build.artifactStagingDirectory)/packages + - script: dotnet pack --no-build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --output $(Build.artifactStagingDirectory)/packages displayName: 'dotnet pack $(buildConfiguration) with version suffix' - condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'true')) + condition: and(succeeded(), eq(variables.UseVersionSuffix, 'true')) - script: dotnet pack --no-build --configuration $(buildConfiguration) --output $(Build.artifactStagingDirectory)/packages displayName: 'dotnet pack $(buildConfiguration)' - condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'false')) + condition: and(succeeded(), eq(variables.UseVersionSuffix, 'false')) - template: codesign-nuget-packages.yml@templates parameters: