Skip to content

Commit

Permalink
Add Publish task, generate prerelease tag
Browse files Browse the repository at this point in the history
The Prerelease tag in the module manifest is generated from the
AssemblyInformationalAttribute in Microsoft.PowerShell.PSReadLine2.dll.
  • Loading branch information
lzybkr committed Dec 6, 2017
1 parent bbfcb33 commit d3b01e2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
56 changes: 55 additions & 1 deletion PSReadLine.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,23 @@ task LayoutModule BuildMainModule, BuildMamlHelp, {
# Copy module manifest, but fix the version to match what we've specified in the binary module.
$version = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine2.dll).VersionInfo.FileVersion
$moduleManifestContent = Get-Content -Path 'PSReadLine/PSReadLine.psd1' -Raw
[regex]::Replace($moduleManifestContent, "ModuleVersion = '.*'", "ModuleVersion = '$version'") | Set-Content -Path $targetDir/PSReadLine.psd1

$b = Get-Content -Encoding Byte -Raw ./bin/$Configuration/PSReadLine/Microsoft.PowerShell.PSReadLine2.dll
$a = [System.Reflection.Assembly]::Load($b)
$semVer = ($a.GetCustomAttributes([System.Reflection.AssemblyInformationalVersionAttribute], $false)).InformationalVersion

if ($semVer -match "(.*)-(.*)")
{
# Make sure versions match
if ($matches[1] -ne $version) { throw "AssemblyFileVersion mismatch with AssemblyInformationalVersion" }
$prerelease = $matches[2]

# Put the prerelease tag in private data
$moduleManifestContent = [regex]::Replace($moduleManifestContent, "}", "PrivateData = @{ PSData = @{ Prerelease = '$prerelease' } }$([System.Environment]::Newline)}")
}

$moduleManifestContent = [regex]::Replace($moduleManifestContent, "ModuleVersion = '.*'", "ModuleVersion = '$version'")
$moduleManifestContent | Set-Content -Path $targetDir/PSReadLine.psd1

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

<#
Synopsis: Publish to PSGallery
#>
task Publish -If ($Configuration -eq 'Release') LayoutModule, {

$manifest = Import-PowerShellDataFile $PSScriptRoot/bin/Release/PSReadLine/PSReadLine.psd1

$version = $manifest.ModuleVersion
if ($null -ne $manifest.PrivateData)
{
$psdata = $manifest.PrivateData['PSData']
if ($null -ne $psdata)
{
$prerelease = $psdata['Prerelease']
if ($null -ne $prerelease)
{
$version = $version + '-' + $prerelease
}
}
}

$yes = Read-Host "Publish version $version (y/n)"

if ($yes -ne 'y') { throw "Publish aborted" }

$nugetApiKey = Read-Host "Nuget api key for PSGallery"

$publishParams = @{
Path = "$PSScriptRoot/bin/Release/PSReadLine"
NuGetApiKey = $nugetApiKey
Repository = "PSGallery"
ReleaseNotes = (Get-Content -Raw $PSScriptRoot/bin/Release/PSReadLine/Changes.txt)
ProjectUri = 'https://github.com/lzybkr/PSReadLine'
}

Publish-Module @publishParams
}

<#
Synopsis: Default build rule - build and create module layout
#>
Expand Down
5 changes: 3 additions & 2 deletions PSReadLine/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PSReadLine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Great command line editing in PowerShell")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PSReadLine")]
Expand All @@ -37,7 +37,8 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0")]
[assembly: AssemblyFileVersion("2.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0-beta1")]


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

0 comments on commit d3b01e2

Please sign in to comment.