Skip to content

Commit e91003a

Browse files
committed
!deploy v0.1.0 - First release after fixes to enable passing tests in PS5.1
## 0.1.0 - Initial release to the PowerShell Gallery - Included functions are `Protect-PEMString` and `Unprotect-PEMString` - Fixed deployment issue
1 parent 42f23ee commit e91003a

2 files changed

Lines changed: 81 additions & 79 deletions

File tree

ci/BuildHelpers.ps1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,79 @@ function Add-EnvironmentSummary {
290290
''
291291
) | Write-Host
292292
}
293+
294+
function Publish-GitHubRelease {
295+
<#
296+
.SYNOPSIS
297+
Publishes a release to GitHub Releases. Borrowed from https://www.herebedragons.io/powershell-create-github-release-with-artifact
298+
#>
299+
[CmdletBinding()]
300+
Param (
301+
[parameter(Mandatory = $true)]
302+
[String]
303+
$VersionNumber,
304+
[parameter(Mandatory = $false)]
305+
[String]
306+
$CommitId = 'master',
307+
[parameter(Mandatory = $true)]
308+
[String]
309+
$ReleaseNotes,
310+
[parameter(Mandatory = $true)]
311+
[ValidateScript( {Test-Path $_})]
312+
[String]
313+
$ArtifactPath,
314+
[parameter(Mandatory = $true)]
315+
[String]
316+
$GitHubUsername,
317+
[parameter(Mandatory = $true)]
318+
[String]
319+
$GitHubRepository,
320+
[parameter(Mandatory = $true)]
321+
[String]
322+
$GitHubApiKey,
323+
[parameter(Mandatory = $false)]
324+
[Switch]
325+
$PreRelease,
326+
[parameter(Mandatory = $false)]
327+
[Switch]
328+
$Draft
329+
)
330+
$releaseData = @{
331+
tag_name = [string]::Format("v{0}", $VersionNumber)
332+
target_commitish = $CommitId
333+
name = [string]::Format("$($env:BHProjectName) v{0}", $VersionNumber)
334+
body = $ReleaseNotes
335+
draft = [bool]$Draft
336+
prerelease = [bool]$PreRelease
337+
}
338+
339+
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic"))
340+
341+
$releaseParams = @{
342+
Uri = "https://api.github.com/repos/$GitHubUsername/$GitHubRepository/releases"
343+
Method = 'POST'
344+
Headers = @{
345+
Authorization = $auth
346+
}
347+
ContentType = 'application/json'
348+
Body = (ConvertTo-Json $releaseData -Compress)
349+
}
350+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
351+
$result = Invoke-RestMethod @releaseParams
352+
$uploadUri = $result | Select-Object -ExpandProperty upload_url
353+
$uploadUri = $uploadUri -creplace '\{\?name,label\}'
354+
$artifact = Get-Item $ArtifactPath
355+
$uploadUri = $uploadUri + "?name=$($artifact.Name)"
356+
$uploadFile = $artifact.FullName
357+
358+
$uploadParams = @{
359+
Uri = $uploadUri
360+
Method = 'POST'
361+
Headers = @{
362+
Authorization = $auth
363+
}
364+
ContentType = 'application/zip'
365+
InFile = $uploadFile
366+
}
367+
$result = Invoke-RestMethod @uploadParams
368+
}

