Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10f7322

Browse files
Dreynor87Chris Wall (WIN SDE)Copilot
authored
Automate Patch and Revision versions using Azure DevOps Variable Library (#6462)
* Automate Patch and Revision versions using Azure DevOps Variable Library Add version automation to the Open (Foundation) repo, mirroring the pattern from the Aggregator repo. Uses a separate '{MajorVersion}-Foundation-Versions' Library to track PatchVersion and Revision across builds. - Add WindowsAppSDK-VersionVariables.yml to load version vars from Library - Add WindowsAppSDK-UpdateLibrary-Job.yml to bump versions after official builds - Update Official/PR/Nightly pipelines to include version templates - Update PackTransportPackage to use Library-based versioning for official builds - Patch only bumps on official builds (not PR or Nightly) Co-authored-by: Copilot <[email protected]> * Remove the system.debug, since parameters.debug is empty * Change name of pipeline run * Respond to Agne 1 * Revert the change to depending on Publish --------- Co-authored-by: Chris Wall (WIN SDE) <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 6d969bc commit 10f7322

8 files changed

Lines changed: 319 additions & 39 deletions

build/AzurePipelinesTemplates/WindowsAppSDK-PackTransportPackage-Stage.yml

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ parameters:
1111
- name: "BuildMockWindowsAppSDK"
1212
type: boolean
1313
default: true
14+
- name: PrOrNightly
15+
displayName: "PR or Nightly"
16+
type: string
17+
default: ''
18+
- name: BuildType
19+
displayName: "Build Type"
20+
type: string
21+
default: 'experimental'
22+
- name: RunUpdateLibraryJob
23+
displayName: "Run the Update Library Variable Group Job"
24+
type: boolean
25+
default: false
1426

1527
stages:
1628
- stage: Pack
@@ -155,37 +167,10 @@ stages:
155167
inputs:
156168
targetType: 'inline'
157169
script: |
158-
$paddedRevision = '$(versionCounter)'
159-
if([int]$(versionCounter) -lt 10)
160-
{
161-
$paddedRevision = '00' + '$(versionCounter)'
162-
}
163-
elseif ([int]$(versionCounter) -lt 100)
164-
{
165-
$paddedRevision = '0' + '$(versionCounter)'
166-
}
167-
Write-Host "paddedRevision " $paddedRevision
168-
169-
if ([int]$(versionCounter) -gt 999)
170-
{
171-
Write-Host "Revision Number limit reach. Please try again the next day"
172-
Write-Host "##vso[task.complete result=Failed;]DONE"
173-
}
174-
175170
$buildType = '$(channel)'
176-
$majorMinorPatchRev = '$(MajorVersion).$(MinorVersion).$(versionMinDate)'
177-
$majorMinorPatchRev = $majorMinorPatchRev + $paddedRevision
178-
179-
if ($env:ComponentType)
180-
{
181-
Write-Host "componentType " $env:ComponentType
182-
$majorMinorPatchRev = $majorMinorPatchRev + $env:ComponentType
183-
}
184-
185-
$version = $majorMinorPatchRev + '-' + $buildType
186171
187-
# If using release versioning, drop the version suffix, which includes a tag & build stamp.
188-
# This should only be done when prepping final release packages.
172+
# All builds (PR, Nightly, Official) use Library-based versioning
173+
$majorMinorPatch = '$(MajorVersion).$(FoundationMinorVersionResolved).$(FoundationPatchVersionResolved)'
189174
190175
if ('${{ parameters.IsOfficial }}' -eq 'true')
191176
{
@@ -209,8 +194,37 @@ stages:
209194
{
210195
$formattedTag = '-' + $versionTag
211196
}
197+
198+
# For stable official builds with no tag: Major.Minor.Patch
199+
# For non-stable official builds: Major.Minor.Patch-tag{Revision}
200+
$revision = '$(Revision)'
201+
if ($buildType -eq "stable" -and [String]::IsNullOrEmpty($formattedTag))
202+
{
203+
$version = $majorMinorPatch
204+
}
205+
elseif (-not [String]::IsNullOrEmpty($revision))
206+
{
207+
$version = $majorMinorPatch + $formattedTag + $revision
208+
}
209+
else
210+
{
211+
$version = $majorMinorPatch + $formattedTag
212+
}
213+
212214
Write-Host "Using Release Versioning"
213-
$version = $majorMinorPatchRev + $formattedTag
215+
}
216+
else
217+
{
218+
# PR/Nightly: Major.Minor.Patch-{NugetBuildTypePrefix}{buildType}{Revision}
219+
# Uses Library version but does NOT update it. Distinguished by prefix + revision.
220+
$versionTag = '$(NugetBuildTypePrefix)' + $buildType
221+
$version = $majorMinorPatch + '-' + $versionTag + '$(Revision)'
222+
}
223+
224+
if ($env:ComponentType)
225+
{
226+
Write-Host "componentType " $env:ComponentType
227+
$version = $version + $env:ComponentType
214228
}
215229
216230
Write-Host 'Component Package Version: ' $version
@@ -262,3 +276,13 @@ stages:
262276
nuGetFeedType: 'internal'
263277
#Note: The project qualifier is always required when using a feed name. Also, do not use organization scoped feeds.
264278
publishVstsFeed: 'ProjectReunion/Project.Reunion.nuget.internal'
279+
280+
- stage: UpdateFoundationLibrary
281+
dependsOn: Pack
282+
condition: and(succeeded('Pack'), eq(${{ parameters.RunUpdateLibraryJob }}, true))
283+
jobs:
284+
- template: WindowsAppSDK-UpdateLibrary-Job.yml
285+
parameters:
286+
jobName: 'UpdateFoundationLibraryJob'
287+
BuildType: ${{ parameters.BuildType }}
288+
PrOrNightly: ${{ parameters.PrOrNightly }}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# This template updates the Azure DevOps Variable Group (Library) for the Open (Foundation) repo
2+
# after a successful official build. It bumps PatchVersion and Revision variables.
3+
# This job should only run on official builds (not PR or Nightly).
4+
5+
parameters:
6+
- name: jobName
7+
displayName: "Job Name"
8+
type: string
9+
default: 'UpdateFoundationLibraryJob'
10+
- name: BuildType
11+
displayName: "Build Type"
12+
type: string
13+
default: 'stable'
14+
- name: PrOrNightly
15+
displayName: "PR or Nightly"
16+
type: string
17+
default: ''
18+
19+
jobs:
20+
- job: ${{ parameters.jobName }}
21+
variables:
22+
ob_outputDirectory: '$(REPOROOT)\out'
23+
ob_artifactBaseName: '${{parameters.jobName}}'
24+
pool:
25+
type: windows
26+
displayName: "Update Foundation Variable Group"
27+
steps:
28+
- script: |
29+
echo MajorVersion : $(MajorVersion)
30+
echo MinorVersion : $(MinorVersion)
31+
echo Revision : $(Revision)
32+
echo FoundationMinorVersionResolved : $(FoundationMinorVersionResolved)
33+
echo FoundationPatchVersionResolved : $(FoundationPatchVersionResolved)
34+
echo FoundationLibraryName : $(FoundationLibraryName)
35+
echo NugetBuildTypePrefix : $(NugetBuildTypePrefix)
36+
displayName: 'Variables'
37+
38+
# Create the next Variable Group if it does not already exist so that when we change the Major version,
39+
# the next build will already have the variable group available.
40+
- task: PowerShell@2
41+
displayName: Create Next Variable Group if Necessary
42+
env:
43+
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
44+
inputs:
45+
targetType: 'inline'
46+
script: |
47+
$NextMajorVersion = [int]$(MajorVersion) + 1
48+
$NextLibraryName = "$NextMajorVersion-Foundation-Versions"
49+
50+
echo "Next Major Version will be $NextMajorVersion, so next Variable Group will be $NextLibraryName"
51+
echo "Checking to see if the next Variable Group exists"
52+
$groupExists = az pipelines variable-group list --query "[?name=='$NextLibraryName']" | ConvertFrom-Json
53+
if ($groupExists.Count -eq 0)
54+
{
55+
echo "Creating Variable Group $NextLibraryName"
56+
az pipelines variable-group create --name "$NextLibraryName" --description "Variable group for Windows App SDK Foundation Major Version $NextMajorVersion" --authorize --variables FoundationMinorVersion=0 FoundationPatchVersion=0 FoundationPreviewRevision=0 FoundationExperimentalRevision=0
57+
}
58+
else
59+
{
60+
echo "Variable Group $NextLibraryName already exists"
61+
}
62+
63+
- task: PowerShell@2
64+
condition: and(ne(variables.FoundationMinorVersionResolved, variables.MinorVersion), eq('${{ parameters.PrOrNightly }}', ''))
65+
displayName: Update FoundationMinorVersion in Variable Group
66+
env:
67+
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
68+
inputs:
69+
targetType: 'inline'
70+
script: |
71+
echo "Updating Foundation Minor Version variable in Variable Group"
72+
$group_id = $(az pipelines variable-group list -p $(System.TeamProject) --group-name $(FoundationLibraryName) --query '[0].id' -o json)
73+
az pipelines variable-group variable update --group-id $group_id --name FoundationMinorVersion --value $(MinorVersion)
74+
75+
- task: PowerShell@2
76+
condition: eq('${{ parameters.PrOrNightly }}', '')
77+
displayName: Update PreviewRevision in Variable Group
78+
env:
79+
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
80+
inputs:
81+
targetType: 'inline'
82+
script: |
83+
echo "Determining if we need to update FoundationPreviewRevision variable in Variable Group"
84+
$NextPreviewRevision = [int]$(FoundationPreviewRevisionResolved)
85+
if ("${{ parameters.BuildType }}" -eq 'preview')
86+
{
87+
$NextPreviewRevision = $NextPreviewRevision + 1
88+
}
89+
90+
if ($NextPreviewRevision -ne '$(FoundationPreviewRevision)')
91+
{
92+
echo "Updating FoundationPreviewRevision variable in Variable Group to $NextPreviewRevision"
93+
$group_id = $(az pipelines variable-group list -p $(System.TeamProject) --group-name $(FoundationLibraryName) --query '[0].id' -o json)
94+
az pipelines variable-group variable update --group-id $group_id --name FoundationPreviewRevision --value $NextPreviewRevision
95+
}
96+
else
97+
{
98+
echo "No update needed for FoundationPreviewRevision variable in Variable Group"
99+
}
100+
101+
- task: PowerShell@2
102+
condition: eq('${{ parameters.PrOrNightly }}', '')
103+
displayName: Update ExperimentalRevision in Variable Group
104+
env:
105+
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
106+
inputs:
107+
targetType: 'inline'
108+
script: |
109+
echo "Determining if we need to update FoundationExperimentalRevision variable in Variable Group"
110+
$NextExperimentalRevision = [int]$(FoundationExperimentalRevisionResolved)
111+
if ("${{ parameters.BuildType }}" -eq "experimental")
112+
{
113+
$NextExperimentalRevision = $NextExperimentalRevision + 1
114+
}
115+
116+
if ($NextExperimentalRevision -ne '$(FoundationExperimentalRevision)')
117+
{
118+
echo "Updating FoundationExperimentalRevision variable in Variable Group to $NextExperimentalRevision"
119+
$group_id = $(az pipelines variable-group list -p $(System.TeamProject) --group-name $(FoundationLibraryName) --query '[0].id' -o json)
120+
az pipelines variable-group variable update --group-id $group_id --name FoundationExperimentalRevision --value $NextExperimentalRevision
121+
}
122+
else
123+
{
124+
echo "No update needed for FoundationExperimentalRevision variable in Variable Group"
125+
}
126+
127+
- task: PowerShell@2
128+
condition: eq('${{ parameters.PrOrNightly }}', '')
129+
displayName: Update FoundationPatchVersion in Variable Group
130+
env:
131+
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
132+
inputs:
133+
targetType: 'inline'
134+
script: |
135+
echo "Determining if we need to update FoundationPatchVersion variable in Variable Group"
136+
$NextPatchVersion = "$(FoundationPatchVersionResolved)"
137+
138+
# Bump patch on stable official builds (when NugetBuildTypePrefix is empty, meaning not PR/Nightly)
139+
if (("${{ parameters.BuildType }}" -eq "stable") -And ('$(NugetBuildTypePrefix)' -eq ''))
140+
{
141+
$NextPatchVersion = [int]$NextPatchVersion + 1
142+
}
143+
elseif ((($(FoundationMinorVersionResolved) -ne 0) -Or ($(FoundationPatchVersionResolved) -ne 0)) -And ('$(NugetBuildTypePrefix)' -eq ''))
144+
{
145+
$NextPatchVersion = [int]$NextPatchVersion + 1
146+
}
147+
148+
if ($NextPatchVersion -ne '$(FoundationPatchVersion)')
149+
{
150+
echo "Updating FoundationPatchVersion variable in Variable Group to $NextPatchVersion"
151+
$group_id = $(az pipelines variable-group list -p $(System.TeamProject) --group-name $(FoundationLibraryName) --query '[0].id' -o json)
152+
az pipelines variable-group variable update --group-id $group_id --name FoundationPatchVersion --value $NextPatchVersion
153+
}
154+
else
155+
{
156+
echo "No update needed for FoundationPatchVersion variable in Variable Group"
157+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This template loads version variables from a per-major-version Azure DevOps Library
2+
# for the Open (Foundation) repo. It mirrors the pattern from the Aggregator repo's
3+
# WindowsAppSDK-VersionVariables.yml but uses a separate "Foundation-Versions" library.
4+
#
5+
# Variables loaded from the library:
6+
# - FoundationMinorVersion: The minor version for Foundation, tracked independently
7+
# - FoundationPatchVersion: The patch version, incremented on each official build
8+
# - FoundationPreviewRevision: The revision for preview official builds
9+
# - FoundationExperimentalRevision: The revision for experimental official builds
10+
#
11+
# All builds (PR, Nightly, Official) use the Library-based version. Only official builds
12+
# update the Library values. PR/Nightly are distinguished by NugetBuildTypePrefix + Revision.
13+
14+
parameters:
15+
- name: PrOrNightly
16+
displayName: "PR or Nightly Identifier"
17+
type: string
18+
default: ''
19+
- name: BuildType
20+
displayName: "Build Type"
21+
type: string
22+
default: 'experimental'
23+
24+
variables:
25+
- template: AzurePipelinesTemplates\WindowsAppSDK-Versions.yml@WindowsAppSDKVersionConfig
26+
- name: FoundationLibraryName
27+
value: ${{ format('{0}-Foundation-Versions', variables.MajorVersion)}}
28+
- group: ${{ variables.FoundationLibraryName }}
29+
- name: FoundationMinorVersionResolved
30+
value: $[coalesce(variables['FoundationMinorVersion'], 0)]
31+
- name: FoundationPatchVersionResolved
32+
value: $[coalesce(variables['FoundationPatchVersion'], 0)]
33+
- name: PRNightlyRevision
34+
value: $[counter(format('{0}-{1}-{2}-{3}', variables.MajorVersion, variables.FoundationMinorVersionResolved, variables.FoundationPatchVersionResolved, variables.NugetBuildTypePrefix), 1)]
35+
- name: FoundationPreviewRevisionResolved
36+
value: $[coalesce(variables['FoundationPreviewRevision'], 0)]
37+
- name: FoundationExperimentalRevisionResolved
38+
value: $[coalesce(variables['FoundationExperimentalRevision'], 0)]
39+
- ${{ if ne(parameters.PrOrNightly, '') }}:
40+
- name: Revision
41+
value: $[variables['PRNightlyRevision']]
42+
- ${{ else }}:
43+
- ${{ if eq(parameters.BuildType, 'experimental') }}:
44+
- name: Revision
45+
value: $[variables['FoundationExperimentalRevisionResolved']]
46+
- ${{ else }}:
47+
- ${{ if eq(parameters.BuildType, 'preview') }}:
48+
- name: Revision
49+
value: $[variables['FoundationPreviewRevisionResolved']]
50+
- ${{ else }}:
51+
- name: Revision
52+
value: ""

build/WindowsAppSDK-CommonVariables.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
parameters:
2+
- name: PrOrNightly
3+
displayName: "PR or Nightly Identifier"
4+
type: string
5+
default: ''
6+
17
variables:
28
_useBuildOutputFromPipeline: $[coalesce(variables.useBuildOutputFromPipeline, variables['System.DefinitionId'] )]
39
_useBuildOutputFromBuildId: $[coalesce(variables.useBuildOutputFromBuildId, variables['Build.BuildId'] )]
@@ -9,10 +15,15 @@ variables:
915
versionCounter: $[counter(variables['versionDate'], 0)]
1016
version: $[format('{0}.{1}.{2}-{3}.{4}', variables['MajorVersion'], variables['MinorVersion'], variables['PatchVersion'], variables['versionDate'], variables['versionCounter'])]
1117
SamplesBranch: "release/experimental" # Used in the Samples Build Compat Test
18+
19+
# Extra nuget version variables for version automation
20+
${{ if ne(parameters.PrOrNightly, '') }}:
21+
NugetBuildTypePrefix: ${{ format('{0}.', parameters.PrOrNightly) }}
22+
${{ else }}:
23+
NugetBuildTypePrefix: ''
1224

1325
#OneBranch Variables
1426
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
15-
system.debug: ${{ parameters.debug }}
1627
ENABLE_PRS_DELAYSIGN: 1
1728
ROOT: $(Build.SourcesDirectory)
1829
REPOROOT: $(Build.SourcesDirectory)

build/WindowsAppSDK-Foundation-DevTest.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# #
1515
#####################################################################################################################################
1616

17-
name: $(version)
18-
1917
# https://aka.ms/obpipelines/triggers
2018
trigger: none
2119

@@ -51,11 +49,18 @@ variables:
5149
- template: WindowsAppSDK-Foundation-TestConfig.yml@WindowsAppSDKConfig
5250
- template: AzurePipelinesTemplates\WindowsAppSDK-Versions.yml@WindowsAppSDKVersionConfig
5351
- template: WindowsAppSDK-CommonVariables.yml
52+
parameters:
53+
PrOrNightly: 'devtest'
54+
- template: AzurePipelinesTemplates\WindowsAppSDK-VersionVariables.yml
55+
parameters:
56+
PrOrNightly: 'devtest'
5457
- name: maxParallelForBuildSamplesCompatJob_x64
5558
value: 20
5659
- name: maxParallelForBuildSamplesCompatJob_arm64
5760
value: 20
5861

62+
name: $(MajorVersion).$(FoundationMinorVersionResolved).$(FoundationPatchVersionResolved)-$(NugetBuildTypePrefix)$(channel)$(Revision)
63+
5964
resources:
6065
repositories:
6166
- repository: templates

0 commit comments

Comments
 (0)