Skip to content

Commit

Permalink
Merge pull request #85 from FirelyTeam/devops/new-version-suffix-logic
Browse files Browse the repository at this point in the history
DevOps: ported new version suffix logic to local templates
  • Loading branch information
marcovisserFurore authored Nov 27, 2023
2 parents 9aa57bd + 8694286 commit e0ee298
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 14 deletions.
2 changes: 2 additions & 0 deletions build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ stages:
parameters:
dotNetCoreVersion: $(DOTNET_CORE_SDK)
useVersionSuffix: true
propsFile: 'Firely.Fhir.Packages.props'
packageArtifacts: true
restoreDependencies: true
nuGetServiceConnections: GitHubPackageGetFeed
Expand All @@ -43,6 +44,7 @@ stages:
parameters:
dotNetCoreVersion: $(DOTNET_CORE_SDK)
useVersionSuffix: false
propsFile: 'Firely.Fhir.Packages.props'
packageArtifacts: true
restoreDependencies: true
pool:
Expand Down
74 changes: 64 additions & 10 deletions build/templates/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,23 +29,74 @@ 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) /p:ContinuousIntegrationBuild=true --version-suffix $(VersionSuffix) --no-restore
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) /p:ContinuousIntegrationBuild=true --version-suffix $(VersionSuffix)
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) /p:ContinuousIntegrationBuild=true --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) /p:ContinuousIntegrationBuild=true --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'
Expand All @@ -60,11 +112,13 @@ jobs:
parameters:
artifactName: ${{parameters.packageArtifactName}}
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 }}

41 changes: 37 additions & 4 deletions build/templates/package.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
parameters:
# Default values
useVersionSuffix: true
useVersionSuffix: true #add build number to version suffix
versionSuffix: ''
artifactName: 'NuGetPackages'

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 e0ee298

Please sign in to comment.