|
| 1 | +[CmdletBinding()] |
| 2 | +param |
| 3 | +( |
| 4 | + [parameter(Mandatory=$false)] |
| 5 | + [switch]$IsDraft, |
| 6 | + |
| 7 | + [ValidateScript({Test-Path $_ -PathType Leaf})] |
| 8 | + [parameter(Mandatory=$true)] |
| 9 | + [string]$NotesFile, |
| 10 | + |
| 11 | + [ValidateScript({Test-Path $_ -PathType Leaf})] |
| 12 | + [parameter(Mandatory=$false)] |
| 13 | + [string[]]$Assets |
| 14 | +) |
| 15 | + |
| 16 | +function Invoke-GitHub([string]$ghArgs) |
| 17 | +{ |
| 18 | + $pinfo = New-Object System.Diagnostics.ProcessStartInfo |
| 19 | + $pinfo.FileName = "gh" |
| 20 | + $pinfo.UseShellExecute = $false |
| 21 | + $pinfo.Arguments = $ghArgs |
| 22 | + Write-Verbose -Message $pinfo.Arguments |
| 23 | + $ghProcess = New-Object System.Diagnostics.Process |
| 24 | + $ghProcess.StartInfo = $pinfo |
| 25 | + $null = $ghProcess.Start(); |
| 26 | + $ghProcess.WaitForExit(); |
| 27 | + return $ghProcess.ExitCode; |
| 28 | +} |
| 29 | + |
| 30 | +if ([string]::IsNullOrWhiteSpace($Env:GITHUB_TOKEN)) |
| 31 | +{ |
| 32 | + Write-Error "GITHUB_TOKEN environment variable is missing." |
| 33 | + Exit 1; |
| 34 | +} |
| 35 | + |
| 36 | +if ([string]::IsNullOrWhiteSpace($Env:GITHUB_SHA)) |
| 37 | +{ |
| 38 | + Write-Error "GITHUB_SHA is missing." |
| 39 | + Exit 2; |
| 40 | +} |
| 41 | +$Commitish = $Env:GITHUB_SHA; |
| 42 | + |
| 43 | +if ([string]::IsNullOrWhiteSpace($Env:STRAVAIG_PACKAGE_FULL_VERSION)) |
| 44 | +{ |
| 45 | + Write-Error "STRAVAIG_PACKAGE_FULL_VERSION is missing." |
| 46 | + Exit 3; |
| 47 | +} |
| 48 | +$TagName = "v" + $Env:STRAVAIG_PACKAGE_FULL_VERSION |
| 49 | + |
| 50 | + |
| 51 | +if ([string]::IsNullOrWhiteSpace($Env:STRAVAIG_IS_PREVIEW)) |
| 52 | +{ |
| 53 | + Write-Error "STRAVAIG_IS_PREVIEW is missing." |
| 54 | + Exit 4; |
| 55 | +} |
| 56 | +$IsPrerelease = [System.Convert]::ToBoolean($Env:STRAVAIG_IS_PREVIEW); |
| 57 | + |
| 58 | + |
| 59 | +$ghArgs = "release create `"$TagName`"" |
| 60 | +foreach($assetPath in $Assets) |
| 61 | +{ |
| 62 | + $specificAssets = Get-Item $assetPath; |
| 63 | + foreach($specificAsset in $specificAssets) |
| 64 | + { |
| 65 | + if (-not $specificAsset.PSIsContainer) |
| 66 | + { |
| 67 | + $fileName = $specificAsset.FullName; |
| 68 | + $ghArgs += " `"$fileName`"" |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + Write-Verbose "Skipping `"$specificAsset`" as it refers to a directory. Must provide paths to files." |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +$ghArgs += " --title `"Release of $TagName`" --target $Commitish --notes-file `"$NotesFile`"" |
| 80 | +if ($IsDraft) |
| 81 | +{ |
| 82 | + $ghArgs += " --draft" |
| 83 | +} |
| 84 | +if ($IsPrerelease) |
| 85 | +{ |
| 86 | + $ghArgs += " --prerelease" |
| 87 | +} |
| 88 | +$exitCode = Invoke-GitHub $ghArgs |
| 89 | +if ($exitCode -ne 0) |
| 90 | +{ |
| 91 | + Write-Error "Failed to create a release." |
| 92 | + Exit $exitCode; |
| 93 | +} |
| 94 | + |
0 commit comments