Skip to content

Commit 335d277

Browse files
author
JustinGrote
committed
Fix Github Release Issues
1 parent ade9416 commit 335d277

1 file changed

Lines changed: 46 additions & 46 deletions

File tree

PSModule.build.ps1

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ param (
2626
#Initialize Build Environment
2727
Enter-Build {
2828
#Initialize Script-scope variables
29-
New-Variable ArtifactPaths
30-
New-Variable ProjectVersion
31-
New-Variable ProjectBuildPath
29+
$ArtifactPaths = @()
30+
$ProjectBuildVersion = $null
31+
$ProjectBuildPath = $null
3232

3333
$lines = '----------------------------------------------------------------'
3434
function Write-VerboseHeader ([String]$Message) {
@@ -345,12 +345,12 @@ task Pester {
345345

346346
task Package Version,{
347347

348-
$ZipArchivePath = (join-path $env:BHBuildOutput "$env:BHProjectName-$ProjectVersion.zip")
348+
$ZipArchivePath = (join-path $env:BHBuildOutput "$env:BHProjectName-$ProjectBuildVersion.zip")
349349
write-build green "Task $($task.name)`: Writing Finished Module to $ZipArchivePath"
350350
#Package the Powershell Module
351351
Compress-Archive -Path $ProjectBuildPath -DestinationPath $ZipArchivePath -Force @PassThruParams
352352

353-
$Artifacts += $ZipArchivePath
353+
$SCRIPT:ArtifactPaths += $ZipArchivePath
354354
#If we are in Appveyor, push completed zip to Appveyor Artifact
355355
if ($env:APPVEYOR) {
356356
write-build Green "Task $($task.name)`: Detected Appveyor, pushing Powershell Module archive to Artifacts"
@@ -384,36 +384,6 @@ task PreDeploymentChecks {
384384
if (-not (Get-Item $ProjectBuildPath/*.psd1 -erroraction silentlycontinue)) {throw "No Powershell Module Found in $ProjectBuildPath. Skipping deployment. Did you remember to build it first with {Invoke-Build Build}?"}
385385
}
386386
}
387-
#TODO: Replace SkipPublish Logic with Proper invokebuild task skipping
388-
task PublishPSGallery {
389-
if (-not $SkipPublish) {
390-
if ($AppVeyor -and -not $NuGetAPIKey) {
391-
write-build DarkYellow "Couldn't find NuGetAPIKey in the Appveyor secure environment variables. Did you save your NuGet/Powershell Gallery API key as an Appveyor Secure Variable? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item and https://www.appveyor.com/docs/build-configuration/"
392-
$SkipPublish = $true
393-
}
394-
if (-not $NuGetAPIKey) {
395-
#TODO: Add Windows Credential Store support and some kind of Linux secure storage or caching option
396-
write-build DarkYellow '$env:NuGetAPIKey was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -NuGetAPIKey "MyAPIKeyString"}. Have you registered for a Powershell Gallery API key yet? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item'
397-
$SkipPublish = $true
398-
}
399-
}
400-
401-
if ($SkipPublish) {
402-
Write-Build Magenta "Task $($task.name)`: Skipping Powershell Gallery Publish"
403-
} else {
404-
405-
$publishParams = @{
406-
Path = $ProjectBuildPath
407-
NuGetApiKey = $NuGetAPIKey
408-
Repository = 'PSGallery'
409-
Force = $true
410-
ErrorAction = 'Stop'
411-
Confirm = $false
412-
}
413-
#TODO: Add Prerelease Logic when message commit says "!prerelease"
414-
Publish-Module @publishParams @PassThruParams
415-
}
416-
}
417387

418388
task PublishGitHubRelease Package,{
419389
#TODO: Add Prerelease Logic when message commit says "!prerelease" or is in a release branch
@@ -444,37 +414,67 @@ task PublishGitHubRelease Package,{
444414
target_commitish = "master";
445415
name = [string]::Format("v{0}", $ProjectBuildVersion);
446416
body = $env:BHCommitMessage;
447-
draft = $false;
448-
prerelease = $false;
417+
draft = $true;
418+
prerelease = $true;
449419
}
450-
420+
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($GitHubApiKey + ":x-oauth-basic"))
451421
$releaseParams = @{
452422
Uri = "https://api.github.com/repos/$gitHubUserName/$env:BHProjectName/releases"
453423
Method = 'POST'
454424
Headers = @{
455-
Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($GitHubApiKey + ":x-oauth-basic"))
425+
Authorization = $auth
456426
}
457427
ContentType = 'application/json'
458428
Body = (ConvertTo-Json $releaseData -Compress)
459429
}
460430

461431
$result = Invoke-RestMethod @releaseParams -ErrorAction stop
462432

463-
$uploadUri = $result.upload_url
464-
$uploadUri = $uploadUri -creplace '\{\?name,label\}' #, "?name=$artifact"
465-
$uploadUri = $uploadUri + "?name=$(split-path $zipArchivePath -leaf)"
466-
$uploadFile = Join-Path -path $artifactOutputDirectory -childpath $artifact
433+
$uploadUriBase = $result.upload_url -creplace '\{\?name,label\}' # Strip the , "?name=$artifact" part
467434

468435
$uploadParams = @{
469-
Uri = $uploadUri;
470436
Method = 'POST';
471437
Headers = @{
472438
Authorization = $auth;
473439
}
474440
ContentType = 'application/zip';
475-
InFile = $zipArchivePath
476441
}
477-
$result = Invoke-RestMethod @uploadParams -erroraction stop
442+
foreach ($artifactItem in $artifactPaths) {
443+
$uploadparams.URI = $uploadUriBase + "?name=$(split-path $artifactItem -leaf)"
444+
$uploadparams.Infile = $artifactItem
445+
$result = Invoke-RestMethod @uploadParams -erroraction stop
446+
}
447+
}
448+
}
449+
450+
#TODO: Replace SkipPublish Logic with Proper invokebuild task skipping
451+
task PublishPSGallery {
452+
if (-not $SkipPublish) {
453+
if ($AppVeyor -and -not $NuGetAPIKey) {
454+
write-build DarkYellow "Couldn't find NuGetAPIKey in the Appveyor secure environment variables. Did you save your NuGet/Powershell Gallery API key as an Appveyor Secure Variable? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item and https://www.appveyor.com/docs/build-configuration/"
455+
$SkipPublish = $true
456+
}
457+
if (-not $NuGetAPIKey) {
458+
#TODO: Add Windows Credential Store support and some kind of Linux secure storage or caching option
459+
write-build DarkYellow '$env:NuGetAPIKey was not found as an environment variable. Please specify it or use {Invoke-Build Deploy -NuGetAPIKey "MyAPIKeyString"}. Have you registered for a Powershell Gallery API key yet? https://docs.microsoft.com/en-us/powershell/gallery/psgallery/creating-and-publishing-an-item'
460+
$SkipPublish = $true
461+
}
462+
}
463+
464+
if ($SkipPublish) {
465+
Write-Build Magenta "Task $($task.name)`: Skipping Powershell Gallery Publish"
466+
} else {
467+
468+
$publishParams = @{
469+
Path = $ProjectBuildPath
470+
NuGetApiKey = $NuGetAPIKey
471+
Repository = 'PSGallery'
472+
Force = $true
473+
ErrorAction = 'Stop'
474+
Confirm = $false
475+
}
476+
#TODO: Add Prerelease Logic when message commit says "!prerelease"
477+
Publish-Module @publishParams @PassThruParams
478478
}
479479
}
480480

0 commit comments

Comments
 (0)