Skip to content

Commit 26e21e0

Browse files
committedSep 25, 2024·
Make build script more readable
1 parent 4dbc35e commit 26e21e0

File tree

1 file changed

+31
-51
lines changed

1 file changed

+31
-51
lines changed
 

‎SecretManagement.build.ps1

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,6 @@ param(
88

99
#Requires -Modules @{ ModuleName = "InvokeBuild"; ModuleVersion = "5.0.0" }
1010

11-
$ProjectName = "SecretManagement"
12-
$FullModuleName = "Microsoft.PowerShell.SecretManagement"
13-
$CSharpSource = Join-Path $PSScriptRoot src/code
14-
$CSharpPublish = Join-Path $PSScriptRoot artifacts/publish/$FullModuleName/$($Configuration.ToLower())
15-
$ModuleOut = Join-Path $PSScriptRoot module
16-
$PackageOut = Join-Path $PSScriptRoot out
17-
$HelpSource = Join-Path $PSScriptRoot help
18-
$HelpOut = Join-Path $ModuleOut en-US
19-
20-
$CSharpArtifacts = @(
21-
"$FullModuleName.dll",
22-
"$FullModuleName.pdb",
23-
"$FullModuleName.xml",
24-
"System.Runtime.InteropServices.RuntimeInformation.dll")
25-
26-
$BaseArtifacts = @(
27-
"src/$FullModuleName.format.ps1xml",
28-
"README.md",
29-
"LICENSE",
30-
"ThirdPartyNotices.txt")
31-
32-
$ManifestPath = Join-Path $PSScriptRoot "src/$FullModuleName.psd1"
33-
34-
$HelpAboutTopics = @()
35-
3611
task FindDotNet -Before Clean, Build {
3712
Assert (Get-Command dotnet -ErrorAction SilentlyContinue) "The dotnet CLI was not found, please install it: https://aka.ms/dotnet-cli"
3813
$DotnetVersion = dotnet --version
@@ -41,63 +16,68 @@ task FindDotNet -Before Clean, Build {
4116
}
4217

4318
task Clean {
44-
Remove-BuildItem ./artifacts, $ModuleOut, $PackageOut
45-
Invoke-BuildExec { dotnet clean $CSharpSource }
46-
47-
Remove-BuildItem "$HelpOut/$FullModuleName.dll-Help.xml"
48-
foreach ($aboutTopic in $HelpAboutTopics) {
49-
Remove-BuildItem "$HelpSource/$aboutTopic.help.txt"
50-
}
19+
Remove-BuildItem ./artifacts, ./module, ./out
20+
Invoke-BuildExec { dotnet clean ./src/code }
5121
}
5222

53-
task BuildDocs -If { Test-Path -LiteralPath $HelpSource } {
54-
New-ExternalHelp -Path $HelpSource -OutputPath $HelpOut
55-
foreach ($aboutTopic in $HelpAboutTopics) {
56-
New-ExternalHelp -Path "$HelpSource\$aboutTopic.md" -OutputPath $HelpOut
57-
}
23+
task BuildDocs -If { Test-Path -LiteralPath ./help } {
24+
New-ExternalHelp -Path ./help -OutputPath ./module/en-US
5825
}
5926

6027
task BuildModule {
61-
New-Item -ItemType Directory -Force $ModuleOut | Out-Null
28+
New-Item -ItemType Directory -Force ./module | Out-Null
6229

63-
Invoke-BuildExec { dotnet publish $CSharpSource --configuration $Configuration }
30+
Invoke-BuildExec { dotnet publish ./src/code -c $Configuration }
6431

6532
# Hard code building this in release config since we aren't actually developing it,
6633
# it's only for tests. The tests also hard code the path assuming release config.
67-
Invoke-BuildExec { dotnet publish $PSScriptRoot/ExtensionModules/CredManStore/src/code --configuration Release }
34+
Invoke-BuildExec { dotnet publish ./ExtensionModules/CredManStore/src/code -c Release }
35+
36+
$FullModuleName = "Microsoft.PowerShell.SecretManagement"
37+
38+
$CSharpArtifacts = @(
39+
"$FullModuleName.dll",
40+
"$FullModuleName.pdb",
41+
"$FullModuleName.xml",
42+
"System.Runtime.InteropServices.RuntimeInformation.dll")
6843

6944
$CSharpArtifacts | ForEach-Object {
70-
$item = Join-Path $CSharpPublish $_
71-
Copy-Item -Force -LiteralPath $item -Destination $ModuleOut
45+
$item = "./artifacts/publish/$FullModuleName/$($Configuration.ToLower())/$_"
46+
Copy-Item -Force -LiteralPath $item -Destination ./module
7247
}
7348

49+
$BaseArtifacts = @(
50+
"src/$FullModuleName.format.ps1xml",
51+
"README.md",
52+
"LICENSE",
53+
"ThirdPartyNotices.txt")
54+
7455
$BaseArtifacts | ForEach-Object {
7556
$itemToCopy = Join-Path $PSScriptRoot $_
76-
Copy-Item -Force -LiteralPath $itemToCopy -Destination $ModuleOut
57+
Copy-Item -Force -LiteralPath $itemToCopy -Destination ./module
7758
}
7859

7960
[xml]$xml = Get-Content Directory.Build.props
8061
$moduleVersion = $xml.Project.PropertyGroup.ModuleVersion
81-
$manifestContent = Get-Content -LiteralPath $ManifestPath -Raw
62+
$manifestContent = Get-Content -LiteralPath "./src/$FullModuleName.psd1" -Raw
8263
$newManifestContent = $manifestContent -replace '{{ModuleVersion}}', $moduleVersion
83-
Set-Content -LiteralPath "$ModuleOut/$FullModuleName.psd1" -Encoding utf8 -Value $newManifestContent
64+
Set-Content -LiteralPath "./module/$FullModuleName.psd1" -Encoding utf8 -Value $newManifestContent
8465
}
8566

8667
task PackageModule {
87-
New-Item -ItemType Directory -Force $PackageOut | Out-Null
68+
New-Item -ItemType Directory -Force ./out | Out-Null
8869

8970
try {
90-
Register-PSResourceRepository -Name $ProjectName -Uri $PackageOut -ErrorAction Stop
91-
$registerSuccessful = $true
92-
Publish-PSResource -Path $ModuleOut -Repository $ProjectName -Verbose
71+
Register-PSResourceRepository -Name SecretManagement -Uri ./out -ErrorAction Stop
72+
Publish-PSResource -Path ./module -Repository SecretManagement -Verbose
9373
} finally {
94-
Unregister-PSResourceRepository -Name $ProjectName
74+
Unregister-PSResourceRepository -Name SecretManagement
9575
}
9676
}
9777

9878
# AKA Microsoft.PowerShell.SecretManagement.Library
9979
task PackageLibrary -If { $Configuration -eq "Release" } {
100-
Invoke-BuildExec { dotnet pack $CSharpSource --no-build --configuration $Configuration --output $PackageOut }
80+
Invoke-BuildExec { dotnet pack ./src/code --no-build -c $Configuration -o ./out }
10181
}
10282

10383
task Test {

0 commit comments

Comments
 (0)
Please sign in to comment.