@@ -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