Skip to content

Commit f44b4cb

Browse files
committed
Refactor publishing
1 parent 5ef2ce2 commit f44b4cb

4 files changed

Lines changed: 45 additions & 51 deletions

File tree

.gitignore

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
.apikey
2-
.*/
3-
!.template.config/
4-
bin/
5-
obj/
6-
packages/
7-
8-
.fake
9-
.ionide
1+
.*/
2+
!.template.config/
3+
bin/
4+
obj/
5+
packages/
6+
7+
.fake
8+
.ionide

Publish-Module.ps1

Lines changed: 0 additions & 26 deletions
This file was deleted.

Set-ApiKey.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<#
2+
.Synopsis
3+
Sets up storage for the API key.
4+
#>
5+
6+
#Requires -Version 7
7+
#Requires -Modules Microsoft.PowerShell.SecretManagement,Microsoft.PowerShell.SecretStore
8+
[CmdletBinding(ConfirmImpact='High',SupportsShouldProcess=$true)] Param()
9+
if(!(Get-SecretVault PowerShellGallery -ErrorAction SilentlyContinue))
10+
{
11+
Register-SecretVault PowerShellGallery -ModuleName Microsoft.PowerShell.SecretStore
12+
}
13+
$name = [io.path]::GetFileNameWithoutExtension((Resolve-Path $PSScriptRoot\*\*\*.psd1))
14+
if(!(Get-SecretInfo $name -Vault PowerShellGallery) -or $PSCmdlet.ShouldProcess('existing API key','update'))
15+
{
16+
$apikey = Get-Credential $name -Message 'Enter API key'
17+
Set-Secret $apikey.UserName -SecureStringSecret $apikey.Password -Vault PowerShellGallery
18+
}

src/PSModuleTemplate/PSModuleTemplate.fsproj

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
</ItemGroup>
2222

2323
<Target Name="SetAssemblyVersion" BeforeTargets="GetAssemblyVersion">
24-
<Exec Command='pwsh -nol -noni -nop -c "&amp; { Import-LocalizedData -BindingVariable m -FileName $(MSBuildProjectName); (gv m -va).ModuleVersion }"'
25-
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true">
24+
<Exec Command='pwsh -noni -nop -c "Import-LocalizedData -BindingVariable m -FileName $(MSBuildProjectName); (gv m -va).ModuleVersion"'
25+
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true">
2626
<Output TaskParameter="ConsoleOutput" PropertyName="Version" />
2727
</Exec>
2828
</Target>
@@ -31,37 +31,40 @@
3131

3232
<Target Name="Documentation" DependsOnTargets="Publish">
3333
<Copy SourceFiles="$(OutputPath)\publish\FSharp.Core.dll"
34-
DestinationFolder="$(OutputPath)" />
35-
<Exec Command='pwsh -nol -noni -nop -c "&amp; { Import-Module (Resolve-Path $(OutputPath)*.psd1); New-MarkdownHelp -Module $(MSBuildProjectName) -OutputFolder ..\..\docs -ea 0; Update-MarkdownHelp ..\..\docs; New-ExternalHelp ..\..\docs -OutputPath . -Force }"'
36-
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" />
34+
DestinationFolder="$(OutputPath)" />
35+
<Exec Command='pwsh -noni -nop -c "Import-Module (Resolve-Path $(OutputPath)*.psd1); New-MarkdownHelp -Module $(MSBuildProjectName) -OutputFolder ..\..\docs -ea 0; Update-MarkdownHelp ..\..\docs; New-ExternalHelp ..\..\docs -OutputPath . -Force"'
36+
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" />
3737
</Target>
3838

3939
<Target Name="test" DependsOnTargets="Pester" />
4040

4141
<Target Name="Pester" DependsOnTargets="Publish" Condition="'$(Configuration)' == 'Debug'">
4242
<Copy SourceFiles="$(OutputPath)\publish\FSharp.Core.dll"
43-
DestinationFolder="$(OutputPath)" />
44-
<Exec Command='pwsh -nol -noni -nop -c "&amp; { cd ..\..; Invoke-Pester }"'
45-
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" />
43+
DestinationFolder="$(OutputPath)" />
44+
<Exec Command='pwsh -noni -nop -c "cd ..\..; Invoke-Pester"'
45+
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" />
4646
</Target>
4747

4848
<ItemGroup>
4949
<PSModulePath Include="$(PSModulePath)" Exclude="C:\Program Files\**;C:\Windows\**;C:\ProgramData\chocolatey\**" />
5050
</ItemGroup>
5151

5252
<Target Name="PublishModule" DependsOnTargets="Publish" Condition="'$(Configuration)' == 'Release'">
53-
<RemoveDir Directories="@(PSModulePath->'%(FullPath)\$(MSBuildProjectName)')" />
53+
<RemoveDir Directories="@(PSModulePath-&gt;'%(FullPath)\$(MSBuildProjectName)')" />
5454
<Copy SourceFiles="$(OutputPath)\publish\FSharp.Core.dll" DestinationFolder="$(OutputPath)" />
5555
<ItemGroup><ModuleFiles Include="$(OutputPath)\*" /></ItemGroup>
56-
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="@(PSModulePath->'%(FullPath)\$(MSBuildProjectName)\$(Version)')" />
57-
<Error Text="To publish, first run: (Get-Credential API-key -Message &#x27;Enter your API key&#x27;).Password |ConvertFrom-SecureString |Out-File .\.apikey utf8"
58-
Condition="!Exists('..\..\.apikey')" />
59-
<Exec Command='pwsh -nol -noni -nop -c "&amp; { (New-Object PSCredential apikey,(Get-Content ..\..\.apikey |ConvertTo-SecureString)).GetNetworkCredential().Password }"'
60-
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" Condition="Exists('..\..\.apikey')">
56+
<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="@(PSModulePath-&gt;'%(FullPath)\$(MSBuildProjectName)\$(Version)')" />
57+
<Exec Command='pwsh -noni -nop -c "[bool](Get-SecretInfo $(MSBuildProjectName) -Vault PowerShellGallery)"'
58+
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true">
59+
<Output TaskParameter="ConsoleOutput" PropertyName="HasApiKey" />
60+
</Exec>
61+
<Error Text="To publish, first run: .\Set-ApiKey.ps1" Condition="!$(HasApiKey)" />
62+
<Exec Command='pwsh -nop -c "(New-Object PSCredential _,(Get-Secret $(MSBuildProjectName) -Vault PowerShellGallery)).GetNetworkCredential().Password"'
63+
ConsoleToMSBuild="true" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" Condition="$(HasApiKey)">
6164
<Output TaskParameter="ConsoleOutput" PropertyName="ApiKey" />
6265
</Exec>
63-
<Exec Command='pwsh -nol -noni -nop -c "&amp; { Import-Module $(MSBuildProjectName); Publish-Module -Name $(MSBuildProjectName) -NuGetApiKey $(ApiKey) }"'
64-
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" Condition="Exists('..\..\.apikey')" />
66+
<Exec Command='pwsh -noni -nop -c "Import-Module $(MSBuildProjectName); Publish-Module -Name $(MSBuildProjectName) -NuGetApiKey $(ApiKey)"'
67+
IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" Condition="$(HasApiKey)" />
6568
</Target>
6669

6770
</Project>

0 commit comments

Comments
 (0)