1
- # This is a PSake script that supports the following tasks:
2
- # clean, build, test and publish. The default task is build.
3
- #
4
- # The publish task uses the Publish-Module command to publish
5
- # to either the PowerShell Gallery (the default) or you can change
6
- # the $Repository property to the name of an alternate repository.
7
- #
8
- # The test task invokes Pester to run any Pester tests in your
9
- # workspace folder. Name your test scripts <TestName>.Tests.ps1
10
- # and Pester will find and run the tests contained in the files.
11
- #
12
- # You can run this build script directly using the invoke-psake
13
- # command which will execute the build task. This task "builds"
14
- # a temporary folder from which the module can be published.
15
- #
16
- # PS C:\> invoke-psake build.ps1
17
- #
18
- # You can run your Pester tests (if any) by running the following command.
19
- #
20
- # PS C:\> invoke-psake build.ps1 -taskList test
21
- #
22
- # You can execute the publish task with the following command. Note that
23
- # the publish task will run the test task first. The Pester tests must pass
24
- # before the publish task will run. The first time you run the publish
25
- # command, you will be prompted to enter your PowerShell Gallery NuGetApiKey.
26
- # After entering the key, it is encrypted and stored so you will not have to
27
- # enter it again.
28
- #
29
- # PS C:\> invoke-psake build.ps1 -taskList publish
30
- #
31
- # You can verify the stored and encrypted NuGetApiKey by running the following
32
- # command. This will display your NuGetApiKey in plain text!
33
- #
34
- # PS C:\> invoke-psake build.ps1 -taskList showKey
35
- #
36
- # You can store a new NuGetApiKey with this command. You can leave off
37
- # the -properties parameter and you'll be prompted for the key.
38
- #
39
- # PS C:\> invoke-psake build.ps1 -taskList storeKey -properties @{NuGetApiKey='test123'}
40
- #
41
1
42
2
# ##############################################################################
43
3
# Customize these properties for your module.
@@ -63,31 +23,18 @@ Properties {
63
23
(Split-Path $PSCommandPath - Leaf)
64
24
)
65
25
66
- # Name of the repository you wish to publish to. Default repo is the PSGallery.
67
- $PublishRepository = $null
68
-
69
- # Your NuGet API key for the PSGallery. Leave it as $null and the first time
70
- # you publish you will be prompted to enter your API key. The build will
71
- # store the key encrypted in a file, so that on subsequent publishes you
72
- # will no longer be prompted for the API key.
73
- $NuGetApiKey = $null
74
- $EncryptedApiKeyPath = " $env: LOCALAPPDATA \vscode-powershell\NuGetApiKey.clixml"
75
26
}
76
27
77
28
# ##############################################################################
78
29
# Customize these tasks for performing operations before and/or after publish.
79
30
# ##############################################################################
80
31
Task PrePublish {
81
32
$functionDeclarations = @ ( Get-ChildItem - Path $PublishDir \Public\* .ps1 - ErrorAction SilentlyContinue )
82
- $functionNames = @ ()
83
- foreach ($function in $functionDeclarations ) {
84
- $functionNames += $function.BaseName
85
- }
86
- $functionsToExport = $functionNames -join " ,"
33
+ [string []]$functionNames = @ ($functionDeclarations.BaseName )
87
34
88
35
Update-ModuleManifest - Path $PublishDir \${ModuleName}.psd1 `
89
- - ModuleVersion " 0.0.14 " `
90
- - FunctionsToExport $functionsToExport
36
+ - ModuleVersion " $ env: GitVersion_Version " `
37
+ - FunctionsToExport $functionNames
91
38
}
92
39
93
40
Task PostPublish {
@@ -102,8 +49,8 @@ Task default -depends Build
102
49
Task Publish - depends Test, PrePublish, PublishImpl, PostPublish {
103
50
}
104
51
105
- Task PublishImpl - depends Test - requiredVariables PublishDir, EncryptedApiKeyPath {
106
- $NuGetApiKey = Get-NuGetApiKey $NuGetApiKey $EncryptedApiKeyPath
52
+ Task PublishImpl - depends Test - requiredVariables PublishDir {
53
+ $NuGetApiKey = $ env: PSGalleryAPIToken
107
54
108
55
$publishParams = @ {
109
56
Path = $PublishDir
@@ -119,7 +66,7 @@ Task PublishImpl -depends Test -requiredVariables PublishDir, EncryptedApiKeyPat
119
66
120
67
Task Test - depends Build {
121
68
Import-Module Pester
122
- Invoke-Pester $PSScriptRoot
69
+ Invoke-Pester $PSScriptRoot / Tests
123
70
}
124
71
125
72
Task Build - depends Clean - requiredVariables PublishDir, Exclude, ModuleName {
@@ -148,58 +95,7 @@ Task Init -requiredVariables PublishDir {
148
95
}
149
96
}
150
97
151
- Task StoreKey - requiredVariables EncryptedApiKeyPath {
152
- if (Test-Path $EncryptedApiKeyPath ) {
153
- Remove-Item $EncryptedApiKeyPath
154
- }
155
-
156
- $null = Get-NuGetApiKey $NuGetApiKey $EncryptedApiKeyPath
157
- " The NuGetApiKey has been stored in $EncryptedApiKeyPath "
158
- }
159
-
160
- Task ShowKey - requiredVariables EncryptedApiKeyPath {
161
- $NuGetApiKey = Get-NuGetApiKey $NuGetApiKey $EncryptedApiKeyPath
162
- " The stored NuGetApiKey is: $NuGetApiKey "
163
- }
164
-
165
98
Task ? - description ' Lists the available tasks' {
166
99
" Available tasks:"
167
100
$psake.context.Peek ().tasks.Keys | Sort
168
101
}
169
-
170
- # ##############################################################################
171
- # Helper functions
172
- # ##############################################################################
173
- function Get-NuGetApiKey ($NuGetApiKey , $EncryptedApiKeyPath ) {
174
- $storedKey = $null
175
- if (! $NuGetApiKey ) {
176
- if (Test-Path $EncryptedApiKeyPath ) {
177
- $storedKey = Import-Clixml $EncryptedApiKeyPath | ConvertTo-SecureString
178
- $cred = New-Object - TypeName PSCredential - ArgumentList ' kh' , $storedKey
179
- $NuGetApiKey = $cred.GetNetworkCredential ().Password
180
- Write-Verbose " Retrieved encrypted NuGetApiKey from $EncryptedApiKeyPath "
181
- }
182
- else {
183
- $apiKeySS = Read-Host - Prompt " Enter your NuGet API Key" - AsSecureString
184
- $cred = New-Object - TypeName PSCredential - ArgumentList ' dw' , $apiKeySS
185
- $NuGetApiKey = $cred.GetNetworkCredential ().Password
186
- }
187
- }
188
-
189
- if (! $storedKey ) {
190
- # Store encrypted NuGet API key to use for future invocations
191
- if (! $apiKeySS ) {
192
- $apiKeySS = ConvertTo-SecureString - String $NuGetApiKey - AsPlainText - Force
193
- }
194
-
195
- $parentDir = Split-Path $EncryptedApiKeyPath - Parent
196
- if (! (Test-Path - Path $parentDir )) {
197
- $null = New-Item - Path $parentDir - ItemType Directory
198
- }
199
-
200
- $apiKeySS | ConvertFrom-SecureString | Export-Clixml $EncryptedApiKeyPath
201
- Write-Verbose " Stored encrypted NuGetApiKey to $EncryptedApiKeyPath "
202
- }
203
-
204
- $NuGetApiKey
205
- }
0 commit comments