Created
April 12, 2017 23:06
-
-
Save gpduck/bea1f64d1c939f964fa4317b1a55f73e to your computer and use it in GitHub Desktop.
PSake Build Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Properties { | |
if(!$OutDir) { | |
$OutDir = "out" | |
} | |
if(!$ProjectDir) { | |
$ProjectDir = $PSake.build_script_dir | |
} | |
if(!$TargetDir) { | |
$TargetDir = Join-Path -Path $ProjectDir -ChildPath $OutDir | |
} | |
if(!$ProjectName) { | |
$ProjectName = Split-Path -Path $ProjectDir -Leaf | |
} | |
if(!$NuSpecFile) { | |
$NuSpecFile = Join-Path -Path $ProjectDir -ChildPath "$ProjectName.nuspec" | |
} | |
if(!$BasePath) { | |
$BasePath = $ProjectDir | |
} | |
if(!$NugetServer) { | |
$NugetServer = "http://mynugetserver/nuget" | |
} | |
} | |
Task default -Depends Pack,Publish | |
Task Build -Depends VersionModule | |
function GenerateVersion { | |
param($NuSpecFile) | |
$NuSpecXml = [Xml](Get-Content $NuSpecFile) | |
$NuSpecVersion = [Version]($NuSpecXml.Package.Metadata.Version) | |
$VersionDate = [int][Datetime]::Now.ToString("yyyyMMdd") | |
New-Object System.Version($NuSpecVersion.Major, $NuSpecVersion.Minor, $VersionDate, $BuildNumber) | |
} | |
Task VersionModule { | |
$OutputVersion = GenerateVersion -NuSpecFile $NuSpecFile | |
$ModuleFile = Join-Path -Path $ProjectDir -ChildPath "$ProjectName.psd1" | |
(Get-Item $ModuleFile).IsReadOnly = $false | |
(Get-Content $ModuleFile) -replace "ModuleVersion ?= ?['`"](\d+\.?){2,4}['`"]", "ModuleVersion = '$OutputVersion'" | Set-Content $ModuleFile | |
} | |
Task Pack -Depends Build { | |
ipmo ps-get | |
Assert (Test-Path $NuSpecFile) -FailureMessage "$NuSpecFile does not exist" | |
if(!(Test-Path $TargetDir)) { | |
mkdir $TargetDir > $null | |
} | |
$OutputVersion = GenerateVersion -NuSpecFile $NuSpecFile | |
exec { nuget pack $NuSpecFile -OutputDirectory $TargetDir -BasePath $BasePath -NoPackageAnalysis -NonInteractive -Version ($OutputVersion.ToString())} | |
$OutputFileName = "$ProjectName.$($OutputVersion.ToString()).nupkg" | |
$Script:OutputFilePath = Join-Path -Path $TargetDir -ChildPath $OutputFileName | |
} | |
Task Publish -Depends Pack { | |
ipmo ps-get | |
exec { nuget push $Script:OutputFilePath -Source $NugetServer -NonInteractive } | |
} | |
Task Clean { | |
if( (Test-Path $TargetDir) ) { | |
del $TargetDir -Recurse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment