Skip to content

Commit

Permalink
Merge pull request #210 from FirelyTeam/devops/new-version-suffix-logic
Browse files Browse the repository at this point in the history
Devops: ported new version suffix logic
  • Loading branch information
marcovisserFurore authored Dec 11, 2023
2 parents 3b6b5ce + 3fb6a5e commit 78370fb
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 14 deletions.
22 changes: 21 additions & 1 deletion build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ stages:
dotNetCoreVersion: $(DOTNET_CORE_SDK)
checkoutSubmodules: true
useVersionSuffix: true
propsFile: 'firely-validator-api.props'
packageArtifacts: true
restoreDependencies: true
nuGetServiceConnections: GitHubPackageGetFeed
Expand All @@ -49,6 +50,7 @@ stages:
dotNetCoreVersion: $(DOTNET_CORE_SDK)
checkoutSubmodules: true
useVersionSuffix: false
propsFile: 'firely-validator-api.props'
packageArtifacts: true
restoreDependencies: true
nuGetServiceConnections: GitHubPackageGetFeed
Expand All @@ -73,4 +75,22 @@ stages:
parameters:
artifact: NuGetPackages
source: https://nuget.pkg.github.com/FirelyTeam/index.json
apiKey: $(GITHUB_PACKAGES_APIKEY)
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)
76 changes: 66 additions & 10 deletions build/templates/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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 }}

40 changes: 37 additions & 3 deletions build/templates/package.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 78370fb

Please sign in to comment.