Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 5f8cf47

Browse files
authored
Changes for release build (#32)
* changes for build and sign. * Additional changes for release build. Update codebase upload. update certificate. * Fix typo in displayname location. * Fix another typo in displayName. * Add test parameter for CI. Mark compare tests as pending. * Change set-location to the proper location. * Be sure to publish the correct directory. Add formatting to files which need signing. * Fix typo in publish path. * Reuse already created variables. Simply the signing pattern. * Additional changes for signed release build. * Fix incorrect yaml indentation. * More incorrect indentation. * Fix line spacing * remove displayName for sbom * Be sure to be in the right directory when creating variables. * Fix incorrect dictionary.txt location * Fix typo in nupkg creation step. add a target path for the nupkg publishing. * Change how the nupkg is published * Copy rather than move the nupkg. Also add -verbose for copy
1 parent 14c6a6c commit 5f8cf47

File tree

4 files changed

+213
-62
lines changed

4 files changed

+213
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
bin/
33
obj/
44
out/
5+
*.nupkg
56
project.lock.json
67
.DS_Store
78

build.ps1

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,103 @@
11
## Copyright (c) Microsoft Corporation.
22
## Licensed under the MIT License.
33

4-
[CmdletBinding()]
4+
[CmdletBinding(DefaultParameterSetName="build")]
55
param (
6-
[Parameter()]
6+
[Parameter(ParameterSetName="build")]
77
[string]
88
$Configuration = "Debug",
99

10+
[Parameter(ParameterSetName="package")]
11+
[switch]
12+
$NoBuild,
13+
14+
[Parameter(ParameterSetName="package")]
15+
[switch]
16+
$Package,
17+
18+
[Parameter(ParameterSetName="package")]
19+
[switch]
20+
$signed,
21+
22+
[Parameter(ParameterSetName="test")]
23+
[switch]
24+
$test,
25+
1026
[Parameter()]
1127
[switch]
12-
$Clean
28+
$Clean,
29+
30+
[Parameter()]
31+
[switch]
32+
$GetPackageVersion
33+
34+
)
35+
36+
37+
$moduleFileManifest = @(
38+
@{ Sign = $true ; File = "Microsoft.PowerShell.TextUtility.format.ps1xml" }
39+
@{ Sign = $true ; File = "Microsoft.PowerShell.TextUtility.psd1" }
40+
@{ Sign = $false; File = "dictionary.txt" }
41+
@{ Sign = $true ; File = "Microsoft.PowerShell.TextUtility.dll" }
1342
)
1443

44+
$moduleName = "Microsoft.PowerShell.TextUtility"
45+
$repoRoot = git rev-parse --show-toplevel
46+
47+
#
48+
function Get-ModuleInfo {
49+
import-powershelldatafile "$repoRoot/src/${moduleName}.psd1"
50+
}
51+
52+
# this takes the files for the module and publishes them to a created, local repository
53+
# so the nupkg can be used to publish to the PSGallery
54+
function Export-Module
55+
{
56+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
57+
param($packageRoot)
58+
59+
if ( -not (test-path $packageRoot)) {
60+
throw "'$packageRoot' does not exist"
61+
}
62+
# now construct a nupkg by registering a local repository and calling publish module
63+
$repoName = [guid]::newGuid().ToString("N")
64+
try {
65+
Register-PSRepository -Name $repoName -SourceLocation ${repoRoot} -InstallationPolicy Trusted
66+
Publish-Module -Path $packageRoot -Repository $repoName
67+
}
68+
catch {
69+
throw $_
70+
}
71+
finally {
72+
if (Get-PackageSource -Name $repoName) {
73+
Unregister-PSRepository -Name $repoName
74+
}
75+
}
76+
Get-ChildItem -Recurse -Name $packageRoot | Write-Verbose -Verbose
77+
78+
# construct the package path and publish it
79+
$nupkgName = "{0}.{1}" -f $moduleName,$moduleInfo.ModuleVersion
80+
$pre = $moduleInfo.PrivateData.PSData.Prerelease
81+
if ($pre) { $nupkgName += "-${pre}" }
82+
$nupkgName += ".nupkg"
83+
$nupkgPath = Join-Path $repoRoot $nupkgName
84+
if ($env:TF_BUILD) {
85+
# In Azure DevOps
86+
Write-Host "##vso[artifact.upload containerfolder=$nupkgName;artifactname=$nupkgName;]$nupkgPath"
87+
}
88+
else {
89+
Write-Verbose -Verbose "package path: ${nupkgPath} (exists:$(Test-Path $nupkgPath))"
90+
}
91+
}
92+
1593
try {
1694
Push-Location "$PSScriptRoot/src/code"
95+
$script:moduleInfo = Get-ModuleInfo
96+
if ($GetPackageVersion) {
97+
return $moduleInfo.ModuleVersion
98+
}
1799

18-
$outPath = "$PSScriptRoot/out/Microsoft.PowerShell.TextUtility"
19-
100+
$outPath = "$PSScriptRoot/out/${moduleName}"
20101
if ($Clean) {
21102
if (Test-Path $outPath) {
22103
Write-Verbose "Deleting $outPath"
@@ -26,7 +107,37 @@ try {
26107
dotnet clean
27108
}
28109

29-
dotnet publish --output $outPath --configuration $Configuration
110+
if (-not $NoBuild) {
111+
dotnet publish --output $outPath --configuration $Configuration
112+
}
113+
114+
if ($Test) {
115+
$script = [ScriptBlock]::Create("try {
116+
Import-Module '${repoRoot}/out/${moduleName}/'
117+
Import-Module -Name Pester -Max 4.99
118+
Push-Location '${repoRoot}/test'
119+
Invoke-Pester
120+
}
121+
finally {
122+
Pop-Location
123+
}")
124+
pwsh -c $script
125+
}
126+
127+
if ($Package) {
128+
if ($Signed) {
129+
$pkgBase = "${PSScriptRoot}/signed/${moduleName}"
130+
}
131+
else {
132+
$pkgBase = "${PSScriptRoot}/out/${moduleName}"
133+
}
134+
135+
if (-not (Test-Path $pkgBase)) {
136+
throw "Directory '$pkgBase' does not exist"
137+
}
138+
139+
Export-Module -packageRoot $pkgBase
140+
}
30141
}
31142
finally {
32143
Pop-Location

test/CompareText.tests.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ example text. used!
3232
}
3333

3434
It 'Compare with no specified view uses inline' {
35+
Set-ItResult -pending -because "comparison tests are not yet running"
3536
$out = Compare-Text -LeftText $leftText -RightText $rightText | Out-String
3637
$out | Should -BeExactly $expectedInline
3738
}
3839

3940
It 'Compare with no specified view uses inline and positional parameters' {
41+
Set-ItResult -pending -because "comparison tests are not yet running"
4042
$out = Compare-Text $leftText $rightText | Out-String
4143
$out | Should -BeExactly $expectedInline
4244
}
4345

4446
It 'Compare with inline works' {
47+
Set-ItResult -pending -because "comparison tests are not yet running"
4548
$out = Compare-Text $leftText $rightText -View Inline | Out-String
4649
$out | Should -BeExactly $expectedInline
4750
}
4851

4952
It 'Compare with sideybyside works' {
53+
Set-ItResult -pending -because "comparison tests are not yet running"
5054
$out = Compare-Text $leftText $rightText -View SideBySide | Out-String
5155
$out | Should -BeExactly $expectedSideBySide
5256
}
53-
}
57+
}

0 commit comments

Comments
 (0)