psake.ps1

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -146,81 +146,6 @@ task Test -Depends Init {
146146

147147

148148
$deployScriptBlock = {
149-
function Publish-GitHubRelease {
150-
<#
151-
.SYNOPSIS
152-
Publishes a release to GitHub Releases. Borrowed from https://www.herebedragons.io/powershell-create-github-release-with-artifact
153-
#>
154-
[CmdletBinding()]
155-
Param (
156-
[parameter(Mandatory = $true)]
157-
[String]
158-
$VersionNumber,
159-
[parameter(Mandatory = $false)]
160-
[String]
161-
$CommitId = 'master',
162-
[parameter(Mandatory = $true)]
163-
[String]
164-
$ReleaseNotes,
165-
[parameter(Mandatory = $true)]
166-
[ValidateScript( {Test-Path $_})]
167-
[String]
168-
$ArtifactPath,
169-
[parameter(Mandatory = $true)]
170-
[String]
171-
$GitHubUsername,
172-
[parameter(Mandatory = $true)]
173-
[String]
174-
$GitHubRepository,
175-
[parameter(Mandatory = $true)]
176-
[String]
177-
$GitHubApiKey,
178-
[parameter(Mandatory = $false)]
179-
[Switch]
180-
$PreRelease,
181-
[parameter(Mandatory = $false)]
182-
[Switch]
183-
$Draft
184-
)
185-
$releaseData = @{
186-
tag_name = [string]::Format("v{0}", $VersionNumber)
187-
target_commitish = $CommitId
188-
name = [string]::Format("$($env:BHProjectName) v{0}", $VersionNumber)
189-
body = $ReleaseNotes
190-
draft = [bool]$Draft
191-
prerelease = [bool]$PreRelease
192-
}
193-
194-
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic"))
195-
196-
$releaseParams = @{
197-
Uri = "https://api.github.com/repos/$GitHubUsername/$GitHubRepository/releases"
198-
Method = 'POST'
199-
Headers = @{
200-
Authorization = $auth
201-
}
202-
ContentType = 'application/json'
203-
Body = (ConvertTo-Json $releaseData -Compress)
204-
}
205-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
206-
$result = Invoke-RestMethod @releaseParams
207-
$uploadUri = $result | Select-Object -ExpandProperty upload_url
208-
$uploadUri = $uploadUri -creplace '\{\?name,label\}'
209-
$artifact = Get-Item $ArtifactPath
210-
$uploadUri = $uploadUri + "?name=$($artifact.Name)"
211-
$uploadFile = $artifact.FullName
212-
213-
$uploadParams = @{
214-
Uri = $uploadUri
215-
Method = 'POST'
216-
Headers = @{
217-
Authorization = $auth
218-
}
219-
ContentType = 'application/zip'
220-
InFile = $uploadFile
221-
}
222-
$result = Invoke-RestMethod @uploadParams
223-
}
224149
if (($ENV:BHBuildSystem -eq 'VSTS' -and $env:BHCommitMessage -match '!deploy' -and $env:BHBranchName -eq "master") -or $global:ForceDeploy -eq $true) {
225150
if ($null -eq (Get-Module PoshTwit -ListAvailable)) {
226151
" Installing PoshTwit module..."
@@ -233,11 +158,12 @@ $deployScriptBlock = {
233158
$commitVer = $commParsed.Matches.Value.Trim().Replace('v','')
234159
}
235160
$curVer = (Get-Module $env:BHProjectName).Version
236-
$galVer = if ($moduleInGallery = Find-Module "$env:BHProjectName*" -Repository PSGallery) {
237-
$moduleInGallery.Version.ToString()
161+
if ($moduleInGallery = Find-Module "$env:BHProjectName*" -Repository PSGallery) {
162+
$galVer = $moduleInGallery.Version.ToString()
163+
" Current version on the PSGallery is: $galVer"
238164
}
239165
else {
240-
'0.0.1'
166+
$galVer = '0.0.1'
241167
}
242168
$galVerSplit = $galVer.Split('.')
243169
$nextGalVer = [System.Version](($galVerSplit[0..($galVerSplit.Count - 2)] -join '.') + '.' + ([int]$galVerSplit[-1] + 1))
@@ -362,7 +288,7 @@ $deployScriptBlock = {
362288
}
363289
}
364290
catch {
365-
Write-Error $_ -ErrorAction Stop
291+
Write-BuildError $_
366292
}
367293
}
368294
else {

0 commit comments

Comments
 (0)