From 4d421a9353ee2924af5876897dd34c7245404504 Mon Sep 17 00:00:00 2001 From: mmsmits Date: Mon, 20 Nov 2023 17:33:44 +0100 Subject: [PATCH 1/5] devops: ported new version suffix logic --- build/azure-pipelines.yml | 2 ++ build/templates/build.yml | 47 +++++++++++++++++++++++++++++-------- build/templates/package.yml | 21 ++++++++++++----- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index 411616e4..2bb30da0 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-tests.props' packageArtifacts: true restoreDependencies: true nuGetServiceConnections: GitHubPackageGetFeed @@ -49,6 +50,7 @@ stages: dotNetCoreVersion: $(DOTNET_CORE_SDK) checkoutSubmodules: true useVersionSuffix: false + propsFile: 'firely-validator-api-tests.props' packageArtifacts: true restoreDependencies: true nuGetServiceConnections: GitHubPackageGetFeed diff --git a/build/templates/build.yml b/build/templates/build.yml index 2b32fbc6..d2d10008 100644 --- a/build/templates/build.yml +++ b/build/templates/build.yml @@ -4,7 +4,8 @@ parameters: # Default values dotNetCoreVersion: '3.1.102' # can also be use with wildcards: latest minor version of 3. , use '3.x' - useVersionSuffix: true + useVersionSuffix: true # if true, the build number will be added as or to the existing version suffix + propsFile: '' # used for versionSuffix, if not empty, the versionSuffix will be read from the props file restoreDependencies: false nuGetServiceConnections: #required when restoreDependies = true nuGetSources: #required when restoreDependies = true @@ -27,23 +28,49 @@ 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')) + - ${{ 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 + displayName: 'dotnet build $(buildConfiguration) with no restore' + condition: and(succeeded(), eq('${{ parameters.restoreDependencies }}', 'true')) - - script: dotnet build --configuration $(buildConfiguration) /p:ContinuousIntegrationBuild=true + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) displayName: 'dotnet build $(buildConfiguration)' - condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'false')) + condition: and(succeeded(), eq('${{ parameters.restoreDependencies }}', 'false')) - task: DotNetCoreCLI@2 displayName: 'dotnet test UnitTests' diff --git a/build/templates/package.yml b/build/templates/package.yml index 32372c41..298a5590 100644 --- a/build/templates/package.yml +++ b/build/templates/package.yml @@ -1,16 +1,25 @@ parameters: # Default values useVersionSuffix: true + versionSuffix: '' steps: - # Package nugets - - script: dotnet pack --no-build --configuration $(buildConfiguration) --version-suffix $(build.buildNumber) --output $(Build.artifactStagingDirectory)/packages - displayName: 'dotnet pack $(buildConfiguration) with version suffix' - condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'true')) + - powershell: | + [string] $versionSuffix = '${{ parameters.versionSuffix }}' + [string] $useVersionSuffix = ${{ parameters.useVersionSuffix }} + + if ([string]::IsNullOrEmpty($versionSuffix) -and $useVersionSuffix -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' - - script: dotnet pack --no-build --configuration $(buildConfiguration) --output $(Build.artifactStagingDirectory)/packages + # Package nugets + - script: dotnet pack --no-build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --output $(Build.artifactStagingDirectory)/packages displayName: 'dotnet pack $(buildConfiguration)' - condition: and(succeeded(), eq('${{ parameters.useVersionSuffix }}', 'false')) - template: codesign-nuget-packages.yml@templates parameters: From 1061aea1e09538c0985e9d258b2b84bc64052d1e Mon Sep 17 00:00:00 2001 From: mmsmits Date: Mon, 20 Nov 2023 18:00:46 +0100 Subject: [PATCH 2/5] forgot two parameters --- build/templates/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/templates/build.yml b/build/templates/build.yml index d2d10008..07456609 100644 --- a/build/templates/build.yml +++ b/build/templates/build.yml @@ -85,11 +85,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 }} From a013f0479938266f8328f821c163bcf8f6a3f2b4 Mon Sep 17 00:00:00 2001 From: mmsmits Date: Tue, 21 Nov 2023 09:00:42 +0100 Subject: [PATCH 3/5] version-suffix parameter cannot be empty --- build/templates/build.yml | 30 ++++++++++++++++++++++++++++-- build/templates/package.yml | 23 +++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/build/templates/build.yml b/build/templates/build.yml index 07456609..22182b0f 100644 --- a/build/templates/build.yml +++ b/build/templates/build.yml @@ -42,6 +42,7 @@ jobs: 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)' @@ -58,6 +59,23 @@ jobs: 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: @@ -66,11 +84,19 @@ jobs: - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --no-restore displayName: 'dotnet build $(buildConfiguration) with no restore' - condition: and(succeeded(), eq('${{ parameters.restoreDependencies }}', 'true')) + condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'true'), eq(variables.UseVersionSuffix, 'false'))) - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) displayName: 'dotnet build $(buildConfiguration)' - condition: and(succeeded(), eq('${{ parameters.restoreDependencies }}', 'false')) + condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'false'), eq(variables.UseVersionSuffix, 'false'))) + + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --no-restore + 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) + 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' diff --git a/build/templates/package.yml b/build/templates/package.yml index 298a5590..35f5c83f 100644 --- a/build/templates/package.yml +++ b/build/templates/package.yml @@ -17,9 +17,32 @@ steps: 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 $(VersionSuffix) --output $(Build.artifactStagingDirectory)/packages + displayName: 'dotnet pack $(buildConfiguration) with version suffix' + 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(variables.UseVersionSuffix, 'false')) - template: codesign-nuget-packages.yml@templates parameters: From afd0773339ca034593d5905ac3c2542c07fa26bb Mon Sep 17 00:00:00 2001 From: mmsmits Date: Tue, 21 Nov 2023 17:56:51 +0100 Subject: [PATCH 4/5] fix displayname --- build/templates/package.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/templates/package.yml b/build/templates/package.yml index 35f5c83f..3c44c049 100644 --- a/build/templates/package.yml +++ b/build/templates/package.yml @@ -6,9 +6,11 @@ parameters: steps: - powershell: | [string] $versionSuffix = '${{ parameters.versionSuffix }}' - [string] $useVersionSuffix = ${{ parameters.useVersionSuffix }} + [string] $addBuildNumber = '${{ parameters.useVersionSuffix }}' - if ([string]::IsNullOrEmpty($versionSuffix) -and $useVersionSuffix -eq 'true') + Write-Host "Add Build Number: $addBuildNumber" + + if ([string]::IsNullOrEmpty($versionSuffix) -and $addBuildNumber -eq 'true') { $versionSuffix = $env:BUILD_BUILDNUMBER } From 3fb6a5e7d884c5723e083840a2731ccb3012bd92 Mon Sep 17 00:00:00 2001 From: Marco Visser Date: Mon, 11 Dec 2023 16:51:12 +0100 Subject: [PATCH 5/5] Some corrections and stage for deploying to NuGet --- build/azure-pipelines.yml | 24 +++++++++++++++++++++--- build/templates/build.yml | 11 +++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index 0d8aeaa9..4c589123 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -36,7 +36,7 @@ stages: dotNetCoreVersion: $(DOTNET_CORE_SDK) checkoutSubmodules: true useVersionSuffix: true - propsFile: 'firely-validator-api-tests.props' + propsFile: 'firely-validator-api.props' packageArtifacts: true restoreDependencies: true nuGetServiceConnections: GitHubPackageGetFeed @@ -50,7 +50,7 @@ stages: dotNetCoreVersion: $(DOTNET_CORE_SDK) checkoutSubmodules: true useVersionSuffix: false - propsFile: 'firely-validator-api-tests.props' + propsFile: 'firely-validator-api.props' packageArtifacts: true restoreDependencies: true nuGetServiceConnections: GitHubPackageGetFeed @@ -75,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 22eb1f75..2e0cf8b8 100644 --- a/build/templates/build.yml +++ b/build/templates/build.yml @@ -8,6 +8,9 @@ parameters: - 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 @@ -100,19 +103,19 @@ jobs: nuGetServiceConnections: ${{ parameters.nuGetServiceConnections }} nuGetSources: ${{ parameters.nuGetSources }} - - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --no-restore + - 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) --version-suffix $(VersionSuffix) + - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) /p:ContinuousIntegrationBuild=true displayName: 'dotnet build $(buildConfiguration)' condition: and(succeeded(), and(eq('${{ parameters.restoreDependencies }}', 'false'), eq(variables.UseVersionSuffix, 'false'))) - - script: dotnet build --configuration $(buildConfiguration) --version-suffix $(VersionSuffix) --no-restore + - 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) + - 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')))