1+ function New-GithubRelease {
2+ [CmdletBinding ()]
3+ param (
4+ [Parameter (Mandatory = $true )][String ]$Version ,
5+ [Parameter (Mandatory = $true )][String ]$Name ,
6+ [Parameter (Mandatory = $true )][String ]$ReleaseNotes ,
7+ [Parameter (Mandatory = $true )][String ]$OutputDirectory ,
8+ [Parameter (Mandatory = $true )][String ]$FileName ,
9+ [Parameter (Mandatory = $false )][String ]$GitHubUsername = " ffeldhaus" ,
10+ [Parameter (Mandatory = $false )][String ]$GitHubRepository = " StorageGRID-Webscale" ,
11+ [Parameter (Mandatory = $false )][switch ]$Draft = $false ,
12+ [Parameter (Mandatory = $false )][switch ]$PreRelease = $false
13+
14+ )
15+
16+ # The github API key must be available in $GitHubApiKey (https://github.com/blog/1509-personal-api-tokens)
17+
18+ # The Commit SHA for corresponding to this release
19+ $CommitId = git rev- list - n 1 $Version
20+
21+ $ReleaseData = @ {
22+ tag_name = $Version ;
23+ target_commitish = $CommitId ;
24+ name = $Name ;
25+ body = $ReleaseNotes ;
26+ draft = $Draft.IsPresent ;
27+ prerelease = $PreRelease.IsPresent ;
28+ }
29+
30+ $ReleaseParams = @ {
31+ Uri = " https://api.github.com/repos/$GitHubUsername /$GitHubRepository /releases" ;
32+ Method = ' POST' ;
33+ Headers = @ {
34+ Authorization = ' token ' + $GitHubApiKey ;
35+ }
36+ ContentType = ' application/json' ;
37+ Body = (ConvertTo-Json $releaseData - Compress)
38+ }
39+
40+ $Result = Invoke-RestMethod @ReleaseParams
41+ $UploadUri = $Result | Select - ExpandProperty upload_url
42+ $UploadUri = $UploadUri -replace ' \{\?name,label\}' , " ?name=$FileName "
43+ $UploadFile = Join-Path - path $OutputDirectory - childpath $FileName
44+
45+ $uploadParams = @ {
46+ Uri = $UploadUri ;
47+ Method = ' POST' ;
48+ Headers = @ {
49+ Authorization = ' token ' + $GitHubApiKey ;
50+ }
51+ ContentType = ' application/zip' ;
52+ InFile = $UploadFile
53+ }
54+
55+ $Result = Invoke-RestMethod @UploadParams
56+ }
57+
58+
159<#
260. SYNOPSIS
361Generates a manifest for the module and bundles all of the module source files and manifest into a distributable ZIP file.
462. DESCRIPTION
563Generates a manifest for the module and bundles all of the module source files and manifest into a distributable ZIP file.
664. EXAMPLE
7- New-OciRelease .
65+ New-SGWRelease .
866#>
967function New-SGWRelease {
1068 [CmdletBinding ()]
1169 param (
1270 [Parameter (Mandatory = $false )][String ]$Author = ' Florian Feldhaus' ,
1371 [Parameter (Mandatory = $false )][String ]$Company = ' NetApp Deutschland GmbH' ,
72+ [Parameter (Mandatory = $true )][String ]$Name ,
73+ [Parameter (Mandatory = $true )][String ]$ReleaseNotes ,
1474 [Parameter (Mandatory = $false )][switch ]$Major ,
1575 [Parameter (Mandatory = $false )][switch ]$Minor ,
1676 [Parameter (Mandatory = $false )][switch ]$Build ,
@@ -28,22 +88,30 @@ function New-SGWRelease {
2888 if ($Minor ) { $ModuleVersion = New-Object System.Version($ModuleVersion.Major , ($ModuleVersion.Minor + 1 ), 0 ) }
2989 if ($Build ) { $ModuleVersion = New-Object System.Version($ModuleVersion.Major , $ModuleVersion.Minor , ($ModuleVersion.Build + 1 )) }
3090
91+ Write-Host " Running Pester tests"
92+ # Invoke-SGWTests
93+
3194 Write-Host " Building release for version $ModuleVersion "
3295
3396 $scriptPath = Split-Path - LiteralPath $ (if ($PSVersionTable.PSVersion.Major -ge 3 ) { $PSCommandPath } else { & { $MyInvocation.ScriptName } })
3497
3598 $src = (Join-Path (Split-Path $PSScriptRoot ) ' src' )
3699 $dst = (Join-Path (Split-Path $PSScriptRoot ) ' release' )
100+ $out = (Join-Path (Split-Path $PSScriptRoot ) ' out' )
37101
38102 if (Test-Path $dst ) {
39103 Remove-Item $dst - Force - Recurse
40104 }
41- New-Item $dst - ItemType Directory | Out-Null
105+ New-Item $dst - ItemType Directory - Force | Out-Null
42106
43107 Write-Host " Creating module manifest..."
44108
45109 $manifestFileName = Join-Path $dst ' StorageGRID-Webscale.psd1'
46110
111+ $functionsToExport = Get-Command - Module StorageGRID- Webscale - Name *- SGW* | Select - ExpandProperty Name
112+
113+ $tags = @ (" StorageGRID-Webscale" , " SGW" , " NetApp" )
114+
47115 New-ModuleManifest `
48116 - Path $manifestFileName `
49117 - ModuleVersion $ModuleVersion `
@@ -53,14 +121,19 @@ function New-SGWRelease {
53121 - Copyright " (c) $ ( (Get-Date ).Year) NetApp Deutschland GmbH. All rights reserved." `
54122 - Description ' StorageGRID-Webscale Powershell Cmdlet.' `
55123 - PowerShellVersion ' 3.0' `
56- - DotNetFrameworkVersion ' 3 .5' `
124+ - DotNetFrameworkVersion ' 4 .5' `
57125 - NestedModules (Get-ChildItem $src \* .psm1, $src \* .dll | % { $_.Name }) `
58- - FormatsToProcess (Get-ChildItem $src \* .format.ps1xml | % { $_.Name })
126+ - FormatsToProcess (Get-ChildItem $src \* .format.ps1xml | % { $_.Name }) `
127+ - LicenseUri " https://github.com/ffeldhaus/StorageGRID-Webscale/blob/master/LICENSE" `
128+ - ProjectUri " https://github.com/ffeldhaus/StorageGRID-Webscale" `
129+ - RootModule " StorageGRID-Webscale" `
130+ - FunctionsToExport $functionsToExport `
131+ - Tags $tags
59132
60133 Write-Host " Copying file to release folder..."
61134
62- # Copy the distributable files to the dist folder.
63- Copy-Item - Path " $src \*" `
135+ # Copy the Module files to the dist folder.
136+ Copy-Item - Path " $src \*.psm1 " `
64137 - Destination $dst `
65138 - Recurse
66139
@@ -69,18 +142,21 @@ function New-SGWRelease {
69142 Copy-Item - Path " $scriptPath \..\README.md" `
70143 - Destination " $dst \README.txt"
71144
145+ Copy-Item - Path " $scriptPath \..\LICENSE" `
146+ - Destination " $dst \LICENSE"
147+
72148 Write-Host " Signing PowerShell files..."
73149
74150 # Code Signing
75151 $cert = Get-ChildItem cert:\CurrentUser\My - CodeSigningCert
76152 Get-ChildItem $dst \* .ps* | % { $_.FullName } | Set-AuthenticodeSignature - Certificate $cert | Out-Null
77-
153+
78154 Write-Host " Creating the release archive..."
79155
80156 # Requires .NET 4.5
81157 [Reflection.Assembly ]::LoadWithPartialName(" System.IO.Compression.FileSystem" ) | Out-Null
82158
83- $zipFileName = Join-Path ([ System.IO.Path ]::GetDirectoryName( $dst )) " $ ( [ System.IO.Path ]::GetFileNameWithoutExtension( $manifestFileName ) ) .zip"
159+ $zipFileName = Join-Path $out " StorageGRID-Webscale .zip"
84160
85161 # Overwrite the ZIP if it already already exists.
86162 if (Test-Path $zipFileName ) {
@@ -91,24 +167,49 @@ function New-SGWRelease {
91167 $includeBaseDirectory = $false
92168 [System.IO.Compression.ZipFile ]::CreateFromDirectory($dst , $zipFileName , $compressionLevel , $includeBaseDirectory )
93169
94- Move-Item $zipFileName $dst - Force
170+ Write-Host " Release zip file $zipFileName successfully created!" - ForegroundColor Green
171+
172+ Write-Host " Creating MSI installers..."
173+ Start-WixBuild - Path $dst - OutputFolder $out - ProductShortName " StorageGRID-Webscale" - ProductName " StorageGRID-Webscale PowerShell Cmdlets" - ProductVersion $ModuleVersion - Manufacturer $Author - IconFile $PSScriptRoot \icon.ico - BannerFile $PSScriptRoot \banner.bmp - DialogFile $PSScriptRoot \dialog.bmp - UpgradeCodeX86 " CCEE2853-0FC5-4D1B-8485-4625D9D75CF8" - UpgradeCodeX64 " 7A7CD8B3-CD26-4829-8E05-08D7D9CFA5CA"
95174
96- Write-Host " Release file $zipFileName successfully created!" - ForegroundColor Green
175+ Write-Host " Release MSI Installer OnCommand_Insight_$ ( $ModuleVersion ) _x64.msi and OnCommand_Insight_$ ( $ModuleVersion ) _x86.msi successfully created!" - ForegroundColor Green
176+
177+ Remove-Item $dst \.wix.json
97178
98179 if ($Release ) {
99- git pull
100- git tag $ModuleVersion
101- if ($Major -or $Minor ) {
102- git branch $ModuleVersion
180+ Write-Host " Publishing Module to PowerShell Gallery"
181+ Publish-Module - Name " StorageGRID-Webscale" - NuGetApiKey $NuGetApiKey
182+
183+ Write-Host " Creating git tag"
184+ & git pull
185+ & git tag $ModuleVersion
186+ if ($Major ) {
187+ Write-Host " Creating new git branch"
188+ & git branch $ModuleVersion
103189 Write-Host " New Git Branch $ModuleVersion created"
104190 }
105191 try {
106- git push 2> $null
107- git push -- all 2> $null
108- git push -- tags 2> $null
192+ & git push 2> $null
193+ & git push -- all 2> $null
194+ & git push -- tags 2> $null
109195 }
110196 catch {
111197 }
112- Write-Host " New Git tag $ModuleVersion created"
198+
199+ Write-Host " Creating GitHub release"
200+ New-GithubRelease - Version $ModuleVersion - Name $Name - ReleaseNotes $ReleaseNotes - FileName " StorageGRID-Webscale.zip" - OutputDirectory $out
201+ }
202+ }
203+
204+ function Invoke-SGWTests {
205+ $SGWServer = ' localhost'
206+ $SGWCredential = New-Object - TypeName System.Management.Automation.PSCredential - ArgumentList " root" , (" netapp01" | ConvertTo-SecureString - AsPlainText - Force)
207+
208+ $VerbosePreference = " Continue"
209+
210+ $Result = Invoke-Pester - Script @ {Path = ' ./' ;Parameters = @ {Server = $SGWServer ;Credential = $SGWCredential ;Version = $Version ;Record = $Record }} - PassThru
211+
212+ if ($Result.FailedCount -gt 0 ) {
213+ Write-Error " Aborting due to test errors"
113214 }
114215}
0 commit comments