Skip to content

Commit d058daf

Browse files
committed
Adjust build process to tag builds with package info
Use normal cloud build number as primary release tag. Add packages and versions to release notes.
1 parent c74b0f0 commit d058daf

File tree

5 files changed

+240
-15
lines changed

5 files changed

+240
-15
lines changed

MSBuild.SDK.SystemWeb.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{A4372060
1616
.gitignore = .gitignore
1717
azure-pipelines.yml = azure-pipelines.yml
1818
cloud3d-codesign.snk = cloud3d-codesign.snk
19+
build\ConvertTo-MarkdownTable.ps1 = build\ConvertTo-MarkdownTable.ps1
20+
build\DetectPackages.ps1 = build\DetectPackages.ps1
1921
Directory.Build.Props = Directory.Build.Props
2022
Directory.Build.Targets = Directory.Build.Targets
2123
global.json = global.json

azure-pipelines.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,10 @@ steps:
125125
- task: PowerShell@2
126126
displayName: 'Detect packages'
127127
inputs:
128-
targetType: inline
129-
script: |
130-
$dir = $env:BUILD_ARTIFACTSTAGINGDIRECTORY + "\*.nupkg"
131-
Write-Host "Package Directory: $dir"
132-
$packages = Get-ChildItem -Path $dir -Recurse
133-
$ids = $packages | Select-Object -ExpandProperty name
134-
Write-Host "Packages: $ids"
135-
Write-Host "Package Count: $($packages.Count)"
136-
Write-Host ("##vso[task.setvariable variable=package_count;]$($packages.Count)")
128+
targetType: filePath
129+
filePath: 'build/DetectPackages.ps1'
130+
env:
131+
branchName: $(variables['branchName'])
137132

138133
# Run the signing command
139134
- task: PowerShell@2
@@ -221,7 +216,7 @@ steps:
221216
displayName: Tag build
222217
env:
223218
BuildNumber: $(Build.BuildNumber)
224-
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
219+
condition: and(succeeded(), eq(variables['branchName'], 'main'))
225220

226221
- task: GithubRelease@1
227222
displayName: 'Create GitHub Release'
@@ -231,3 +226,5 @@ steps:
231226
repositoryName: CZEMacLeod/MSBuild.SDK.SystemWeb
232227
assets: $(Build.ArtifactStagingDirectory)/*.nupkg
233228
addChangeLog: true
229+
releaseNotesSource: filePath
230+
releaseNotesFilePath: $(Build.ArtifactStagingDirectory)/ReleaseNotes.md

build/ConvertTo-MarkdownTable.ps1

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
function ConvertTo-MarkdownTable {
2+
<#
3+
.SYNOPSIS
4+
Converts a collection of objects into a markdown-formatted table.
5+
6+
.DESCRIPTION
7+
The `ConvertTo-MarkdownTable` function converts a collection of objects into a markdown-formatted table. The names
8+
of all properties on the first object are used as column names in the order they are defined. If subsequent objects
9+
define properties that were not present on the first item processed, those additional properties will be ignored
10+
and columns will not be created for them.
11+
12+
Optionally, a maximum width can be specified for one, or all columns using MaxColumnWidth. However, if the length
13+
of the name column header is greater than the specified MaxColumnWidth, the MaxColumnWidth value used for that
14+
column will be the length of the column header. Rows with column values longer than MaxColumnWidth will be truncated
15+
and the Ellipsis string will be appended to the end with the length of the resulting string, plus ellipsis characters,
16+
equaling the MaxColumnWidth value for that column.
17+
18+
By default, all columns will be padded with a space between any column header or value and the "|" characters on
19+
either side. Values shorter than the longest value in the column will be right-padded so that all "|" characters
20+
align vertically throughout the table.
21+
22+
If the additional white space is not desired, use of the `Compress` switch will omit any unnecessary white space.
23+
24+
.PARAMETER InputObject
25+
Specified the object, or a collection of objects to represent in the resulting markdown data table. All properties
26+
of InputObject will be used to define the resulting columns. Consider using `Select-Object` first to select which
27+
properties on the source object should be passed to this function.
28+
29+
.PARAMETER MaxColumnWidth
30+
Specifies the maximum length of all columns if one value is provided, or the maximum length of each individual column
31+
if more than one value is provided. When providing more than one value, you must provide a value for every column. Columns
32+
with values longer than MaxColumnWidth will be truncated, and the Ellipsis characters will be appended. The length
33+
of the resulting string with ellipsis will match the MaxColumnWidth value.
34+
35+
The default value is `[int]::MaxValue` so effectively no columns will be truncated. And the minimum value is the length
36+
of Ellipsis + 1, or 4 by default.
37+
38+
.PARAMETER Ellipsis
39+
Specifies the characters to use as an ellipsis. By default, the ellipsis value is "...", but this can be overridden
40+
to be an empty string, or some other value. The minimum value for MaxColumnWidth is defined as 1 + the length of Ellipsis.
41+
42+
.PARAMETER Compress
43+
Specifies that no extra padding should be added to make the "|" symbols align vertically.
44+
45+
.EXAMPLE
46+
Get-Process | Select-Object Name, Id, VirtualMemorySize | ConvertTo-MarkdownTable -MaxColumnWidth 16
47+
48+
Gets a list of processes, selects the Name, Id, and VirtualMemorySize properties, and returns a markdown-formatted
49+
table representing all properties with a maximum column width of 16 characters.
50+
51+
.EXAMPLE
52+
Get-Service | Select-Object DisplayName, Name, Status | ConvertTo-MarkdownTable
53+
54+
Generates a markdown-formatted table with the DisplayName, Name, and Status properties of all services.
55+
56+
.EXAMPLE
57+
Get-Service | Select-Object DisplayName, Name, Status | ConvertTo-MarkdownTable -Compress
58+
59+
Generates a markdown-formatted table with the DisplayName, Name, and Status properties of all services, without any
60+
unnecessary padding, resulting in a much shorter string for large sets of data.
61+
62+
.NOTES
63+
Based on gist at https://gist.github.com/joshooaj/ef9b5ac769dd0f824c01497bf3e771dc
64+
#>#
65+
[CmdletBinding()]
66+
[OutputType([string])]
67+
param(
68+
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
69+
[psobject[]]
70+
$InputObject,
71+
72+
[Parameter()]
73+
[ValidateRange(1, [int]::MaxValue)]
74+
[int[]]
75+
$MaxColumnWidth = ([int]::MaxValue),
76+
77+
[Parameter()]
78+
[string]
79+
$Ellipsis = '...',
80+
81+
[Parameter()]
82+
[switch]
83+
$Compress
84+
)
85+
86+
begin {
87+
$MaxColumnWidth | ForEach-Object {
88+
if ($_ -le $Ellipsis.Length) {
89+
throw "MaxColumnWidth values must be greater than $($Ellipsis.Length) which is the length of the Ellipsis parameter. $_"
90+
}
91+
}
92+
$items = [system.collections.generic.list[object]]::new()
93+
$columns = [ordered]@{}
94+
$firstRecordProcessed = $false
95+
}
96+
97+
process {
98+
foreach ($item in $InputObject) {
99+
$items.Add($item)
100+
$columnNumber = 0
101+
foreach ($property in $item.PSObject.Properties) {
102+
if ($MaxColumnWidth.Count -gt 1 -and $MaxColumnWidth.Count -lt ($columnNumber + 1)) {
103+
throw "No MaxColumnWidth value defined for column $($columnNumber + 1). MaxColumnWidth must define a single value for all columns, or one value for each column."
104+
}
105+
106+
$maxLength = $MaxColumnWidth[0]
107+
if ($MaxColumnWidth.Count -gt 1) {
108+
$maxLength = $MaxColumnWidth[$columnNumber]
109+
}
110+
111+
if (-not $columns.Contains($property.Name)) {
112+
if ($firstRecordProcessed) {
113+
Write-Warning "Ignoring property '$($property.Name)' on $item because the property was not present in the first item processed."
114+
continue
115+
} else {
116+
$columns[$property.Name] = $property.Name.Length
117+
if ($property.Name.Length -gt $maxLength) {
118+
$maxLength = $property.Name.Length
119+
Write-Warning "The header for column $columnNumber, '$($property.Name)', is longer than the MaxColumnWidth value provided. The MaxColumnWidth value for this column is now $maxLength."
120+
}
121+
}
122+
}
123+
124+
$length = 0
125+
if ($null -ne $property.Value) {
126+
$length = [math]::Min($maxLength, $property.Value.ToString().Length)
127+
}
128+
129+
if ($columns[$property.Name] -lt $length) {
130+
$columns[$property.Name] = $length
131+
}
132+
$columnNumber++
133+
}
134+
$firstRecordProcessed = $true
135+
}
136+
}
137+
138+
end {
139+
function Shorten {
140+
param(
141+
[Parameter(ValueFromPipeline)]
142+
[string]
143+
$InputObject,
144+
145+
[Parameter(Mandatory)]
146+
[ValidateRange(1, [int]::MaxValue)]
147+
[int]
148+
$MaxLength,
149+
150+
[Parameter()]
151+
[string]
152+
$Ellipsis = '...'
153+
)
154+
155+
process {
156+
if ($InputObject.Length -gt $MaxLength) {
157+
'{0}{1}' -f $InputObject.Substring(0, ($MaxLength - $Ellipsis.Length)), $Ellipsis
158+
} else {
159+
$InputObject
160+
}
161+
}
162+
}
163+
164+
$sb = [text.stringbuilder]::new()
165+
166+
# Header
167+
$paddedColumnNames = $columns.GetEnumerator() | ForEach-Object {
168+
$text = $_.Key | Shorten -MaxLength $_.Value -Ellipsis $Ellipsis
169+
if ($Compress) {
170+
' {0} ' -f $text
171+
} else {
172+
' {0} ' -f ($text.PadRight($_.Value))
173+
}
174+
}
175+
$null = $sb.AppendLine('|' + ($paddedColumnNames -join '|') + '|')
176+
$null = $sb.AppendLine('|' + (($paddedColumnNames | ForEach-Object { '-' * $_.Length } ) -join '|') + '|')
177+
178+
foreach ($item in $items) {
179+
$paddedRowValues = $columns.GetEnumerator() | ForEach-Object {
180+
$text = [string]::Empty
181+
if ($null -ne $item.($_.Key)) {
182+
$text = $item.($_.Key) | Shorten -MaxLength $_.Value -Ellipsis $Ellipsis
183+
}
184+
if ($Compress) {
185+
' {0} ' -f $text
186+
} else {
187+
' {0} ' -f $text.PadRight($_.Value)
188+
}
189+
}
190+
191+
$null = $sb.AppendLine('|' + ($paddedRowValues -join '|') + '|')
192+
}
193+
$sb.ToString()
194+
}
195+
}

build/DetectPackages.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Import-Module .\build\ConvertTo-MarkdownTable.ps1
2+
$dir = $env:BUILD_ARTIFACTSTAGINGDIRECTORY + "\*.nupkg"
3+
Write-Host "Package Directory: $dir"
4+
$packages = Get-ChildItem -Path $dir -Recurse
5+
$ids = $packages | Select-Object -ExpandProperty name
6+
$pkgs = @()
7+
Write-Host "Source Branch Name: $env:BUILD_SOURCEBRANCHNAME"
8+
Write-Host "Branch Name: $env:branchName"
9+
$origin = "HEAD:$env:branchName"
10+
ForEach ($id in $ids) {
11+
$names = $id.Split(".")
12+
$name = $names[(0..($names.Length-5))] -join "."
13+
$version = $names[(($names.Length-4)..($names.Length-2))] -join "."
14+
$pkg = New-Object -TypeName PSObject -Property @{
15+
Name = $name
16+
Version = $version
17+
}
18+
if ($env:branchName -eq "main") {
19+
$tag = "$($pkg.Name)_v$($pkg.Version)"
20+
Write-Host "Tagging Build: $tag"
21+
git tag $tag
22+
}
23+
$pkgs += $pkg
24+
}
25+
if ($env:branchName -eq "main") {
26+
git push origin --tags
27+
}
28+
$pkgs | Format-Table -Property Name, Version
29+
Write-Host "Package Count: $($packages.Count)"
30+
Write-Host ("##vso[task.setvariable variable=package_count;]$($packages.Count)")
31+
$pushPackages = ($env:branchName -eq "main") -and ($packages.Count -gt 0)
32+
Write-Host ("##vso[task.setvariable variable=push_packages;]$($pushPackages)")
33+
$releaseNotes = $env:BUILD_ARTIFACTSTAGINGDIRECTORY + "\ReleaseNotes.md"
34+
$header = "## Packages$([Environment]::NewLine)"
35+
$header | Out-File $releaseNotes -Encoding ascii
36+
$pkgs | ConvertTo-MarkdownTable | Add-Content $releaseNotes -Encoding ascii

version.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,5 @@
88
"nugetPackageVersion": {
99
"semVer": 2
1010
},
11-
"cloudBuild": {
12-
"buildNumber": {
13-
"enabled": true
14-
}
15-
},
1611
"buildNumberOffset": 11
1712
}

0 commit comments

Comments
 (0)