Skip to content

Commit fbfdf22

Browse files
authored
Fix packaging (#87)
* Simplify versioning logic, closer to SemVer * Remove spaces from tags * Adjust file exclusions to support .NET project * Add support to Invoke REST API * First implementation supports library calls * Fix Choco packaging; generate LICENSE.txt and VERIFICATION.txt * Fix GitVersion behavior for pull requests * Create output dir before copying file * Remove unnecessary PR handling * Add module VSSetup to build process * Add NuGet Restore to MSBuild call * Escape semicolon in MSBuild args
1 parent 16623dc commit fbfdf22

File tree

5 files changed

+173
-54
lines changed

5 files changed

+173
-54
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
".gitignore": true,
55
".vs": true,
66
".vscode": true,
7+
"[Bb]in": true,
78
"[Bb]uild[Tt]ools": true,
9+
"[Oo]bj": true,
810
"[Pp]ackages": true,
911
"[Ss]etup/bin": true,
1012
"[Ss]etup/obj": true,

Build.ps1

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Param
1717
Function Install-Dependencies
1818
{
1919
$NugetPackages = @('GitVersion.CommandLine')
20-
$PsModules = @('InvokeBuild', 'psake', 'PsScriptAnalyzer')
20+
$PsModules = @('InvokeBuild', 'psake', 'PsScriptAnalyzer', 'VSSetup')
2121

2222
$script:PackagesDir = Join-Path $SolutionDir 'packages'
2323

@@ -132,30 +132,10 @@ try
132132

133133
$GitVersionPath = Join-Path $SolutionDir 'packages\gitversion.commandline\tools\GitVersion.exe'
134134
$script:VersionMetadata = (& $GitVersionPath | ConvertFrom-Json)
135-
136-
$VersionMetadata | Write-Verbose
137-
138135
$ProjectBuildNumber = ((Get-Date) - $RepoCreationDate).Days
136+
$BuildName = $VersionMetadata.FullSemVer
139137

140-
if($env:BUILD_REASON -eq 'PullRequest')
141-
{
142-
$LegacyBuildMetadata = ''
143-
$SemVerMetadata = ''
144-
$BuildNameSuffix = $VersionMetadata.PreReleaseTagWithDash
145-
}
146-
else
147-
{
148-
$LegacyBuildMetadata = "$($VersionMetadata.PreReleaseTagWithDash)+0$($VersionMetadata.BuildMetadata)"
149-
$SemVerMetadata = "$($VersionMetadata.PreReleaseTagWithDash)+$ProjectBuildNumber.0$($VersionMetadata.BuildMetadata)"
150-
}
151-
152-
$LegacyVersion = "$($VersionMetadata.MajorMinorPatch).$ProjectBuildNumber"
153-
$LegacyFullVersion = "${LegacyVersion}$LegacyBuildMetadata"
154-
155-
$SemVerVersion = "$($VersionMetadata.MajorMinorPatch)"
156-
$SemVerFullVersion = "${SemVerVersion}$SemVerMetadata"
157-
158-
$BuildName = $SemVerFullVersion
138+
$VersionMetadata | Write-Verbose
159139

160140
Write-Verbose "Outputting build name $BuildName to host"
161141
Write-Host "- Build $BuildName`n" -ForegroundColor Cyan
@@ -177,16 +157,11 @@ try
177157
-Parameters @{
178158
SolutionDir = $SolutionDir
179159
Configuration = $Configuration
180-
BranchName = $VersionMetadata.BranchName
181160
ModuleName = $ModuleName
182161
ModuleAuthor = $ModuleAuthor
183162
ModuleDescription = $ModuleDescription
184-
Commit = $VersionMetadata.Sha
185-
Version = $LegacyVersion
186-
NuGetVersion = $LegacyFullVersion
187-
PreRelease = "$($VersionMetadata.PreReleaseLabel)$($VersionMetadata.PreReleaseNumber)";
188163
BuildName = $BuildName
189-
SemVer = $SemVerFullVersion
164+
BuildNumber = $ProjectBuildNumber
190165
VersionMetadata = $VersionMetadata
191166
SkipTests = $SkipTests.IsPresent
192167
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<#
2+
.SYNOPSIS
3+
Short description
4+
.DESCRIPTION
5+
Long description
6+
.EXAMPLE
7+
PS C:\> <example usage>
8+
Explanation of what the example does
9+
.INPUTS
10+
Inputs (if any)
11+
.OUTPUTS
12+
Output (if any)
13+
.NOTES
14+
General notes
15+
#>
16+
Function Invoke-TfsRestApi
17+
{
18+
[CmdletBinding()]
19+
Param
20+
(
21+
[Parameter(Position=0, Mandatory=$true, ParameterSetName="Library call")]
22+
[Alias("Name")]
23+
[Alias("API")]
24+
[string]
25+
$Operation,
26+
27+
[Parameter(ParameterSetName="Library call")]
28+
[Alias("Client")]
29+
[Alias("Type")]
30+
[string]
31+
$ClientType,
32+
33+
[Parameter(ParameterSetName="Library call")]
34+
[object[]]
35+
$ArgumentList,
36+
37+
[Parameter(ParameterSetName="Library call")]
38+
[string]
39+
$ErrorMessage,
40+
41+
[Parameter(ParameterSetName="Library call")]
42+
[object]
43+
$Collection,
44+
45+
[Parameter()]
46+
[switch]
47+
$AsTask
48+
)
49+
50+
End
51+
{
52+
GET_COLLECTION($tpc)
53+
54+
GET_CLIENT($ClientType)
55+
56+
$task = $client.$Operation.Invoke($ArgumentList)
57+
58+
if ($AsTask)
59+
{
60+
return $task
61+
}
62+
63+
CHECK_ASYNC($task,$result,$Message)
64+
65+
return $result
66+
}
67+
}

Module/TfsCmdlets.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
NestedModules = @()
2020
PrivateData = @{
2121
PSData = @{
22-
Tags = @('TfsCmdlets', 'TFS', 'VSTS', 'PowerShell', 'Azure', 'Azure DevOps', 'DevOps', 'ALM', 'Team Foundation Server')
22+
Tags = @('TfsCmdlets', 'TFS', 'VSTS', 'PowerShell', 'Azure', 'AzureDevOps', 'DevOps', 'ALM', 'TeamFoundationServer')
2323
Branch = 'BranchName'
2424
Commit = 'Commit'
2525
Build = 'BuildName'

psake.ps1

Lines changed: 99 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Properties {
3939
$ChocolateySpecPath = Join-Path $ChocolateyDir "TfsCmdlets.nuspec"
4040

4141
# Wix packaging
42-
$WixVersion = "$Version"
42+
$FourPartVersion = "$($VersionMetadata.MajorMinorPatch).$BuildNumber"
4343
$WixOutputPath = Join-Path $SolutionDir "Setup\bin\$Configuration"
4444

4545
#7zip
@@ -76,9 +76,8 @@ Task CleanOutputDir {
7676
Task BuildLibrary {
7777

7878
$LibSolutionPath = (Join-Path $SolutionDir 'Lib/TfsCmdletsLib.sln')
79-
$TargetDir = (Join-Path $ModuleDir 'Lib')
8079

81-
exec { msbuild $LibSolutionPath /t:Rebuild /p:Configuration=$Configuration /p:Version=$Version /p:AssemblyVersion=$Version /v:d | Write-Verbose }
80+
exec { msbuild $LibSolutionPath /t:Restore`;Build /p:Configuration=$Configuration /p:Version=$FourPartVersion /p:AssemblyVersion=$FourPartVersion /p:AssemblyInformationalVersion=$BuildName /v:d | Write-Verbose }
8281

8382

8483
}
@@ -200,14 +199,15 @@ Updating module manifest file $ModuleManifestPath with the following content:
200199
-NestedModules @($(($nestedModuleList | ForEach-Object { "'$_'" }) -join ','))
201200
-FileList @($(($fileList | ForEach-Object { "'$_'" }) -join ','))
202201
-FunctionsToExport @($(($functionList | ForEach-Object { "'$_'" }) -join ','))
203-
-ModuleVersion '$Version'
202+
-ModuleVersion '$($VersionMetadata.NugetVersion)'
204203
-CompatiblePSEditions @($(($CompatiblePSEditions | ForEach-Object { "'$_'" }) -join ','))
205204
-PrivateData @{
206-
Branch = '$BranchName'
205+
Branch = '$($VersionMetadata.BranchName)'
207206
Build = '$BuildName'
208-
Commit = '$Commit'
207+
Commit = '$($VersionMetadata.Commit)'
209208
TfsClientVersion = '$tfsOmNugetVersion'
210-
PreRelease = '$PreRelease'
209+
PreRelease = '$($VersionMetadata.NugetPrereleaseTag)'
210+
Version = '$($VersionMetadata.FullSemVer)'
211211
}
212212
}
213213
"@
@@ -216,14 +216,15 @@ Updating module manifest file $ModuleManifestPath with the following content:
216216
-NestedModules $nestedModuleList `
217217
-FileList $fileList `
218218
-FunctionsToExport $functionList `
219-
-ModuleVersion $Version `
219+
-ModuleVersion $VersionMetadata.MajorMinorPatch `
220220
-CompatiblePSEditions $CompatiblePSEditions `
221221
-PrivateData @{
222-
Branch = $BranchName
222+
Branch = $VersionMetadata.BranchName
223223
Build = $BuildName
224-
Commit = $Commit
224+
Commit = $VersionMetadata.Sha
225225
TfsClientVersion = $tfsOmNugetVersion
226-
PreRelease = $PreRelease
226+
PreRelease = $VersionMetadata.NugetPrereleaseTag
227+
Version = $VersionMetadata.FullSemVer
227228
}
228229
}
229230

@@ -249,7 +250,7 @@ Task DownloadTfsNugetPackage {
249250
if (-not (Test-Path "$packageDir.*" -PathType Container))
250251
{
251252
Write-Verbose "$package not found. Downloading from Nuget.org"
252-
& $NugetExePath Install $package -OutputDirectory packages -Verbosity Detailed -PreRelease *>&1 | Write-Verbose
253+
& $NugetExePath Install $package -OutputDirectory packages -Verbosity Detailed -PreRelease -PackageSaveMode nuspec`;nupkg *>&1 | Write-Verbose
253254
}
254255
else
255256
{
@@ -277,21 +278,21 @@ Task PackageModule -Depends Build {
277278

278279
if (-not (Test-Path $PortableDir -PathType Container)) { New-Item $PortableDir -ItemType Directory -Force | Out-Null }
279280

280-
& $7zipExePath a (Join-Path $PortableDir "TfsCmdlets-Portable-$NugetVersion.zip") (Join-Path $OutDir 'Module\*') | Write-Verbose
281+
& $7zipExePath a (Join-Path $PortableDir "TfsCmdlets-Portable-$($VersionMetadata.NugetVersion).zip") (Join-Path $OutDir 'Module\*') | Write-Verbose
281282
}
282283

283284
Task PackageNuget -Depends Build, GenerateNuspec {
284285

285286
Copy-Item $ModuleDir $NugetToolsDir\TfsCmdlets -Recurse -Exclude *.ps1 -Force
286287

287-
$cmdLine = "$NugetExePath Pack $NugetSpecPath -OutputDirectory $NugetDir -Verbosity Detailed -NonInteractive -Version $NugetVersion"
288+
$cmdLine = "$NugetExePath Pack $NugetSpecPath -OutputDirectory $NugetDir -Verbosity Detailed -NonInteractive -Version $($VersionMetadata.NugetVersion)"
288289

289290
Write-Verbose "Command line: [$cmdLine]"
290291

291292
Invoke-Expression $cmdLine *>&1 | Write-Verbose
292293
}
293294

294-
Task PackageChocolatey -Depends Build {
295+
Task PackageChocolatey -Depends PackageNuget, GenerateLicenseFile, GenerateVerificationFile {
295296

296297
if (-not (Test-Path $ChocolateyPath))
297298
{
@@ -301,7 +302,7 @@ Task PackageChocolatey -Depends Build {
301302
Copy-Item $ModuleDir $ChocolateyToolsDir\TfsCmdlets -Recurse -Force
302303
Copy-Item $NugetSpecPath -Destination $ChocolateyDir -Force
303304

304-
$cmdLine = "$ChocolateyPath Pack $ChocolateySpecPath -OutputDirectory $ChocolateyDir --Version $Version"
305+
$cmdLine = "$ChocolateyPath Pack $ChocolateySpecPath -OutputDirectory $ChocolateyDir --Version $($VersionMetadata.NugetVersion)"
305306

306307
Write-Verbose "Command line: [$cmdLine]"
307308

@@ -347,7 +348,7 @@ Task PackageMsi -Depends Build {
347348

348349
$CandleArgs = @(
349350
"-sw$WixSuppressedWarnings",
350-
"-dPRODUCTVERSION=$WixVersion",
351+
"-dPRODUCTVERSION=$FourPartVersion",
351352
"-d`"PRODUCTNAME=$ModuleName - $ModuleDescription`"",
352353
"-d`"AUTHOR=$ModuleAuthor`"",
353354
"-dSourceDir=$ModuleDir\",
@@ -362,9 +363,9 @@ Task PackageMsi -Depends Build {
362363
"-dProjectPath=$WixProjectDir\$WixProjectFileName",
363364
"-dTargetDir=$WixBinDir\",
364365
"-dTargetExt=.msi"
365-
"-dTargetFileName=$ModuleName-$NugetVersion.msi",
366-
"-dTargetName=$ModuleName-$NugetVersion",
367-
"-dTargetPath=$WixBinDir\$ModuleName-$NugetVersion.msi",
366+
"-dTargetFileName=$ModuleName-$($VersionMetadata.NugetVersion).msi",
367+
"-dTargetName=$ModuleName-$($VersionMetadata.NugetVersion)",
368+
"-dTargetPath=$WixBinDir\$ModuleName-$($VersionMetadata.NugetVersion).msi",
368369
"-I$WixProjectDir",
369370
"-out", "$WixObjDir\",
370371
"-arch", "x86",
@@ -377,8 +378,8 @@ Task PackageMsi -Depends Build {
377378
& (Join-Path $WixToolsDir 'Candle.exe') $CandleArgs *>&1 | Write-Verbose
378379

379380
$LightArgs = @(
380-
"-out", "$WixBinDir\$ModuleName-$NugetVersion.msi",
381-
"-pdbout", "$WixBinDir\$ModuleName-$NugetVersion.wixpdb",
381+
"-out", "$WixBinDir\$ModuleName-$($VersionMetadata.NugetVersion).msi",
382+
"-pdbout", "$WixBinDir\$ModuleName-$($VersionMetadata.NugetVersion).wixpdb",
382383
"-sw1076",
383384
"-cultures:null",
384385
"-ext", "$WixToolsDir\WixUtilExtension.dll",
@@ -399,8 +400,8 @@ Task PackageMsi -Depends Build {
399400

400401
Task PackageDocs -Depends GenerateDocs {
401402

402-
#Compress-Archive -Path $DocsDir -CompressionLevel Optimal -DestinationPath (Join-Path $DocsDir "TfsCmdlets-docs-$NugetVersion.zip")
403-
& $7zipExePath a (Join-Path $DocsDir "TfsCmdlets-Docs-$NugetVersion.zip") $DocsDir | Write-Verbose
403+
#Compress-Archive -Path $DocsDir -CompressionLevel Optimal -DestinationPath (Join-Path $DocsDir "TfsCmdlets-docs-$($VersionMetadata.NugetVersion).zip")
404+
& $7zipExePath a (Join-Path $DocsDir "TfsCmdlets-Docs-$($VersionMetadata.NugetVersion).zip") $DocsDir | Write-Verbose
404405
}
405406

406407
Task GenerateDocs -Depends Build {
@@ -494,3 +495,77 @@ Task GenerateNuspec {
494495

495496
Set-Content -Path $NugetSpecPath -Value $nuspec
496497
}
498+
499+
Task GenerateLicenseFile {
500+
501+
$outLicenseFile = Join-Path $ChocolateyToolsDir 'LICENSE.txt'
502+
503+
if(-not (Test-Path $ChocolateyToolsDir -PathType Container))
504+
{
505+
New-Item $ChocolateyToolsDir -Force -ItemType Directory | Write-Verbose
506+
}
507+
508+
Copy-Item $SolutionDir\LICENSE.md $outLicenseFile -Force -Recurse
509+
510+
$specFiles = Get-ChildItem $NugetPackagesDir -Include *.nuspec -Recurse
511+
512+
foreach($f in $specFiles)
513+
{
514+
$spec = [xml] (Get-Content $f -Raw -Encoding UTF8)
515+
$packageUrl = "https://nuget.org/packages/$($spec.package.metadata.id)/$($spec.package.metadata.version)"
516+
517+
if($spec.package.metadata.license)
518+
{
519+
if ($spec.package.metadata.license.type -eq 'file')
520+
{
521+
$licenseFile = Join-Path $f.Directory $spec.package.metadata.license.'#text'
522+
$licenseText = Get-Content $licenseFile -Raw -Encoding Utf8
523+
}
524+
else
525+
{
526+
$licenseText = "Please refer to https://spdx.org/licenses/$($spec.package.metadata.license.type).html for license information for this package."
527+
}
528+
}
529+
else
530+
{
531+
$licenseUrl = $spec.package.metadata.licenseUrl
532+
$licenseText = "Please refer to $licenseUrl for license information for this package."
533+
}
534+
535+
@"
536+
=============================
537+
538+
FROM $packageUrl
539+
540+
LICENSE
541+
542+
$licenseText
543+
544+
"@ | Add-Content -Path $outLicenseFile -Encoding Utf8
545+
546+
}
547+
}
548+
549+
Task GenerateVerificationFile {
550+
551+
$outVerifyFile = Join-Path $ChocolateyToolsDir 'VERIFICATION.txt'
552+
553+
$packageUrls = Get-ChildItem $NugetPackagesDir -Include *.nuspec -Recurse | ForEach-Object {
554+
$spec = [xml] (Get-Content $_ -Raw -Encoding UTF8); `
555+
Write-Output "https://nuget.org/packages/$($spec.package.metadata.id)/$($spec.package.metadata.version)"
556+
}
557+
558+
@"
559+
VERIFICATION
560+
============
561+
562+
Verification is intended to assist the Chocolatey moderators and community
563+
in verifying that this package's contents are trustworthy.
564+
565+
Binary files contained in this package can be compared against their respective NuGet source packages, listed below:
566+
567+
$($packageUrls -join "`r`n")
568+
569+
"@ | Out-File $outVerifyFile -Encoding Utf8
570+
571+
}

0 commit comments

Comments
 (0)