1- $Properties = @ {
2- CertificateThumbprint = ' D10BB31E5CE3048A7D4DA0A4DD681F05A85504D3' ;
3- ReleaseDirectory = ' .\Releases' ;
4- TimeStampServer = ' http://timestamp.verisign.com/scripts/timestamp.dll' ;
5- LicenseUrl = ' https://raw.githubusercontent.com/VirtualEngine/ZipArchive/master/LICENSE' ;
6- DownloadBaseUrl = ' http://virtualengine.co.uk/wp-content/uploads' ;
7- }
8-
9- Import-Module VirtualEngine.Build - ErrorAction Stop;
10- # Import-Module Posh-SSH -ErrorAction Stop;
11-
12- $module = Get-ModuleManifest ;
13- $packageName = " $ ( $module.Name.Replace (' .' , ' -' )) -$ ( $module.Version.ToString ()) " ;
14- $tempDirectory = Join-Path $env: TEMP $module.Name ;
15- $zipDirectory = Join-Path $tempDirectory $module.Name ;
16-
17- task Default - depends CreateReleaseZip, CreateChocolateyReleasePackage, RemoveReleaseDirectory
18-
19- task CreateReleaseZipDirectory {
20- Remove-Item - Path $tempDirectory - Recurse - Force - ErrorAction SilentlyContinue;
21- [ref ] $null = New-Item - Path $zipDirectory - ItemType Container;
22- }
23-
24- task StageReleaseZipFiles - depends CreateReleaseZipDirectory {
25-
26- $codeSigningCert = Get-ChildItem Cert:\ - CodeSigningCert - Recurse | Where Thumbprint -eq $Properties.CertificateThumbprint ;
27-
28- foreach ($moduleFile in Get-ModuleFiles ) {
29- Copy-Item - Path $moduleFile.FullName - Destination $zipDirectory - Force;
30-
31- if ($moduleFile.Extension -in ' .ps1' , ' .psm1' ) {
32- $moduleFilePath = Join-Path $zipDirectory $moduleFile.Name ;
33- Write-Verbose (" Signing file '{0}'." -f $moduleFilePath );
34- $signResult = Set-ScriptSigntaure - Path $moduleFilePath - Thumbprint $Properties.CertificateThumbprint - TimeStampServer $Properties.TimeStampServer ;
35- }
36- }
37- }
38-
39- task CreateReleaseZip - depends StageReleaseZipFiles {
40- $releaseDirectory = Resolve-Path (Join-Path . $Properties.ReleaseDirectory );
41- $zipFileName = Join-Path $releaseDirectory (" {0}.zip" -f $packageName );
42- Write-Verbose (" Zip release path '{0}'." -f $zipFileName );
43- $zipFile = New-ZipArchive - Path $tempDirectory - DestinationPath $zipFileName ;
44- Write-Verbose (" Zip archive '{0}' created." -f $zipFile.FullName );
45- }
46-
47- task CreateChocolateyReleaseDirectory {
48- Remove-Item - Path $tempDirectory - Recurse - Force - ErrorAction SilentlyContinue;
49- [ref ] $null = New-Item - Path $tempDirectory - ItemType Container;
50- [ref ] $null = New-Item - Path " $tempDirectory \tools" - ItemType Container;
51- }
52-
53- task StageChocolateyReleaseFiles - depends CreateChocolateyReleaseDirectory {
54- # # Create .nuspec
55- $nuspec = $module | New-NugetNuspec - LicenseUrl $Properties.LicenseUrl ;
56- $nuspecFilename = " $ ( $module.Name ) .nuspec" ;
57- $nuspecPath = Join-Path $tempDirectory $nuspecFilename ;
58- $nuspec.Save ($nuspecPath );
59-
60- # # Create \Tools\ChocolateyInstall.ps1
61- $chocolateyInstallPath = Join-Path (Get-Location ) ' ChocolateyInstall.ps1' ;
62- Copy-Item - Path $chocolateyInstallPath - Destination " $tempDirectory \tools\" - Force;
63-
64- # # Add Install-ChocolateyZipPackage to the ChocolateyInstall.ps1 file with the relevant download link
65- $downloadUrl = " $ ( $Properties.DownloadBaseUrl ) /$packageName .zip" ;
66- $installChocolateyZipPackage = " Install-ChocolateyZipPackage '{0}' '{1}' '$userPSModulePath ';" -f $packageName , $downloadUrl ;
67- Add-Content - Path " $tempDirectory \tools\ChocolateyInstall.ps1" - Value $installChocolateyZipPackage ;
68- }
69-
70- task CreateChocolateyReleasePackage - depends StageChocolateyReleaseFiles {
71-
72- $releaseDirectory = Resolve-Path (Join-Path . $Properties.ReleaseDirectory );
73- Push-Location $tempDirectory ;
74- Invoke-Expression - Command (' Nuget Pack "{0}" -OutputDirectory "{1}"' -f $nuspecFileName , $releaseDirectory );
75- Pop-Location ;
76- }
77-
78- task PushReleaseZip - depends CreateReleaseZip {
79- Import-Module Posh- SSH;
80-
81- }
82-
83- task RemoveReleaseDirectory {
84- Remove-Item - Path $tempDirectory - Recurse - Force - ErrorAction SilentlyContinue;
85- }
1+ # requires -Module VirtualEngine .Build , VirtualEngine .Compression ;
2+ # requires -Version 3 ;
3+
4+ Properties {
5+ $currentDir = Resolve-Path - Path .;
6+ $basePath = $psake.build_script_dir ;
7+ $buildDir = ' Build' ;
8+ $releaseDir = ' Release' ;
9+ $invocation = (Get-Variable MyInvocation - Scope 1 ).Value;
10+ $thumbprint = ' D10BB31E5CE3048A7D4DA0A4DD681F05A85504D3' ;
11+ $timeStampServer = ' http://timestamp.verisign.com/scripts/timestamp.dll' ;
12+ $company = ' Virtual Engine Limited' ;
13+ $author = ' Iain Brighton' ;
14+ $githubTokenPath = ' ~\Github.apitoken' ;
15+ $githubOwner = ' VirtualEngine' ;
16+ $githubRepository = ' Compression'
17+ $chocolateyTokenPath = ' ~\Chocolatey.apitoken' ;
18+ $chocolateyPackageName = ' VirtualEngine-Compression' ;
19+ }
20+
21+ Task Default - Depends Build;
22+ Task Build - Depends Clean , Setup, Test, Deploy;
23+ Task Stage - Depends Build, Version, Sign, Zip;
24+ Task Publish - Depends Stage, Release, Chocolatey;
25+
26+ Task Clean {
27+ # # Remove build directory
28+ $baseBuildPath = Join-Path - Path $psake.build_script_dir - ChildPath $buildDir ;
29+ if (Test-Path - Path $baseBuildPath ) {
30+ Write-Host (' Removing build base directory "{0}".' -f $baseBuildPath ) - ForegroundColor Yellow;
31+ Remove-Item $baseBuildPath - Recurse - Force - ErrorAction Stop;
32+ }
33+ }
34+
35+ Task Setup {
36+ # Properties are not available in the script scope.
37+ Set-Variable manifest - Value (Get-ModuleManifest ) - Scope Script;
38+ Set-Variable buildPath - Value (Join-Path - Path $psake.build_script_dir - ChildPath " $buildDir \$ ( $manifest.Name ) " ) - Scope Script;
39+ Set-Variable chocolateyBuildPath - Value (Join-Path - Path $psake.build_script_dir - ChildPath " $buildDir \Chocolatey" ) - Scope Script;
40+ Set-Variable releasePath - Value (Join-Path - Path $psake.build_script_dir - ChildPath $releaseDir ) - Scope Script;
41+ Set-Variable version - Value ($manifest.Version.ToString ()) - Scope Script;
42+
43+ Write-Host (' Building module "{0}".' -f $manifest.Name ) - ForegroundColor Yellow;
44+ Write-Host (' Using module version "{0}".' -f $version ) - ForegroundColor Yellow;
45+
46+ # # Create the build directory
47+ Write-Host (' Creating build directory "{0}".' -f $buildPath ) - ForegroundColor Yellow;
48+ [Ref ] $null = New-Item $buildPath - ItemType Directory - Force - ErrorAction Stop;
49+
50+ # # Create the release directory
51+ if (! (Test-Path - Path $releasePath )) {
52+ Write-Host (' Creating release directory "{0}".' -f $releasePath ) - ForegroundColor Yellow;
53+ [Ref ] $null = New-Item $releasePath - ItemType Directory - Force - ErrorAction Stop;
54+ }
55+ }
56+
57+ Task Test {
58+ $testResultsPath = Join-Path $buildPath - ChildPath ' NUnit.xml' ;
59+ $testResults = Invoke-Pester - Path $basePath - OutputFile $testResultsPath - OutputFormat NUnitXml - PassThru - Strict;
60+ if ($testResults.FailedCount -gt 0 ) {
61+ Write-Error (' {0} unit tests failed.' -f $testResults.FailedCount );
62+ }
63+ }
64+
65+ Task Deploy {
66+ # # Update license
67+ $licensePath = Join-Path - Path $buildPath - ChildPath LICENSE;
68+ Write-Host (' Creating license file "{0}".' -f $licensePath ) - ForegroundColor Yellow;
69+ [Ref ] $null = New-ModuleLicense - Path $licensePath - LicenseType MIT - FullName $company ;
70+ # # Copy release files
71+ Write-Host (' Copying release files to build directory "{0}".' -f $buildPath ) - ForegroundColor Yellow;
72+ $excludedFiles = @ ( ' *.Tests.ps1' , ' Build.PSake.ps1' , ' .git*' , ' *.png' , ' Build' , ' Release' );
73+ Get-ModuleFile - Exclude $excludedFiles | % {
74+ $destinationPath = ' {0}{1}' -f $buildPath , $PSItem.FullName.Replace ($basePath , ' ' );
75+ [Ref ] $null = New-Item - ItemType File - Path $destinationPath - Force;
76+ Copy-Item - Path $PSItem.FullName - Destination $destinationPath - Force;
77+ }
78+ }
79+
80+ Task Version {
81+ # # Version module manifest prior to build
82+ $manifestPath = Join-Path $buildPath - ChildPath " $ ( $manifest.Name ) .psd1" ;
83+ Set-Variable version - Value (' {0}.{1}.{2}.{3}' -f $manifest.Version.Major , $manifest.Version.Minor , $manifest.Version.Build , (Get-GitRevision )) - Scope Script - Force;
84+ Write-Host (' Versioning module manifest "{0}" as version "{1}".' -f $manifestPath , $version ) - ForegroundColor Yellow;
85+ Set-ModuleManifestProperty - Path $manifestPath - Version $version - CompanyName $company - Author $author ;
86+ # # Reload module manifest to ensure the version number is picked back up
87+ Set-Variable manifest - Value (Get-ModuleManifest - Path $manifestPath ) - Scope Script - Force;
88+ }
89+
90+ Task Sign {
91+ Get-ChildItem - Path $buildPath - Include * .ps* - Recurse - File | % {
92+ Write-Host (' Signing file "{0}":' -f $PSItem.FullName ) - ForegroundColor Yellow - NoNewline;
93+ $signResult = Set-ScriptSignature - Path $PSItem.FullName - Thumbprint $thumbprint - TimeStampServer $timeStampServer - ErrorAction Stop;
94+ Write-Host (' {0}.' -f $signResult.Status ) - ForegroundColor Green;
95+ }
96+ }
97+
98+ Task Zip {
99+ # # Creates the release files in the $releaseDir
100+ $zipReleaseName = ' {0}-v{1}.zip' -f $manifest.Name , $version ;
101+ $zipPath = Join-Path - Path $releasePath - ChildPath $zipReleaseName ;
102+ Write-Host (' Creating zip file "{0}".' -f $zipPath ) - ForegroundColor Yellow;
103+ # # Zip the parent directory
104+ $zipSourcePath = Split-Path - Path $buildPath - Parent;
105+ $zipFile = New-ZipArchive - Path $zipSourcePath - DestinationPath $zipPath ;
106+ Write-Host (' Zip file "{0}" created.' -f $zipFile.Fullname ) - ForegroundColor Yellow;
107+ }
108+
109+ Task Release {
110+ # # Create a Github release
111+ $githubApiKey = (New-Object System.Management.Automation.PSCredential ' OAUTH' , (Get-Content - Path $githubTokenPath | ConvertTo-SecureString )).GetNetworkCredential().Password;
112+ Write-Host (' Creating new Github "{0}" release in repository "{1}/{2}".' -f $version , $githubOwner , $githubRepository ) - ForegroundColor Yellow;
113+ $release = New-GitHubRelease - Version $version - Repository $manifest.Name - Owner $githubOwner - ApiKey $githubApiKey ;
114+ if ($release ) {
115+ # # Creates the release files in the $releaseDir
116+ $zipReleaseName = ' {0}-v{1}.zip' -f $manifest.Name , $version ;
117+ $zipPath = Join-Path - Path $releasePath - ChildPath $zipReleaseName ;
118+ Write-Host (' Uploading asset "{0}".' -f $zipPath ) - ForegroundColor Yellow;
119+ $asset = Invoke-GitHubAssetUpload - Release $release - ApiKey $githubApiKey - Path $zipPath ;
120+ Set-Variable - Name assetUri - Value $asset.Browser_Download_Url - Scope Script - Force;
121+ }
122+ }
123+
124+ Task Chocolatey {
125+ # # Create the Chocolatey folder
126+ Write-Host (' Creating Chocolatey directory "{0}".' -f $chocolateyBuildPath ) - ForegroundColor Yellow;
127+ [Ref ] $null = New-Item $chocolateyBuildPath - ItemType Directory - Force - ErrorAction Stop;
128+ $chocolateyToolsPath = New-Item " $chocolateyBuildPath \tools" - ItemType Directory - Force - ErrorAction Stop;
129+
130+ # # Create the Chocolatey package
131+ $nuspecFilename = ' {0}.nuspec' -f $chocolateyPackageName ;
132+ $nuspecPath = Join-Path - Path $chocolateyBuildPath - ChildPath $nuspecFilename ;
133+ Write-Host (' Creating Nuget specification "{0}".' -f $nuspecPath ) - ForegroundColor Yellow;
134+
135+ $nugetSpecParam = @ {
136+ Name = ' VirtualEngine-Compression' ;
137+ Version = $version ;
138+ Title = ' VirtualEngine-Compression' ;
139+ Authors = $manifest.Author ;
140+ Owners = $manifest.CompanyName ;
141+ Description = $manifest.Description ;
142+ ProjectUrl = $manifest.PrivateData.PSData.ProjectUri ;
143+ IconUrl = $manifest.PrivateData.PSData.IconUri ;
144+ LicenseUrl = $manifest.PrivateData.PSData.LicenseUri ;
145+ Tags = $manifest.PrivateData.PSData.Tags ;
146+ };
147+ (New-NuGetNuspec @nugetSpecParam ).Save($nuspecPath );
148+
149+ Write-Host ' Creating Chocolatey install files.' - ForegroundColor Yellow;
150+ $zipReleaseName = ' {0}-v{1}.zip' -f $manifest.Name , $version ;
151+ $assetUri = ' https://github.com/VirtualEngine/Compression/releases/download/v{0}/{1}' -f $version , $zipReleaseName ;
152+ New-ChocolateyInstallZipModule - Path $chocolateyToolsPath.FullName - PackageName $chocolateyPackageName - Uri $assetUri ;
153+ # # Fix period replacement in package name - curses to the Chocolatey Gods :@
154+ $chocolateyUninstallPath = ' {0}\ChocolateyUninstall.ps1' -f $chocolateyToolsPath.FullName ;
155+ (Get-Content - Path $chocolateyUninstallPath ) | % { $_ -replace $chocolateyPackageName , $Manifest.Name } | Set-Content - Path $chocolateyUninstallPath - Encoding UTF8;
156+ Write-Host (' Creating Nuget package from "{0}".' -f $nuspecPath ) - ForegroundColor Yellow;
157+ $nugetOutput = Invoke-NuGetPack - Path $nuspecPath - DestinationPath $releasePath ;
158+ if ($nugetOutput ) {
159+ $nugetPackagePath = Join-Path - Path $releasePath - ChildPath (' {0}.{1}.nupkg' -f $chocolateyPackageName.ToLower (), $version );
160+ Write-Host (' Chocolatey package "{0}" created.' -f $nugetPackagePath ) - ForegroundColor Yellow;
161+ $chocolateyApiKey = (New-Object System.Management.Automation.PSCredential ' OAUTH' , (Get-Content - Path $chocolateyTokenPath | ConvertTo-SecureString )).GetNetworkCredential().Password;
162+ Write-Host (' Pushing Chocolatey package "{0}".' -f $nugetPackagePath ) - ForegroundColor Yellow;
163+ }
164+ }
0 commit comments