Skip to content

Commit e7ce642

Browse files
authored
Refactored psake build script. (#147)
* Refactored psake build script. This separates out the user customizations into a separate file build.settings.ps1. Also made changes related to the discussion in issue #145. Fixed some bugs with the build script as well after a fair bit of testing. Too bad my code-signing cert expired last month. Hopefully DigiCert will come through with a new cert so I can test the Sign task. * Eliminate 28 script analyzer warnings.
1 parent af75068 commit e7ce642

File tree

9 files changed

+458
-343
lines changed

9 files changed

+458
-343
lines changed

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
]
6767
},
6868
{
69-
"taskName": "Build Docs",
69+
"taskName": "BuildHelp",
7070
"suppressTaskName": true,
7171
"showOutput": "always",
7272
"args": [
73-
"Write-Host 'Invoking psake...'; Invoke-psake build.psake.ps1 -taskList BuildDocs;",
74-
"Invoke-Command { Write-Host 'Completed BuildDocs task in task runner.' }"
73+
"Write-Host 'Invoking psake...'; Invoke-psake build.psake.ps1 -taskList BuildHelp;",
74+
"Invoke-Command { Write-Host 'Completed BuildHelp task in task runner.' }"
7575
]
7676
},
7777
{

build.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# This builds this module by invoking the build.psake.ps1 script
1+
#Requires -Modules psake
22

3-
if ($null -eq (Get-Module -Name PSake -ListAvailable)) {
4-
throw "You need to install PSake before continuing. Install with 'Install-Module PSake -Scope CurrentUser'."
5-
}
6-
7-
Import-Module Psake
3+
# Builds the module by invoking psake on the build.psake.ps1 script.
84
Invoke-PSake $PSScriptRoot\build.psake.ps1 -taskList Build

build.psake.ps1

Lines changed: 73 additions & 163 deletions
Large diffs are not rendered by default.

build.settings.ps1

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
###############################################################################
2+
# Customize these properties and tasks for your module.
3+
###############################################################################
4+
5+
Properties {
6+
# ----------------------- Basic properties --------------------------------
7+
8+
# The root directories for the module's docs, src and test.
9+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='DocsRootDir')]
10+
$DocsRootDir = "$PSScriptRoot/docs"
11+
$SrcRootDir = "$PSScriptRoot/src"
12+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestRootDir')]
13+
$TestRootDir = "$PSScriptRoot/test"
14+
15+
# The name of your module should match the basename of the PSD1 file.
16+
$ModuleName = Get-Item $SrcRootDir/*.psd1 |
17+
Where-Object { $null -ne (Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue) } |
18+
Select-Object -First 1 | Foreach-Object BaseName
19+
20+
# The $OutDir must match the ModuleName in order to support publishing the module.
21+
$ReleaseDir = "$PSScriptRoot/Release"
22+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='OutDir')]
23+
$OutDir = "$ReleaseDir/$ModuleName"
24+
25+
# Default Locale used for documentation generatioon, defaults to en-US.
26+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='DefaultLocale')]
27+
$DefaultLocale = $null
28+
29+
# Items in the $Exclude array will not be copied to the $OutDir e.g. $Exclude = @('.gitattributes')
30+
# Typically you wouldn't put any file under the src dir unless the file was going to ship with
31+
# the module. However, if there are such files, add their $SrcRootDir relative paths to the exclude list.
32+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='Exclude')]
33+
$Exclude = @()
34+
35+
36+
# ------------------- Script signing properties ---------------------------
37+
38+
# Set to $true if you want to sign your scripts. You will need to have a code-signing certificate.
39+
# You can specify the certificate's subject name below. If not specified, you will be prompted to
40+
# provide either a subject name or path to a PFX file. After this one time prompt, the value will
41+
# saved for future use and you will no longer be prompted.
42+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='SignScripts')]
43+
$SignScripts = $false
44+
45+
# Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the
46+
# first time you build, you will be prompted to enter your code-signing certificate's Subject Name.
47+
# This variable is used only if $SignScripts is set to $true.
48+
#
49+
# This does require the code-signing certificate to be installed to your certificate store. If you
50+
# have a code-signing certificate in a PFX file, install the certificate to your certificate store
51+
# with the command below. You may be prompted for the certificate's password.
52+
#
53+
# Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My
54+
#
55+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='CertSubjectName')]
56+
$CertSubjectName = $null
57+
58+
59+
# -------------------- Publishing properties ------------------------------
60+
61+
# Your NuGet API key for the PSGallery. Leave it as $null and the first time you publish,
62+
# you will be prompted to enter your API key. The build will store the key encrypted in the
63+
# settings file, so that on subsequent publishes you will no longer be prompted for the API key.
64+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='NuGetApiKey')]
65+
$NuGetApiKey = $null
66+
67+
# Name of the repository you wish to publish to. If $null is specified the default repo (PowerShellGallery) is used.
68+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='PublishRepository')]
69+
$PublishRepository = $null
70+
71+
# Path to the release notes file. Set to $null if the release notes reside in the manifest file.
72+
# The contents of this file are used during publishing for the ReleaseNotes parameter.
73+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='ReleaseNotesPath')]
74+
$ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md"
75+
76+
77+
# ----------------------- Misc properties ---------------------------------
78+
79+
# In addition, PFX certificates are supported in an interactive scenario only,
80+
# as a way to import a certificate into the user personal store for later use.
81+
# This can be provided using the CertPfxPath parameter. PFX passwords will not be stored.
82+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='SettingsPath')]
83+
$SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml"
84+
85+
# The local installation directory for the install task. Defaults to your user PSModulePath.
86+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='InstallPath')]
87+
$InstallPath = $null
88+
89+
# Specifies an output file path to send to Invoke-Pester's -OutputFile parameter.
90+
# This is typically used to write out test results so that they can be sent to a CI
91+
# system like AppVeyor.
92+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestOutputFile')]
93+
$TestOutputFile = $null
94+
95+
# Specifies the test output format to use when the TestOutputFile property is given
96+
# a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter.
97+
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestOutputFormat')]
98+
$TestOutputFormat = "NUnitXml"
99+
}
100+
101+
###############################################################################
102+
# Customize these tasks for performing operations before and/or after Build.
103+
###############################################################################
104+
105+
# Executes before the BuildImpl phase of the Build task.
106+
Task PreBuild {
107+
}
108+
109+
# Executes after the Sign phase of the Build task.
110+
Task PostBuild {
111+
}
112+
113+
###############################################################################
114+
# Customize these tasks for performing operations before and/or after BuildHelp.
115+
###############################################################################
116+
117+
# Executes before the GenerateMarkdown phase of the BuildHelp task.
118+
Task PreBuildHelp {
119+
}
120+
121+
# Executes after the BuildHelpImpl phase of the BuildHelp task.
122+
Task PostBuildHelp {
123+
}
124+
125+
###############################################################################
126+
# Customize these tasks for performing operations before and/or after Install.
127+
###############################################################################
128+
129+
# Executes before the InstallImpl phase of the Install task.
130+
Task PreInstall {
131+
}
132+
133+
# Executes after the InstallImpl phase of the Install task.
134+
Task PostInstall {
135+
}
136+
137+
###############################################################################
138+
# Customize these tasks for performing operations before and/or after Publish.
139+
###############################################################################
140+
141+
# Executes before publishing occurs.
142+
Task PrePublish {
143+
}
144+
145+
# Executes after publishing occurs.
146+
Task PostPublish {
147+
}

src/Templates/NewModule/build.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# This builds this module by invoking the build.psake.ps1 script
1+
#Requires -Modules psake
22

3-
if ($null -eq (Get-Module -Name PSake -ListAvailable)) {
4-
throw "You need to install PSake before continuing. Install with 'Install-Module PSake -Scope CurrentUser'."
5-
}
6-
7-
Import-Module Psake
3+
# Builds the module by invoking psake on the build.psake.ps1 script.
84
Invoke-PSake $PSScriptRoot\build.psake.ps1 -taskList Build

0 commit comments

Comments
 (0)