Skip to content

Commit d3b01e2

Browse files
committed
Add Publish task, generate prerelease tag
The Prerelease tag in the module manifest is generated from the AssemblyInformationalAttribute in Microsoft.PowerShell.PSReadLine2.dll.
1 parent bbfcb33 commit d3b01e2

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

PSReadLine.build.ps1

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,23 @@ task LayoutModule BuildMainModule, BuildMamlHelp, {
191191
# Copy module manifest, but fix the version to match what we've specified in the binary module.
192192
$version = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine2.dll).VersionInfo.FileVersion
193193
$moduleManifestContent = Get-Content -Path 'PSReadLine/PSReadLine.psd1' -Raw
194-
[regex]::Replace($moduleManifestContent, "ModuleVersion = '.*'", "ModuleVersion = '$version'") | Set-Content -Path $targetDir/PSReadLine.psd1
194+
195+
$b = Get-Content -Encoding Byte -Raw ./bin/$Configuration/PSReadLine/Microsoft.PowerShell.PSReadLine2.dll
196+
$a = [System.Reflection.Assembly]::Load($b)
197+
$semVer = ($a.GetCustomAttributes([System.Reflection.AssemblyInformationalVersionAttribute], $false)).InformationalVersion
198+
199+
if ($semVer -match "(.*)-(.*)")
200+
{
201+
# Make sure versions match
202+
if ($matches[1] -ne $version) { throw "AssemblyFileVersion mismatch with AssemblyInformationalVersion" }
203+
$prerelease = $matches[2]
204+
205+
# Put the prerelease tag in private data
206+
$moduleManifestContent = [regex]::Replace($moduleManifestContent, "}", "PrivateData = @{ PSData = @{ Prerelease = '$prerelease' } }$([System.Environment]::Newline)}")
207+
}
208+
209+
$moduleManifestContent = [regex]::Replace($moduleManifestContent, "ModuleVersion = '.*'", "ModuleVersion = '$version'")
210+
$moduleManifestContent | Set-Content -Path $targetDir/PSReadLine.psd1
195211

196212
# Make sure we don't ship any read-only files
197213
foreach ($file in (Get-ChildItem -Recurse -File $targetDir))
@@ -238,6 +254,44 @@ task Install LayoutModule, {
238254
Install "$HOME\Documents\PowerShell\Modules"
239255
}
240256

257+
<#
258+
Synopsis: Publish to PSGallery
259+
#>
260+
task Publish -If ($Configuration -eq 'Release') LayoutModule, {
261+
262+
$manifest = Import-PowerShellDataFile $PSScriptRoot/bin/Release/PSReadLine/PSReadLine.psd1
263+
264+
$version = $manifest.ModuleVersion
265+
if ($null -ne $manifest.PrivateData)
266+
{
267+
$psdata = $manifest.PrivateData['PSData']
268+
if ($null -ne $psdata)
269+
{
270+
$prerelease = $psdata['Prerelease']
271+
if ($null -ne $prerelease)
272+
{
273+
$version = $version + '-' + $prerelease
274+
}
275+
}
276+
}
277+
278+
$yes = Read-Host "Publish version $version (y/n)"
279+
280+
if ($yes -ne 'y') { throw "Publish aborted" }
281+
282+
$nugetApiKey = Read-Host "Nuget api key for PSGallery"
283+
284+
$publishParams = @{
285+
Path = "$PSScriptRoot/bin/Release/PSReadLine"
286+
NuGetApiKey = $nugetApiKey
287+
Repository = "PSGallery"
288+
ReleaseNotes = (Get-Content -Raw $PSScriptRoot/bin/Release/PSReadLine/Changes.txt)
289+
ProjectUri = 'https://github.com/lzybkr/PSReadLine'
290+
}
291+
292+
Publish-Module @publishParams
293+
}
294+
241295
<#
242296
Synopsis: Default build rule - build and create module layout
243297
#>

PSReadLine/AssemblyInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// set of attributes. Change these attribute values to modify the information
1111
// associated with an assembly.
1212
[assembly: AssemblyTitle("PSReadLine")]
13-
[assembly: AssemblyDescription("")]
13+
[assembly: AssemblyDescription("Great command line editing in PowerShell")]
1414
[assembly: AssemblyConfiguration("")]
1515
[assembly: AssemblyCompany("")]
1616
[assembly: AssemblyProduct("PSReadLine")]
@@ -37,7 +37,8 @@
3737
// by using the '*' as shown below:
3838
// [assembly: AssemblyVersion("1.0.*")]
3939
[assembly: AssemblyVersion("2.0.0.0")]
40-
[assembly: AssemblyFileVersion("2.0")]
40+
[assembly: AssemblyFileVersion("2.0.0")]
41+
[assembly: AssemblyInformationalVersion("2.0.0-beta1")]
4142

4243

4344
[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]

0 commit comments

Comments
 (0)